It sets ErrorLevel. The codes are:
0: Success
1: No window with the specified hWnd could be found.
2: The specified window is a top-level window.
3: The specified control's class name could not be retrieved.
4: The specified control's class atom could not be retrieved.
5: The control could not be found by EnumChildWindows().
Code: Select all
GetClassNN(hWnd) {
static FindNN := RegisterCallback("GetClassNN@FindNN", "Fast", 2)
If !DllCall("IsWindow", "Ptr", hWnd)
return "", ErrorLevel := 1
If (Main := DllCall("GetAncestor", "Ptr", hWnd, "Int", 2, "UPtr")) == hWnd
return "", ErrorLevel := 2
If not Atom := DllCall("GetClassWord", "Ptr", hWnd, "Int", -32, "UShort")
return "", ErrorLevel := 4
VarSetCapacity(Data, 2 * A_PtrSize + 2, 0), NumPut(Atom, Data, "UShort"), NumPut(hWnd, Data, 2)
If DllCall("EnumChildWindows", "Ptr", Main, "Ptr", FindNN, "Str", Data)
return "", ErrorLevel := 5
VarSetCapacity(Class, 257 << (A_IsUnicode = true), 0)
return DllCall("GetClassName", "Ptr", hWnd, "Str", Class, "Int", 257) ? (Class NumGet(Data, A_PtrSize + 2), ErrorLevel := 0) : ("", ErrorLevel := 3)
}
GetClassNN@FindNN(Ctrl, DataAddress) {
If DllCall("GetClassWord", "Ptr", Ctrl, "Int", -32, "UShort") == NumGet(DataAddress + 0, "UShort")
NumPut(NumGet(DataAddress + 0, A_PtrSize + 2) + 1, DataAddress + 0, A_PtrSize + 2)
return Ctrl <> NumGet(DataAddress + 0, 2)
}