28.3 The mouse wheel

Though not everyone has a wheel mouse yet, they are becoming more popular. If you don't have one, you really should get one, as the wheel makes it a lot easier to scroll through all the files you have to look at when you're programming. An additional good feature of some wheel mice (such as Microsoft's high-end one) is that you can press down on the wheel to simulate a double click.

You can add a handler for WM_MOUSEWHEEL to add a method BOOL CPopView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt). Check the Visual Studio help for the meaning of the arguments.

For our purposes, we only want the mouse wheel to scroll through the different tool types. In the Pop Framework build, the mouse wheel scrolls through all the available cursors for each game. Thanks to encapsulation and OOP, the mouse wheel code is particularly clean.

BOOL CPopView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{ 
/* Swap the cursor functionality, depending which cursors the game 
    uses. We just use the sign of zdelta, which will be some positive 
    or negative number, depending on which way and how far you turned 
    the wheel. */ 

    pgame()->nextHCURSOR(_hCursor, zDelta); 
    return TRUE; 
} 


    Part I: Software Engineering and Computer Games
    Part II: Software Engineering and Computer Games Reference