-2

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.

Jack
  • 16,276
  • 55
  • 159
  • 284
  • 1
    The HWND is an opaque value. IOW, you can know nothing about it other than the fact that it's a window handle. The internal structure is not documented by MS because it's not supposed to be used as anything but a window handle. – Ken White Jan 12 '21 at 01:19
  • https://learn.microsoft.com/en-us/cpp/mfc/relationship-between-a-cpp-window-object-and-an-hwnd?view=msvc-160 – Dai Jan 12 '21 at 01:20
  • if your formal ask for format - as general knowledge but not for usage - low 16 bits of `HWND` used as index in windows handle table. the next 16 bits used as reuse index - when a cell is used for the first time this index is 1. when this cell is reused, the index is increased by 1. and so on – RbMm Jan 12 '21 at 02:17
  • 1
    *associate a HWND returned by CreateWindow() to a class instance* - for this `GWLP_USERDATA` used – RbMm Jan 12 '21 at 02:20

2 Answers2

2

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)

Dai
  • 141,631
  • 28
  • 261
  • 374
2

To store a value you need to know its type only. As documented under Windows Data Types, an HWND is a type alias for a HANDLE, which is a type alias for PVOID, which in turn is a type alias for void*.

In other words: An HWND is a pointer to unknown data. It's pointer-sized and trivially copy-able.

IInspectable
  • 46,945
  • 8
  • 85
  • 181