what does the return false mean? shouldn't we return int?
|
The numeric value of false is an int, or at least can be promoted to one.
That logic you show is based on the idea that if the CreateWindow() call for the main program window fails, there isn't much sense in doing anything beyond exiting WinMain().
In terms of your question about the way the switch is structured in the Window Procedure, never, ever try what you suggest. It is critical to the internal workings of Windows that the correct return value for each message processed be used. If you intend to handle some specific message such as WM_CREATE, WM_PAINT, etc., then you must look up that message in the MSDN documentation, where the return value to Windows will be specified. I guarantee you will come to grief if you do not do this correctly, as the code that Windows runs internally to support your windows is depandant on what you return from each message.
The way the Window Procedure has to be set up, is that if you handle a specific message, i.e., provide code for it, you must return the value specified for that message. In most cases, although not all, the return is zero. Another way of saying this is that after your code runs for the specific message you are handling, you must exit the Window Procedure. The reason why a 'return' is used rather than a 'break' is that a 'return' causes an immediate exit, while a 'break' does not.
If you have no case clause specified for a particular message, then that message must be passed on to the default Window Procedure within Windows.
There are actually at leat two ways of accomplishing this logic, and you should become familiar with both constructs. This is actually a critical area of Windows Programming to understand.
Realize with SelectObject() that there are memory allocations involved with just about any graphics object you or Windows creates, and these memory allocations will be in your process memory. If you do not use SelectObject() and DeleteObject() properly, you'll have memory leaks in your process. For long running programs such memory leaks can crash your program.