Sign in to follow this  
Followers 0
oMBRa

get window's handle from control's handle

8 posts in this topic

I have an handle of a control, and with it I should get the handle of the window owner, but how to do it?

Share this post


Link to post
Share on other sites



_WinAPI_GetParent() ?

Share this post


Link to post
Share on other sites

this is my code:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
HotKeySet('{F2}', 'Esc')

Global $tPOINT = DllStructCreate("int X;int Y")



While 1
    Sleep(10)
    DllStructSetData($tPOINT, 'X', _WinAPI_GetMousePosX())
    DllStructSetData($tPOINT, 'Y', _WinAPI_GetMousePosY())

    $hWnd = _WinAPI_WindowFromPoint($tPOINT)
    ToolTip('' & _WinAPI_GetWindowText($hWnd), 0, 0)
    
WEnd

Func Esc()
    Exit
EndFunc  ;==>Esc

with that code I get the text of the control, but I need the name of the window that own the control

Share this post


Link to post
Share on other sites

Well, you have to use _WinAPI_GetParetn, as evilertoaster said :mellow:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
HotKeySet('{F2}', 'Esc')

Global $tPOINT = DllStructCreate("int X;int Y")



While 1
    Sleep(10)
    $tPOINT= _WinAPI_GetMousePos()

    $hWnd = _WinAPI_WindowFromPoint($tPOINT)
    ; Get the "real" parent window ( also from child of child :) )
    $hWnd2 = $hWnd
    Do 
        $hWnd = $hWnd2
        $hWnd2 = _WinAPI_GetParent($hWnd)
    Until $hWnd2=0
    $title = WinGetTitle($hWnd)
    ; Show Class for Window without Title
    If $title = "" Then $title = "[CLASS:"&_WinAPI_GetClassName($hWnd)&"]"
    ToolTip($title, 0, 0)
    
WEnd

Func Esc()
    Exit
EndFunc  ;==>Esc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

yes, now works thx

Share this post


Link to post
Share on other sites

Because a Parent can have a Parent... I use...

user32.dll - GetAncestor() with $GA_ROOT=2

Retrieves the root window by walking the chain of parent windows.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey. this is better... didn't know that it exists :mellow:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
HotKeySet('{F2}', 'Esc')

Global $tPOINT = DllStructCreate("int X;int Y")



While 1
    Sleep(10)
    $tPOINT= _WinAPI_GetMousePos()

    $hWnd = _WinAPI_WindowFromPoint($tPOINT)
    ; Get the "real" parent window ( also from child of child smile.gif )
    $hWnd2 = _WinAPI_GetAncestor($hWnd,2)
    If Not($hWnd2 = 0) Then $HWnd = $hWnd2
    $title = WinGetTitle($hWnd)
    ; Show Class for Window without Title
    If $title = "" Then $title = "[CLASS:"&_WinAPI_GetClassName($hWnd)&"]"
    ToolTip($title, 0, 0)
   
WEnd

Func Esc()
    Exit
EndFunc  ;==>Esc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

yes u are right:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
HotKeySet('{F2}', 'Esc')

Global $tPOINT = DllStructCreate("int X;int Y")

While 1
    Sleep(10)
    $tPOINT = _WinAPI_GetMousePos()
    $hWnd = _WinAPI_WindowFromPoint($tPOINT)
    ToolTip('' & _WinAPI_GetWindowText(_WinAPI_GetAncestor($hWnd, 2)), 0, 0)
WEnd

Func Esc()
    Exit
EndFunc  ;==>Esc

Share this post


Link to post
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
Sign in to follow this  
Followers 0