Monday 28 November 2011

Can a mouse click be captured in an area outside your program’s client area? in C programming

Can a mouse click be captured in an area outside your program’s client area?

In Windows, the client area of your program includes all the space within the border of your window, with the exception of the following areas:
  •   The title bar
  •  The scrollbars
  •   The pull-down menu
Can a mouse click be captured within any of these three regions? Yes. When the mouse is clicked in these regions, Windows sends a “nonclient area” message to your program. This way, you can trap for these events
when they occur.

Trapping for these events is unusual, however. This is because Windows has prebuilt functionality to handle mouse clicks in these regions. For instance, if you double-click on a window’s title bar, the window resizes itself (maximized or restored). If you click on a scrollbar, the window scrolls. If you click on a pull-down menu, the menu is shown on-screen. None of these events requires any code to be written—they are automatically handled by Windows.

Most of the time, you will want to pass these messages to what is called the DefWindowProc() function. The DefWindowProc() calls the default window procedure (that is, it implements the window’s built-in functionality). You very rarely would need to trap for a nonclient mouse hit. Nonetheless, Table XXI.20 presents some of the messages you can trap for.

Nonclient area mouse events.
--------------------------------------------------------------------------------------------------------------
Nonclient Message                                   Meaning
--------------------------------------------------------------------------------------------------------------
WM_NCLBUTTONDOWN                   Nonclient left mouse button down
WM_NCMBUTTONDOWN                  Nonclient middle mouse button down
WM_NCRBUTTONDOWN                   Nonclient right mouse button down
WM_NCLBUTTONUP                           Nonclient left mouse button up
WM_NCMBUTTONUP                          Nonclient middle mouse button up
WM_NCRBUTTONUP                           Nonclient right mouse button up
WM_NCLBUTTONDBLCLK                 Nonclient left mouse button double-click
WM_NCMBUTTONDBLCLK                Nonclient middle mouse button double-click
WM_NCRBUTTONDBLCLK                 Nonclient right mouse button double-click
--------------------------------------------------------------------------------------------------------------

Cross Reference:

XXI.14: How do you determine a Windows program’s client area size?

No comments:

Post a Comment