One of the apps I'm trying to control has randomized classnames, making it very difficult to find the control I want to target. Sometimes the control I'm looking for is implemented via a separate ocx (eg. "vsflex7n.ocx"). This function fetches the OCX filename, which sometimes allows you to locate the desired control.
This is the same information that the WinSpy-like
WinID displays.
(note: this is different from other examples of GetModuleFileNameExA() here, since you give an
hWnd rather than a
pid to the funtion)
Code:
#SingleInstance force
#Persistent
SetTimer,repeat,100 ; ten times a second
repeat:
MouseGetPos,,,,mouseover_class
MouseGetPos,,,,mouseover_hwnd,2
filename := GetControlFilename(mouseover_hwnd)
ToolTip,class: %mouseover_class%`nfilename:%filename%
return
; Get the .ocx/.dll that implements a particular control.
GetControlFilename(hwnd)
{
hInstance := DllCall("GetWindowLong", "uint", hwnd, "uint", GWW_HINSTANCE:=-6)
WinGet, pPID, PID, ahk_id %hwnd%
; you must have permission to open the process... this may require admin on WinXP or later
hProcess := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", pPID )
VarSetCapacity( filename, name_size:=255 )
DllCall( "psapi.dll\GetModuleFileNameExA", "uint", hProcess, "uint", hInstance, "str", filename, "uint", name_size )
DllCall( "CloseHandle", hProcess )
return filename
}
[/b]