Jump to content

How to ignore click on the the window title and change its size?


AndreyS
 Share

Recommended Posts

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

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
Link to comment
Share on other sites

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

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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