AndreyS Posted August 13, 2013 Share Posted August 13, 2013 All developers hello! The guys tell me, please, who knows. I have a function GUISetOnEvent ($ $ GUI_EVENT_PRIMARYVDOWN, "Func1", $ Form1). How to make sure that it does not start when I click on the title bar or resize the window when Form1? Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 (edited) Hi,Try this :#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $hGUI = GUICreate("MyGUI", Default, Default, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN") GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(1000) WEnd Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) ConsoleWrite("left button clicked" & @CrLf) Return $GUI_RUNDEFMSG EndFunc Func _Exit() GUIDelete($hGUI) Exit EndFuncEdit: Added indents.Br, FireFox. Edited August 13, 2013 by FireFox Link to comment Share on other sites More sharing options...
AndreyS Posted August 13, 2013 Author Share Posted August 13, 2013 Oh! An interesting solution! Thank you! Now it only works when you click on an empty spot without controls. How to make so that when you click on all the controls on the form and the function work? Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 What is the final purpose of this? There must be a more reliable way to do what you want Br, FireFox. Link to comment Share on other sites More sharing options...
AndreyS Posted August 13, 2013 Author Share Posted August 13, 2013 The purpose of the easiest! I want my function to start when you click on the form, or by any of its controls. But when I move the window of the form that it did not fire. That's it. Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 So what are the purpose of your controls? Link to comment Share on other sites More sharing options...
AndreyS Posted August 13, 2013 Author Share Posted August 13, 2013 I do not understand what you explain more? We need to do so on any control function worked. In your example, on the Edit control as well. And for all that, I would add. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $hGUI = GUICreate("MyGUI", Default, Default, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUICtrlCreateEdit("", 10, 10, 300,300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN") GUISetState(@SW_SHOW, $hGUI) While 1 Sleep(1000) WEnd Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) ConsoleWrite("left button clicked" & @CrLf) Return $GUI_RUNDEFMSG EndFunc Func _Exit() GUIDelete($hGUI) Exit EndFunc Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 I mean why the target function needs to be fired for a click on any control? Link to comment Share on other sites More sharing options...
AndreyS Posted August 13, 2013 Author Share Posted August 13, 2013 Click on the window to any location should change the contents of the controls. I do not want false positives when I drag a window. How else to explain it? Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 Apart from a design thing, I don't see why you want to do this.Anyway, you will have to set an event on all your controls (GUICtrlSetOnEvent function).Br, FireFox. Link to comment Share on other sites More sharing options...
AndreyS Posted August 13, 2013 Author Share Posted August 13, 2013 Since the mouse control is very convenient in my case. For each element, it is inconvenient. Elements and functions may vary as well. It is necessary to find a general solution. Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 (edited) Try this :expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Opt("GUIOnEventMode", 1) Global Const $SM_CXSIZEFRAME = 32 Global $iSM_CXDLGFRAME = _WinAPI_GetSystemMetrics($SM_CXSIZEFRAME) Global $iSM_CYCAPTION = _WinAPI_GetSystemMetrics($SM_CYCAPTION) Global $hGUI = GUICreate("MyGUI", Default, Default, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateButton("button", 10, 10) GUICtrlCreateInput("input", 10, 40) GUICtrlCreateCheckbox("checkbox", 10, 70, 80) GUISetState(@SW_SHOW, $hGUI) Global $hMouseHook = DllCallbackRegister("_MouseProc", "long", "int;ptr;ptr") Global $hMouseProc = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseHook), _WinAPI_GetModuleHandle(0), 0) OnAutoItExitRegister("OnAutoItExit") While 1 Sleep(1000) WEnd Func _MouseProc($iCode, $wParam, $lParam) If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hMouseHook, $iCode, $wParam, $lParam) Switch BitAND($wParam, 0xFFFF) Case $WM_LBUTTONDOWN If WinActive($hGUI) > 0 Then Local $aWgp = WinGetPos($hGUI) Local $aMgp = MouseGetPos() If ($aMgp[0] > ($aWgp[0] + $iSM_CXDLGFRAME)) And ($aMgp[0] < ($aWgp[0] + $aWgp[2] - $iSM_CXDLGFRAME)) _ And ($aMgp[1] > $aWgp[1] + $iSM_CYCAPTION) And ($aMgp[1] < ($aWgp[1] + $aWgp[3] - $iSM_CXDLGFRAME)) Then _LeftClick() EndIf EndIf EndSwitch Return _WinAPI_CallNextHookEx($hMouseHook, $iCode, $wParam, $lParam) EndFunc Func _LeftClick() ConsoleWrite("left button clicked" & @CrLf) EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hMouseHook) DllCallbackFree($hMouseProc) EndFunc Func _Exit() GUIDelete($hGUI) Exit EndFuncEdit: Added indents.Br, FireFox. Edited August 13, 2013 by FireFox AndreyS 1 Link to comment Share on other sites More sharing options...
AndreyS Posted August 13, 2013 Author Share Posted August 13, 2013 Wow solution! Not simple, but it works. Thanks for the help, FireFox! Link to comment Share on other sites More sharing options...
FireFox Posted August 13, 2013 Share Posted August 13, 2013 (edited) You're welcome Note that the script must be adjusted (at least for me) for the bottom corner of the GUI when you want to resize it (a -2 should do the trick at the end of the last expression ) Edited August 13, 2013 by FireFox 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