The 10 mouse messages discussed so far occur when the mouse is moved or clicked within the client area of a window. If the mouse is outside a window's client area but still within the window, Windows sends the window procedure a ”nonclient-area“ mouse message. The nonclient area includes the caption bar, the menu, and window scroll bars.
You do not usually need to process nonclient-area mouse messages. Instead, you simply pass them on to DefWindowProc so Windows can perform system functions. In this respect, the nonclient-area mouse messages are similar to the system keyboard messages WM_SYSKEYDOWN, WM_SYSKEYUP, and WM_SYSCHAR.
The nonclient-area mouse messages parallel almost exactly the client-area mouse messages. The messages include the letters ”NC“ to indicate ”nonclient.“ If the mouse is moved within a nonclient area of a window, then the window procedure receives the message WM_NCMOUSEMOVE. The mouse buttons generate these messages:
Button | Pressed | Released | Pressed (2d Click) |
Left | WM_NCLBUTTONDOWN | WM_NCLBUTTONUP | WM_NCLBUTTONDBLCLK |
Middle | WM_NCMBUTTONDOWN | WM_NCMBUTTONUP | WM_NCMBUTTONDBLCLK |
Right | WM_NCRBUTTONDOWN | WM_NCRBUTTONUP | WM_NCRBUTTONDBLCLK |
However, the wParam and lParam parameters for nonclient-area mouse messages are different from those for client-area mouse messages. The wParam parameter indicates the nonclient area where the mouse was moved or clicked. It is set to one of the identifi- ers beginning with HT that are defined in WINDOWS.H (such as HTCAPTION and HTSYSMENU).
The lParam variable contains an x-coordinate in the low word and a y-coordinate in the high word. However, these are screen coordinates, not client-area coordinates as they are for client-area mouse messages. For screen coordinates, the upper left corner of the display area has x and y values of 0. Values of x increase as you move to the right, and values of y increase as you move down. (See Figure 4-3.)
You can convert screen coordinates to client-area coordinates and vice versa with two Windows functions:
ScreenToClient (hwnd, lpPoint) ;
ClientToScreen (hwnd, lpPoint) ;
The lpPoint parameter is a far (or long) pointer to a structure of type POINT. These two functions convert the values stored in the structure without preserving the old values. Note that if a screen-coordinate point is above the window's client area, then the converted client-area y-coordinate will be negative. Similarly, a screen coordinate to the left of a client area is a negative x value when expressed as a client-area coordinate.