Jump to content
Sign in to follow this  
Drew

How to get the instance number of a window.

Recommended Posts

Drew

I have searched the helpfile as well as the forum for roughly 45 minutes now and cannot seem to find how how I would go about retrieving the INSTANCE: of a particular window. I've noticed that the Window tool can, so I'm sure it can be done... But I can't seem to figure it out on my own.

Can someone point me in the right direction?

Share this post


Link to post
Share on other sites
Drew

What I need can be found under the "Control" tab on the window info tool...

What I need to be able to retrieve is the number beside: Instance

You may be right about the control class , that makes sense; I didn't think of that. But the above is exactly what I need, regardless its origins.

Share this post


Link to post
Share on other sites
Malkey

This _WinGetClassNameNN() function returns the ClassnameNN of a control.

The ClassnameNN is made up of the class of a control and its instance.

;
$hWnd = WinGetHandle("");[CLASS:Notepad]")
$hWndCtrl = ControlGetHandle("", "", "");[CLASS:Notepad]","","")

MsgBox(0, "Result", "__WinGetClassNameNN: " & _WinGetClassNameNN($hWnd, $hWndCtrl) & @CRLF)

;MsgBox(0,"Handles","Active window handle:  " &  WinGetHandle('') & @CRLF  & @CRLF & _
;                  "Active control handle: " &  ControlGetHandle('',"",""))

Func _WinGetClassNameNN($hWinWnd = "", $hCtrlWnd = "")
    If $hCtrlWnd = "" Then $hCtrlWnd = ControlGetHandle("", "", "")
    Local $aRet = DllCall("User32.dll", "int", "GetClassName", "hwnd", $hCtrlWnd, "str", "", "int", 256)
    Local $sClass = $aRet[2]
    Local $iMatch = StringRegExp(WinGetClassList($hWinWnd), $sClass, 3)
    For $x = 0 To UBound($iMatch) - 1
        If ControlGetHandle($hWinWnd, "", $sClass & ($x + 1)) = $hCtrlWnd Then Return $sClass & ($x + 1)
    Next
    Return -1
EndFunc  ;==>_WinGetClassNameNN
;

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.