level20peon Posted May 21, 2009 Share Posted May 21, 2009 (edited) I am looking for a way to get the window title of the window I am hovering with my mouse. The last days turned out to be unsuccessful though.I have found numerous ways people seemed to have succeeded with this but none of the code I tried worked out so far.Example by PsaltyDS taken from hereHotKeySet("{ESC}", "_Quit") Global $Struct = DllStructCreate("int x;int y") While 1 Sleep(100) ToolTip("") Pos() $hwnd = WindowFromPoint() ToolTip($hwnd) WEnd Func Pos() DllStructSetData($Struct, "x", MouseGetPos(0)) DllStructSetData($Struct, "y", MouseGetPos(1)) EndFunc ;==>Pos Func WindowFromPoint() Local $x = DllStructGetData($Struct, "X") Local $y = DllStructGetData($Struct, "Y") Local $aResult = DllCall("User32.dll", "hwnd", "WindowFromPoint", "int", $x, "int", $y) Return $aResult[0] EndFunc ;==>WindowFromPoint Func _Quit() Exit EndFunc ;==>_QuitDoesn't really work. If I have a Firefox window on parts of the screen for example the script correctly returns the ff window handle. If I hover parts of the desktop the script returns the filemanager handle (also correctly). However, if I hover another window while the ff window is there (active or not) the script returns the filemanager handle as if the other window wasn't even there.Au3Info returns the correct handle (or title) all the time so why do you think the au3 implementations don't work for me ?I am using Vista x64 if that's relevant.It also doesn't matter which MouseCoordMode I chose.Any hints or things I could try ? Edited May 21, 2009 by level20peon Link to comment Share on other sites More sharing options...
picea892 Posted May 21, 2009 Share Posted May 21, 2009 http://www.autoitscript.com/forum/index.ph...mp;#entry681029 Link to comment Share on other sites More sharing options...
level20peon Posted May 21, 2009 Author Share Posted May 21, 2009 http://www.autoitscript.com/forum/index.ph...mp;#entry681029 Same behaviour, this is my derived test-script: #include <WinAPI.au3> While 1 Sleep(100) test() WEnd Func test() ToolTip("") $pos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint($pos) ToolTip($hwnd) EndFunc Link to comment Share on other sites More sharing options...
level20peon Posted May 21, 2009 Author Share Posted May 21, 2009 (edited) I just found out that the tooltip shows half of the correct information. It doesn't take the y coordinates correctly but always assumes them as 0. What could cause that ? Edited May 21, 2009 by level20peon Link to comment Share on other sites More sharing options...
hydroxide Posted May 21, 2009 Share Posted May 21, 2009 Use WinAPI_GetWindowText(handle) to get the title #include <WinAPI.au3> While 1 Sleep(100) test() WEnd Func test() ToolTip("") $pos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint($pos) $nm = _WinAPI_GetWindowText($hwnd) ToolTip($nm) EndFunc Link to comment Share on other sites More sharing options...
WideBoyDixon Posted May 21, 2009 Share Posted May 21, 2009 #include <WinAPI.au3> While 1 Sleep(100) test() WEnd Func test() $pos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint($pos) While _WinAPI_GetParent($hwnd) <> 0 $hwnd = _WinAPI_GetParent($hwnd) Wend ToolTip($hwnd & " : " & WinGetTitle($hwnd)) EndFunc This? [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
level20peon Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks for your help guys but the "bug" isn't really on either your or my side. As mentioned earlier I am on a x64 OS. Seems that the WindowFromPoint API function doesn't handle the tagPoint structure the same way as a x86 OS. I get the correct values if I run the script in (x86) mode. Maybe some Dev could look into this matter ? Link to comment Share on other sites More sharing options...
level20peon Posted May 22, 2009 Author Share Posted May 22, 2009 Added a ticket to the bugtracker. 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