BackHomeAgain Posted May 25, 2010 Posted May 25, 2010 For the active window I want to determine if the mouse click is on the title bar and not somewhere else in the window. Here's my attempt using the _SendMessage function: If _SendMessage($hWnd, $WM_NCLBUTTONDOWN, $WM_NCHITTEST, $HTCAPTION, 4) <> 0 Then Test passed Else Test failed EndIf The problem is that the test always passes. It would appear that I am doing something wrong or making incorrect assumptions? I have used the WinGetPos($hWnd) function to calculate the title bar area, but if I could just find this area using the _SendMessage function or some other function if that is not correct, it would save a lot of calculation. Also, the various title bar buttons could be checked.
wolf9228 Posted May 25, 2010 Posted May 25, 2010 For the active window I want to determine if the mouse click is on the title bar and not somewhere else in the window. Here's my attempt using the _SendMessage function: If _SendMessage($hWnd, $WM_NCLBUTTONDOWN, $WM_NCHITTEST, $HTCAPTION, 4) <> 0 Then Test passed Else Test failed EndIf The problem is that the test always passes. It would appear that I am doing something wrong or making incorrect assumptions? I have used the WinGetPos($hWnd) function to calculate the title bar area, but if I could just find this area using the _SendMessage function or some other function if that is not correct, it would save a lot of calculation. Also, the various title bar buttons could be checked. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Gui = GUICreate("My GUI") GUIRegisterMsg($WM_NCLBUTTONDOWN, "WM_NCLBUTTONDOWN") GUISetState(@SW_SHOW) Global $Test = False While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $Test = True Then MsgBox(0,"MSG","passed") $Test = False WEnd GUIDelete() Func WM_NCLBUTTONDOWN($hWnd, $Msg, $wParam, $lParam) $Test = True Return $GUI_RUNDEFMSG EndFunc صرح السماء كان هنا
BackHomeAgain Posted May 26, 2010 Author Posted May 26, 2010 The example works fine for a new window, but what about for an existing window, in this case the active window? I have spent much time on the documentation, examples, and forum discussions with some frustration. The _SendMessage function appears to be what I need. If I pass in the handle for the active window and the appropriate message parameter, it should work? I patterned my code after the _SendMessage function example. #include <SendMessage.au3> #include <WindowsConstants.au3> $hWnd = WinGetHandle("[ACTIVE]") _SendMessage($hWnd, $WM_NCLBUTTONDOWN) If NOT @error Then The title bar area was selected. Else The mouse was in some other part of the window. EndIf What am I missing?
wolf9228 Posted May 27, 2010 Posted May 27, 2010 (edited) The example works fine for a new window, but what about for an existing window, in this case the active window? I have spent much time on the documentation, examples, and forum discussions with some frustration. The _SendMessage function appears to be what I need. If I pass in the handle for the active window and the appropriate message parameter, it should work? I patterned my code after the _SendMessage function example. #include <SendMessage.au3> #include <WindowsConstants.au3> $hWnd = WinGetHandle("[ACTIVE]") _SendMessage($hWnd, $WM_NCLBUTTONDOWN) If NOT @error Then The title bar area was selected. Else The mouse was in some other part of the window. EndIf What am I missing? expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <Misc.au3> HotKeySet("{ESC}", "Terminate") $dll = DllOpen("user32.dll") While 1 if MouseProc() Then MsgBox(0,"MSG","Pressed") WEnd Func MouseProc() $L = MouseGetPos(0) $T = MouseGetPos(1) $sR = _WinAPI_GetSystemMetrics(0) $sB = _WinAPI_GetSystemMetrics(1) $Handle = WinGetHandle("[active]") $WINDOWINFO = GetWindowInfo($Handle) $cxWindowBorders = DllStructGetData($WINDOWINFO,"cxWindowBorders") $cyWindowBorders = DllStructGetData($WINDOWINFO,"cyWindowBorders") $RECT = _WinAPI_GetWindowRect($Handle) $CRECT = _WinAPI_GetClientRect($Handle) $iL = DllStructGetData($RECT,"Left") $iT = DllStructGetData($RECT,"Top") $iR = DllStructGetData($RECT,"Right") $iB = DllStructGetData($RECT,"Bottom") If $iL < 0 Then $iL = 0 If $iT < 0 Then $iT = 0 if $iR > $sR Then $iR = $sR if $iB > $sB Then $iB = $sB $CL = DllStructGetData($CRECT,"Left") $CT = DllStructGetData($CRECT,"Top") $CR = DllStructGetData($CRECT,"Right") $CB = DllStructGetData($CRECT,"Bottom") If $CL < 0 Then $CL = 0 If $CT < 0 Then $CT = 0 if $CR > $sR Then $CR = $sR if $CB > $sB Then $CB = $sB if $L >= $iL And $L <= $iR And $T < ($iB - $CB - $cxWindowBorders) Then if _IsPressed("01", $dll) Then Return True Else Return False EndIf EndFunc Func Terminate() Exit 0 EndFunc Func GetWindowInfo($hwnd) $Tag_struct = "DWORD cbSize;LONG IL;LONG IT;LONG IR;LONG IB;LONG CL;LONG CT;LONG CR;LONG CB;" & _ "DWORD dwStyle;DWORD dwExStyle;DWORD dwWindowStatus;UINT cxWindowBorders;UINT cyWindowBorders;" & _ "int atomWindowType;WORD wCreatorVersion" $WINDOWINFO = DllStructCreate($Tag_struct) DllStructSetData($WINDOWINFO,"cbSize",DllStructGetSize($WINDOWINFO)) $LPWINDOWINFO = DllStructGetPtr($WINDOWINFO) DllCall("User32.dll" ,"int","GetWindowInfo","HWND",$hwnd,"ptr",$LPWINDOWINFO) Return $WINDOWINFO EndFunc Edited May 27, 2010 by wolf9228 صرح السماء كان هنا
BackHomeAgain Posted June 3, 2010 Author Posted June 3, 2010 The script displays the window coordinates at the top left corner of the window and will update itself when the window is dragged across the screen. The script works for both window content and no content mode. The issue that I am trying to resolve is not to display the coordinates if any of the title bar buttons are pressed. The example checks for the minimize button. If it was not pressed, the coordinates will be displayed. But, it is not working. If one changes "If @error to NOT @error", the coordinates are displayed regardless where the title bar was selected. Any help would be much appreciated. expandcollapse popup#Include <Misc.au3> #include <WinAPI.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <SendMessage.au3> While 1 GUIGetMsg() $hWnd = WinGetHandle("[ACTIVE]") $title = WinGetTitle($hWnd) $coord = WinGetPos($hWnd) If NOT _IsPressed("01", "user32.dll") Then Local $fp = 0, $b = 0, $c = 0 ToolTip("") Else If $title <> "Program Manager" AND $title <> "" Then $BarInfo = _GetTitleBarInfo($hWnd) $bH = DllStructGetData($BarInfo, "Bottom") - DllStructGetData($BarInfo, "Top") $x1 = $coord[0] $y1 = $coord[1] $xW = $coord[2] $yH = $coord[3] $x2 = $x1+$xW $y2 = $y1+$yH $yT = $y1+$bH $mc = MouseGetCursor() $Cx = MouseGetPos(0) $Cy = MouseGetPos(1) If $fp = 0 Then $fp = 1 If $fp = 1 Then ;First pass $fp += 1 If $mc = $IDC_ARROW Then If $Cx >= $x1 AND $Cx <= $x2 AND $Cy >= $y1 AND $Cy <= $yT Then _SendMessage($hWnd, $WM_NCLBUTTONDOWN, $WM_NCHITTEST, $HTMINBUTTON) If @error Then ;Title bar minimize button was not selected $b = $Cx-$x1 $c = $Cy-$y1 EndIf EndIf EndIf EndIf If $b <> 0 Then $x1 = $Cx-$b $y1 = $Cy-$c $XY = " X:" & $x1 & " Y:" & $y1 ToolTip($XY, $x1, $y1, "", 0, 4) EndIf EndIf EndIf WEnd Func _GetTitleBarInfo($hwnd) $Tag_struct = "DWORD cbSize;" & $tagRECT & ";DWORD rgstate[6]" $BarInfo = DllStructCreate($Tag_struct) DllStructSetData($BarInfo, "cbSize", DllStructGetSize($BarInfo)) DllCall("User32.dll", "int", "GetTitleBarInfo", "HWND",$hwnd, "ptr",DllStructGetPtr($BarInfo)) Return $BarInfo EndFunc
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