Jump to content

check if mouse is clicked on the titlebar of gui


Recommended Posts

so i have a gui i need to check when the mouse is clicked on the title bar of the gui

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

If you need this coarse hack,

Here it is. :)

#include <Misc.au3>

AutoItSetOption( "MouseCoordMode", 0 ) ; relative coords to the active window

$frontWin = GUICreate( "Windows title height", 310, 35, @DesktopWidth, @DesktopHeight )
$winSize = WinGetPos( $frontWin )
$clientSize = WinGetClientSize( $frontWin )
WinClose( $frontWin )

Global $titleHeight = $winSize[3] - $clientSize[1] - 3


While 1
    Sleep( 50 )
    If _IsPressed( "01" ) Then ; Left mouse button
        $pos = MouseGetPos( )
        If $pos[1] < $titleHeight Then
            MsgBox( 0, "Notice", "The title bar is clicked." )
        EndIf
    EndIf
WEnd
Link to comment
Share on other sites

Better way would be to use GUIRegisterMsg() function..

#include <GUIConstants.au3>

Global Const $WM_NCLBUTTONDOWN = 0xA1
Global $Clicked

GuiCreate("TitleBar Click", 300, 100)
GUISetState()

GUIRegisterMsg ($WM_NCLBUTTONDOWN, "WM_NCLBUTTONDOWN_FUNC")

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    If $Clicked = 1 Then
        MsgBox(0,"","Title Bar Clicked")
        $Clicked = 0
    EndIf   
WEnd
    
Func WM_NCLBUTTONDOWN_FUNC($hWnd, $Msg, $WParam, $LParam)
    $nID            = BitAnd($wParam, 0x0000FFFF)
    If $Clicked = 0 And $nID = 2 Then 
        $Clicked = 1
        Return $GUI_RUNDEFMSG
    Else    
        Return $GUI_RUNDEFMSG
    EndIf   
EndFunc

This would register when the left mouse button is clicked on the titlebar.

(Min, Max, Close, and titlebar context menu wont be counted in this poor example)

A better way would be if Lobishomen happened along and made the function correctly

(unlike me who has no clue with how GUIRegisterMsg() is meant to be used properly) :)

Cheers

Edit: Note if your using the $GUI_WS_EX_PARENTDRAG style , then the message will also be sent when the ctrl with style is clicked.

Edited by smashly
Link to comment
Share on other sites

ah i can't edit the post

maybe do i need moon light?

(Min, Max, Close, and titlebar context menu wont be counted in this poor example)

i guessed he wanted global approach ;D heh heh

sorry for the mistake

anyhow, in the example code, you may need a flag var to prevent calling a fucntion again and again while you are pressing a mouse button.

#include <Misc.au3>

AutoItSetOption( "MouseCoordMode", 0 ) ; relative coords to the active window

$frontWin = GUICreate( "Windows title height", 310, 35, @DesktopWidth, @DesktopHeight )
$winSize = WinGetPos( $frontWin )
$clientSize = WinGetClientSize( $frontWin )
WinClose( $frontWin )

Global $titleHeight = $winSize[3] - $clientSize[1] - 3
Global $btnPressed = False


While 1
    Sleep( 50 )
    If _IsPressed( "01" ) Then ; Left mouse button
        If Not $btnPressed Then
            $pos = MouseGetPos( )
            If $pos[1] < $titleHeight Then
;~          MsgBox( 0, "Notice", "The title bar is clicked." )
                Beep( 500, 100 )
                $btnPressed = True
            EndIf
        EndIf
    Else
        $btnPressed = False
    EndIf
WEnd

umm.. werewolf may live eternally?

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...