guiltyking Posted April 12, 2016 Posted April 12, 2016 (edited) Is there any better solution to check right Click on a button rather than that one? Since could be there 100`s keys to process. Topic is about to find out what is missing in AutoIT to handle contol ID`s of right Clicked Buttons amongst bunch of buttonkeys. expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 300, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "bye") GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp") global $cButton[9] for $x=1 to 3 $cButton[$x] = GUICtrlCreateButton("Check"&$x, 10, 10*($X*5), 80, 30) GUICtrlSetOnEvent(-1, "_Button") next $x+=1 $cButton[$x] = GUICtrlCreateButton("NoCheck", 10, 10*($X*5), 80, 30) GUISetState() While Sleep(10) WEnd Func _Button() $nTempId=GUICtrlRead(@GUI_CtrlId) ; can get ID from Left Clicked Button// $aCInfo = GUIGetCursorInfo($hGUI) MsgBox(0, "Pressed", "LEFT "&$nTempId&":"&GUICtrlRead($aCInfo[4]),.5) EndFunc Func _SecondaryUp() $aCInfo = GUIGetCursorInfo($hGUI) for $x=1 to 3 ; my solutionprocess slower.... If $aCInfo[4] = $cButton[$x] Then $nTempId=GUICtrlRead(@GUI_CtrlId) ;cannot get real ID, but last one. $nTempId2=GUICtrlRead($cButton[$x]) ;can get ID MsgBox(0, "Pressed", "RIGHT "&$nTempId&":<=? True= "&$nTempId2,1) EndIf next EndFunc Func bye() Exit EndFunc Edited April 12, 2016 by guiltyking
InunoTaishou Posted April 12, 2016 Posted April 12, 2016 (edited) #include <GUIConstants.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> #include <WinAPIShellEx.au3> Global Enum $idSettings = 1000 Global $hMain = GUICreate("", 120, 50) Global $btnMenu = GUICtrlCreateButton("Menu", 10, 10, 100, 30) Global $hBtnMenu = GUICtrlGetHandle($btnMenu) Global $pButtonProc = DllCallbackGetPtr(DllCallbackRegister("ButtonProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")) GUISetState(@SW_SHOW, $hMain) _WinAPI_SetWindowSubclass($hBtnMenu, $pButtonProc, 1000) While (True) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE GUIDelete($hMain) Exit 0 EndSwitch WEnd Func ButtonProc($hWndFrom, $iMsg, $wParam, $lParam, $iSubclassId, $pData) Switch ($hWndFrom) Case $hBtnMenu Switch ($iMsg) Case $WM_RBUTTONUP Local $hMenuButton = _GUICtrlMenu_CreatePopup($MNS_NOCHECK) _GUICtrlMenu_AddMenuItem($hMenuButton, "Settings", $idSettings) _GUICtrlMenu_TrackPopupMenu($hMenuButton, $hWndFrom) _GUICtrlMenu_DestroyMenu($hMenuButton) EndSwitch EndSwitch Return _WinAPI_DefSubclassProc($hWndFrom, $iMsg, $wParam, $lParam) EndFunc ;==>EditProc Edited April 12, 2016 by InunoTaishou krasnoshtan 1
guiltyking Posted April 12, 2016 Author Posted April 12, 2016 (edited) Quote Case $hBtnMenu how come you can multiple that then? mine still better and shorter. Edited April 12, 2016 by guiltyking
InunoTaishou Posted April 12, 2016 Posted April 12, 2016 Typo, it was supposed to be Switch ($hWndFrom) I don't know about better. I'm getting the handle of the button that was clicked from windows as well as every message that button can send to your gui.
qwert Posted April 12, 2016 Posted April 12, 2016 Here's a short method I've used now and then: #include <GUIConstantsEx.au3> $hGui = GUICreate("Test GUI", 300, 200) $send = GUICtrlCreateLabel("Test Label", 20, 40, 100, 40) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $send MsgBox(0, "Label", "Clicked", 1) Case $GUI_EVENT_SECONDARYUP $aCur = GUIGetCursorInfo($hGui) If IsArray($aCur) Then If $aCur[4] = $send Then MsgBox(0, "Label", "Right Clicked", 1) EndIf EndIf EndSwitch WEnd Sometimes the method just depends on what other processing you need to include. krasnoshtan 1
guiltyking Posted April 12, 2016 Author Posted April 12, 2016 (edited) examine my code, it restricts right click on only selected buttons. And GUIGetCursorInfo($hGui) fails on multiple keys. therefore you have to loop like mine Edited April 12, 2016 by guiltyking
qwert Posted April 12, 2016 Posted April 12, 2016 I'm curious: what's the advantage of restricting over ignoring? But, like I said, it depends on what other processing you need. Regardless, I can imagine that your topic title will result in a lot of people looking for a minimal method ... and maybe the complicated ones, too.
krasnoshtan Posted August 31, 2020 Posted August 31, 2020 (edited) On 4/12/2016 at 7:59 PM, qwert said: Here's a short method I've used now and then: #include <GUIConstantsEx.au3> $hGui = GUICreate("Test GUI", 300, 200) $send = GUICtrlCreateLabel("Test Label", 20, 40, 100, 40) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $send MsgBox(0, "Label", "Clicked", 1) Case $GUI_EVENT_SECONDARYUP $aCur = GUIGetCursorInfo($hGui) If IsArray($aCur) Then If $aCur[4] = $send Then MsgBox(0, "Label", "Right Clicked", 1) EndIf EndIf EndSwitch WEnd Sometimes the method just depends on what other processing you need to include. Wow! That is almost what I am need. Can you describe me what that array is doing, how to understand its behaviour? UPD: is it possible to use multiple (included) switches/cases for better understanding? Edited August 31, 2020 by krasnoshtan
krasnoshtan Posted August 31, 2020 Posted August 31, 2020 (edited) 24 minutes ago, krasnoshtan said: ...Can you describe me what that array is doing, how to understand its behaviour?.. Okay, just got it. Every time right mouse button is released above the GUI, the check is performed - is there are any defined elements was right clicked. Edited August 31, 2020 by krasnoshtan
Nine Posted August 31, 2020 Posted August 31, 2020 Maybe this : #include <GUIConstants.au3> $hGui = GUICreate("Test GUI", 300, 200) $lab1 = GUICtrlCreateLabel("Test Label", 20, 40, 100, 25, $SS_SUNKEN) $but1 = GUICtrlCreateButton("Button1", 20, 70, 100, 25) $lab2 = GUICtrlCreateLabel("Test Label 2", 20, 100, 100, 25, $SS_SUNKEN) $but2 = GUICtrlCreateButton("Button2", 20, 130, 100, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $lab1 MsgBox(0, "Label", "Clicked", 2) Case $GUI_EVENT_SECONDARYUP $aCur = GUIGetCursorInfo($hGui) If Not IsArray($aCur) Then ContinueLoop Switch $aCur[4] Case $lab1 MsgBox(0, "Label 1", "Right Clicked", 2) Case $but1 MsgBox(0, "Button 1", "Right Clicked", 2) Case $lab2 MsgBox(0, "Label 2", "Right Clicked", 2) Case $but2 MsgBox(0, "Button 2", "Right Clicked", 2) EndSwitch EndSwitch WEnd krasnoshtan 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
krasnoshtan Posted August 31, 2020 Posted August 31, 2020 3 minutes ago, Nine said: Maybe this : #include <GUIConstants.au3> $hGui = GUICreate("Test GUI", 300, 200) $lab1 = GUICtrlCreateLabel("Test Label", 20, 40, 100, 25, $SS_SUNKEN) $but1 = GUICtrlCreateButton("Button1", 20, 70, 100, 25) $lab2 = GUICtrlCreateLabel("Test Label 2", 20, 100, 100, 25, $SS_SUNKEN) $but2 = GUICtrlCreateButton("Button2", 20, 130, 100, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $lab1 MsgBox(0, "Label", "Clicked", 2) Case $GUI_EVENT_SECONDARYUP $aCur = GUIGetCursorInfo($hGui) If Not IsArray($aCur) Then ContinueLoop Switch $aCur[4] Case $lab1 MsgBox(0, "Label 1", "Right Clicked", 2) Case $but1 MsgBox(0, "Button 1", "Right Clicked", 2) Case $lab2 MsgBox(0, "Label 2", "Right Clicked", 2) Case $but2 MsgBox(0, "Button 2", "Right Clicked", 2) EndSwitch EndSwitch WEnd yeah, that's clearer, thanks!
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