It actually isn't sent immediately after creation, but can be received anytime after creation if the window has a Non-Client area defined. Windows have two major regions, Client and Non-Client. The Non-Client area is the outer border/margin of a window, and the client area can be considered the 'body' of the window. This is the area where you will get the most activity, and usually this is the intended area of a window where a user should interact. Of course, sometimes other parties will make controls that have no non-client areas and yet still display their own borders and other details.
For almost all stock controls (anything in the Common Control Library and other window-based controls published by Microsoft), the following areas are treated as Non-Client areas.
- Captions Caption Details
- System Menu / Minimize / Maximize / Close
- Borders
Messages that are prefixed with NC represent events that occurred in Non-Client areas of the window. Messages without the prefix are in the Client area.
Anyhow, I presume that you have a function that is tracking mouse events on a specific window. If there is a need to track any movement over the non-client areas of the window (say, for dragging or hover operations) you'll want to add the following messages to your mouse tracking.
(mouse position has changed in a non-client area)
- WM_NCLBUTTONDBLCLK
- WM_NCLBUTTONDOWN
- WM_NCLBUTTONUP
(left-button actions in non-client area)
- WM_NCMBUTTONDBLCLK
- WM_NCMBUTTONDOWN
- WM_NCMBUTTONUP
(middle-button actions in non-client area)
- WM_NCRBUTTONDBLCLK
- WM_NCRBUTTONDOWN
- WM_NCRBUTTONUP
(right-button actions in non-client area)
In addition, depending on your application, the following messages may be of interest as well.
(window activation has changed by user action and the non-client area needs to be updated)
(window manager wants to know if the non-client area is tracking mouse activity)
(non-client area needs to be repainted)
A useful trick for determining the visual extent of a Non-Client area is to intercept the WM_NCPAINT message and just paint the non-client area in a color of your choice (red/pink or some other color that stands out). This is useful for debugging situations where you have multiple windows adjacent to each other with non-client areas that should appear seamless.
Finally, here is a link that has demo source code that may worth examining to see how Non-Client areas work.
Customizing the Non-client Area from CodeProject (VB)