Game Development Reference
In-Depth Information
3. The mouse moves away from the button, outside its border.
4. The button stops receiving any events from the mouse since the mouse isn ' t
directly over the button.
5. The mouse button is released.
The result is that the button will still be drawn in the down position, awaiting a but-
ton release event that will never happen. If the mouse events are captured, the button
will continue to receive mouse events until the button is released.
To better understand this, take a look at a code snippet that shows some code you
can use to capture the mouse and draw lines:
LRESULT APIENTRY MainWndProc(HWND hwndMain, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
static POINTS ptsBegin;
// beginning point
switch (uMsg)
{
case WM_LBUTTONDOWN:
// Capture mouse input.
SetCapture(hwndMain);
bIsCaptured = true;
ptsBegin = MAKEPOINTS(lParam);
return 0;
case WM_MOUSEMOVE:
// When moving the mouse, the user must hold down
// the left mouse button to draw lines.
if (wParam & MK_LBUTTON)
{
// imaginary code
you write this function
pseudocode::ErasePreviousLine();
-
// Convert the current cursor coordinates to a
// POINTS structure, and then draw a new line.
ptsEnd = MAKEPOINTS(lParam);
// also imaginary
pseudocode::DrawLine(ptsEnd.x, ptsEnd.y);
}
break;
Search WWH ::




Custom Search