Search code examples
c++winapihwnd

how to get text from a window with specific HWND?


I'm new to win32 programming and haven't worked around with cpp for a long time. What I intend to do is to get a window's HWND via spy++, and get the text of this window. The problem is that I don't know how to create a HWND object, could anyone give me some idea? Thanks a lot!


Solution

  • If you have the numeric value of the HWND, you can cast it to the right type. Start with an integer of the right size, e.g.:

    uintptr_t numeric_hwnd = 0x987654;
    HWND hwnd = reinterpret_cast<HWND>(numeric_hwnd);