Game Development Reference
In-Depth Information
case WM_LBUTTONUP:
// The user has finished drawing the line. Reset the
// previous line flag, release the mouse cursor, and
// release the mouse capture.
fPrevLine = FALSE;
bIsCaptured = false;
ReleaseCapture();
break;
}
case WM_ACTIVATEAPP:
{
if (wParam == TRUE)
{
// got focus again
-
regain our mouse capture
if (bIsCaptured)
SetCapture(hwndMain);
}
break;
}
return 0;
}
If you were to write functions for erasing and drawing lines, you
d have a nice rubber
band line-drawing mechanism, which mouse capturing makes possible. By using it,
your lines will continue to follow the mouse, even if you leave the window
'
'
s client
area.
One thing to note: If your application loses focus, you
ll also lose the mouse capture,
which can be handled easily by listening to the WM_ACTIVATEAPP message.
'
Making a Mouse Drag Work
You might wonder why a mouse drag is so important. Drags are important because
they are prerequisites to much of the user interface code in a lot of PC games. When
you select a group of combatants in RTS games like good old Command & Conquer,
for example, you drag out a rectangle. When you play Freecell in Windows, you use
the mouse to drag cards around. It is quite likely that you
'
ll have to code a mouse
drag at some point.
Dragging the mouse adds a little complexity to the process of capturing it. Most user
interface code distinguishes a single-click, double-click, and drag as three separate
actions, and therefore will call different game code. Dragging also relates to the
 
 
Search WWH ::




Custom Search