AdmiralAlkex Posted August 15, 2008 Share Posted August 15, 2008 (edited) I am creating a GUI in AutoIt and want something that looks like a button and that runs a function when right-clicked. How can I do this without constant checking in my "main-loop"?? I am using OnEventMode and are running 3.2.12.0 Edited August 15, 2008 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 15, 2008 Author Share Posted August 15, 2008 I just wanted to say that I manage to do it by using GUISetOnEvent with $GUI_EVENT_SECONDARYDOWN and $GUI_EVENT_SECONDARYUP and then checking if the button is under the mouse with GUIGetCursorInfo. If there is a more elegant solution please do tell me! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Achilles Posted August 15, 2008 Share Posted August 15, 2008 Try using GUIRegisterMsg with WM_RBUTTONDOWN My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
rasim Posted August 15, 2008 Share Posted August 15, 2008 Achilles Try using GUIRegisterMsg with WM_RBUTTONDOWNWrong, because: MSDN The WM_RBUTTONDOWN message is posted when the user presses the right mouse button while the cursor is in the client area of a windowAccordingly not works with the any control. AdmiralAlkex If there is a more elegant solution please do tell me!I don`t know about elegance of this solution, but... #include <GuiConstantsEx.au3> #include <Constants.au3> #include <WinAPI.au3> Global Const $WM_RBUTTONUP = 0x0205 $hGui = GUICreate("Button right click demo", 200, 100) $button = GUICtrlCreateButton("start", 60, 40, 75, 23) GUISetState() $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($button), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) While GUIGetMsg() <> -3 WEnd GUIDelete($hGui) DllCallbackFree($wProcHandle) Func _WindowProc($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case GUICtrlGetHandle($button) Switch $Msg Case $WM_RBUTTONUP ConsoleWrite("!> Right mouse click" & @LF) EndSwitch EndSwitch Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _ "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam) Return $aRet[0] EndFunc Link to comment Share on other sites More sharing options...
Arterie Posted August 18, 2008 Share Posted August 18, 2008 Ok this works fine for me too, but maybe i am too nooby for that dll thing..how does it look with a few more buttons 3 or 4? Link to comment Share on other sites More sharing options...
Achilles Posted August 18, 2008 Share Posted August 18, 2008 Ok this works fine for me too, but maybe i am too nooby for that dll thing..how does it look with a few more buttons 3 or 4?See where there's a Case GUICtrlGetHandle($button), replace that (or add a new one) with Case GUICtrlGetHandle($yourOtherButton)... Then you'll need to add all same stuff under it... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Arterie Posted August 18, 2008 Share Posted August 18, 2008 I also need to add $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($button2), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) But thanks for help Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 18, 2008 Author Share Posted August 18, 2008 I like my solution better and it can easely be adapted for more buttons. See this example: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $ClickedButton $GUI = GUICreate("A gui") $ButtonMinimize = GUICtrlCreateButton("Right-click me to minimize", 5, 15) GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_GuiEvents") GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_GuiEvents") GUISetState() While 1 Sleep(10) WEnd Func _GuiEvents() Switch @GUI_CtrlId Case $GUI_EVENT_SECONDARYDOWN $Cursor = GUIGetCursorInfo($GUI) If IsArray($Cursor) Then $ClickedButton = $Cursor[4] Case $GUI_EVENT_SECONDARYUP $Cursor = GUIGetCursorInfo($GUI) If IsArray($Cursor) And $ClickedButton = $ButtonMinimize And $Cursor[4] = $ButtonMinimize Then GUISetState(@SW_MINIMIZE, $GUI) EndIf EndSwitch EndFunc .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Arterie Posted August 19, 2008 Share Posted August 19, 2008 (edited) But with this code i got the problem that none of the menus or buttons work anymore when leftclicked. Rasims works too, but its very laggy for the mass of buttons i got. Is it possible to just call it when the right button is pressed (without _IsPressed because it would call it muliple times) Edited August 19, 2008 by Arterie Link to comment Share on other sites More sharing options...
rasim Posted August 19, 2008 Share Posted August 19, 2008 ArterieGlobal Const $WM_RBUTTONUP = 0x0205 Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 19, 2008 Author Share Posted August 19, 2008 But with this code i got the problem that none of the menus or buttons work anymore when leftclicked.Rasims works too, but its very laggy for the mass of buttons i got. Is it possible to just call it when the right button is pressed (without _IsPressed because it would call it muliple times)What the hell are you talking about? My code doesn't interfere with leftclicks and with one/multiple Switch...Case...EndSwitch it would barely use any CPU at all .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface 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