28.1. Mouse messages

Processing a mouse message

Windows generates a number of mouse-related messages, including WM_MOUSEMOVE and WM_ONLBUTTONDOWN. MFC handles these two with message handlers normally called OnMouseMove and OnLButtonDown.

The programmer is free to decide which class is to hold the handler methods. One way to do this is to open the Class View and to right click on the name of class that is supposed to handle the mouse message. In Visual Studio.NET you then select Properties... and click on the Message button in the Properties dialog. (In Version 6.0, you right click the class and select Add Windows Message Handler....)

In any case, the default message handler you’ll get for WM_MOUSEMOVE will look like this.

 void CPopView::OnMouseMove(UINT ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.