It's handy to create a c++ class that contains everything needed for a
particular window. It would contain all the data that needs to be
retained while the program is active, and methods to handle any
windows messages that need to be dealt with.
Any information about a window that you give to windows (icon, position,
etc), doesn't need to be saved in the class, because windows has it, and
it can be retrieved as needed. The exception would be something that is
needed so often that the function calls to retrieve and set it affects program performance.
The best way to connect the class instance to the window is to save a
pointer to it in the windows extra bytes (that you allocated).
There are four ways to handle the connecting the class instance to the window.
- You can pass a pointer to the instance as the lParam arg to
CreateWindowEx. In this case, the pointer is not available to the
window's callback and therefore the window's message handlers until
until the WM_CREATE message. If you do this, you have to use
SetWindowLong to save the point to the instance for future reference.
- You could just wait until CreateWindowEx returns, create the class
instance, then use SetWindowLong to associate a pointer to the
instance with the window. Same caveat as above, but the class instance
is not available until CreateWindowEx returns.
- You can create the instance the first time the window's callback is
passed a message. In this case, the class instance is available to the
window from the start, but you can't get to it, or specify any values until
CreateWindowEx returns.
- You can create the class first. Set any values that need to be set,
then call CreateWindowEx with the pointer to the class. But the
window still does not get the pointer until the WM_CREATE message.
class window {
};
Steps:
1) create an instance of the c++ window class.
2) register the windows window class.
3) create the window.
4) ShowWindow()
5) UpdateWindow()