wndclass data questions
i was just thinking deeply about the WNDCLASS(EX) structure and i have a couple of remaining questions about the content of this struct. 1) what is the purpose and definition of the "cbClsExtra" field? 2) what is the purpose and definition of the "cbWndExtra" field?
Both of these variables allow you to append extra bytes to the end of the WNDCLASSEX structure for storing "user defined" data.
I think the limit for both is 40 extra bytes, and keep in mind that the bytes are effectively cut into 4-byte chunks (ie: the size of a pointer ;)). As an example, the "button" class has I think 8 extra class bytes (a value that Windows itself set of course).
So what good are extra bytes? Let's say that you want to store in every instance of a registered window class a pointer to an object. To retrieve that pointer, you use GetWindowLong(), and specify the offset, in bytes, that the pointer resides at in the extra window bytes. To change the pointer, just use SetWindowLong() in a similar fashion.
Windows, in fact, appends a few of it's own extra bytes to your windows that you can use right away, without adding any yourself. The offset #defined by GWL_USERDATA is useful since it's unused by Windows. In addition there is the offset GWL_WNDPROC, (probably not an extra offset, but in fact your lpfnWndProc offset *within* the confines of the structure) which stores a pointer to your window procedure, and also offsets to the class/window styles you create instances of your windows with, such as WS_VISIBLE, etc, etc.
The class extra bytes are of course accessed with GetClassLong()/SetClassLong().
These two pairs of functions are your best friends, you should experiment with them and figure out what you can do with them.
is it useful to use these extra bytes, or do you most of the time just keep them set at 0?
For now, just set them to zero. If the need ever arises, you'll know what to do. ;)
hehe :D okay, i see what you mean. as of now, i dont need to store any extra class/wnd information. thanks!