-1

I am playing with python ctypes to control clicking through windows and menus and ran into an issue where I can click a button in a window and the windows contents change, yet I can't find a way to detect this change.

I used WinSpy to see if anything changes and noticed the ClassNN value increases, from #327701 to #327703.

Using the Windows API, how would I go about getting this information from a window?

EDIT: I have tried the following code, yet the information I find is inconclusive. The ClassName for example returns '??stBox' or '??2770' or even '????\x01'.

def get_window_class_information(handle, class_name):

    WNDPROC = ctypes.WINFUNCTYPE(ctypes.c_long, ctypes.c_long, ctypes.c_long, ctypes.c_long, ctypes.c_long)

    class WNDCLASSEXW(ctypes.Structure):
        """ https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowinfo """
        _fields_ = [('Size', ctypes.c_ulong),
                    ('Style', ctypes.c_ulong),
                    ('Procedure', WNDPROC),
                    ('ClassExtra', ctypes.c_long),
                    ('WindowExtra', ctypes.c_long),
                    ('Instance', ctypes.c_void_p),
                    ('Icon', ctypes.c_void_p),
                    ('Cursor', ctypes.c_void_p),
                    ('Background', ctypes.c_void_p),
                    ('MenuName', ctypes.c_wchar_p),
                    ('ClassName', ctypes.c_wchar_p),
                    ('IconSmall', ctypes.c_void_p)]

        def __init__(self):
            self.Size = ctypes.sizeof(self)
            super().__init__()

    window_class = WNDCLASSEXW()
    user32.GetClassInfoExW(handle, class_name, ctypes.byref(window_class))
    return window_class
Cody DeGhetto
  • 143
  • 1
  • 7

1 Answers1

0

It looks like you are looking for GetClassName,

Retrieves the name of the class to which the specified window belongs.

Note: You need to get the window hwnd first.

Updated:

After testing, I found that the class name of ordinary win32 windows will not change after redrawing. So relying only on the class name is not enough. You may need to use the hook to detect the drawing api of the window. For details, please refer to @valdo answer.

Strive Sun
  • 5,988
  • 1
  • 9
  • 26