kjpolker Posted June 14, 2023 Share Posted June 14, 2023 I am looking for a way to have a switch recognize when I left click vs. right click on a submenu option. I can perform this task on controls within the GUI but I can't figure it out within Menu Options. #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $GUI, $menu, $subMenu $GUI = GUICreate("Example GUI", 300, 200) $menu = GUICtrlCreateMenu("&File") $subMenu = GUICtrlCreateMenuItem("Options", $menu) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_SECONDARYUP $mCur = GUIGetCursorInfo($GUI) If IsArray($mCur) Then If $mCur[4] = $subMenu Then MsgBox(0, "Test", "Right Clicked") EndIf Case $subMenu MsgBox(0, "Test", "Left Clicked") EndSwitch WEnd Link to comment Share on other sites More sharing options...
Solution spudw2k Posted June 15, 2023 Solution Share Posted June 15, 2023 (edited) I believe you will have to resort to a Message handler. Here is an example which handles the WM_MENURBUTTONUP Windows Message ID. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> Global $GUI, $menu, $subMenu $GUI = GUICreate("Example GUI", 300, 200) $menu = GUICtrlCreateMenu("&File") $subMenu = GUICtrlCreateMenuItem("Options", $menu) GUIRegisterMsg($WM_MENURBUTTONUP, "_WM_MENURBUTTONUP") ;Register Message Handler GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $subMenu MsgBox(0, "Test", "Left Clicked") EndSwitch WEnd Func _WM_MENURBUTTONUP($hWnd, $iMsg, $wParam, $lParam) Local $hMenu = GUICtrlGetHandle($menu) Switch $lParam ;Handle of triggering Menu Case $hMenu Local $iMenuIndexID = _GUICtrlMenu_GetItemID($hMenu, $wParam) ;Get ID using Handle of Menu Subitem ($wParam) Switch $iMenuIndexID Case $subMenu MsgBox(0, "Test", "Right Clicked") EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Edited June 15, 2023 by spudw2k Gianni 1 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
argumentum Posted June 15, 2023 Share Posted June 15, 2023 10 hours ago, kjpolker said: I am looking for a way to have a switch recognize when I left click vs. right click on a submenu option. Why ?, what for ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
spudw2k Posted June 15, 2023 Share Posted June 15, 2023 @argumentum i was wondering the same thing, but I decided to look into how because I was curious. Hopefully @kjpolker will chime in with the "why". Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
kjpolker Posted June 15, 2023 Author Share Posted June 15, 2023 10 hours ago, argumentum said: Why ?, what for ? A bit silly, but my intention was for it to be a bit of an easter egg. A way to access back end information, but I admit the idea was more of a learning opportunity for me to get creative and I took advantage of the idea to improve my understanding of code. The actual script I am looking to implement it on is a glorified mouse clicker with a bunch of handy tools for interacting with Windows. 11 hours ago, spudw2k said: I believe you will have to resort to a Message handler. Here is an example which handles the WM_MENURBUTTONUP Windows Message ID. This! I was looking down the right path but fell short. I was able to find WM_MENUSELECT and that was not working as desired. This is exactly what I was looking for and would not have been able to piece it together without help. I have zero understanding of how that Function is working which gives me a chance to read up argumentum 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now