Search code examples
c++wrapperwindows-messages

How to avoid WM_APP


I am writing a CFrameWnd wrapper and I have this line in the header file :

#define WM_CFW_MESSAGE              (WM_APP + 100)

Is this is a good practice ? Does it require that users of this wrapper will have to remember not to use this particular number (WM_APP + 100) ?


Solution

  • No, it's not a good practice. The WM_USER range is more suitable. The WM_APP range is intended for messages that must be understood by multiple window classes in a single program. The WM_USER range is intended for messages that are intended for a single window class.

    Therefore, you can safely use values in WM_USER range. You can write #define WM_CFW_MESSAGE (WM_USER+0) because you know that your window class has no other WM_USER messages. When you add a second custom message to the same window class, you can use (WM_USER+1), etcetera. If you implement another window class, it can start at WM_USER+0 again.