Jump to content

get window's handle from control's handle


oMBRa
 Share

Recommended Posts

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

Link to comment
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

Link to comment
Share on other sites

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

Link to comment
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
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...