Jump to content

Recommended Posts

Posted
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?
Posted (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
EndFunc
Edit: Added indents.

Br, FireFox.

Edited by FireFox
Posted

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?

Posted

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.

Posted

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
Posted
:huh: 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?  :ermm:
Posted

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.

Posted

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.

Posted (edited)

Try this :

#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
EndFunc
Edit: Added indents.

Br, FireFox.

Edited by FireFox
Posted (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 by FireFox

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...