Jump to content

How to get the instance number of a window.


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
;
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...