Search code examples
windowswinapihwnd

What's the format value from the HWND returned from CreateWindow()?


Is this a memory address ranging to (theorically) 2^32-1 on 32-bit machine? The reason I'd like to know that is I'm trying to somehow associate a HWND returned by CreateWindow() to a class instance, so in order to know how properly store that HWND value, I need to know what's the values like, so I can see what can fit better, AA array, linked list with hash table, etc.


Solution

  • From the documentation for MFC (to avoid confusion: this is documentation where CWnd and "window object" in the article is a C++ class in your program, not USER32):

    The Windows window, on the other hand, is an opaque handle to an internal Windows data structure that corresponds to a window and consumes system resources when present.

    Opaque handles must be treated as "black boxes" or atomic blobs that must not be altered and likely won't reveal any useful information through introspection either.

    Also, see Wikipedia: https://en.wikipedia.org/wiki/Handle_(computing)