Learn how Windows programming Day6 handles mouse movement

Source: Internet
Author: User

#define Point_max 1000

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
HDC hdc;
Paintstruct PS;
Rect rect;
static int cxclient, cyclient;
Static Point Pt[point_max];
static int iCount;
int x, y;

Switch (message)
{
Case WM_LBUTTONDOWN:
ICount = 0;
InvalidateRect (hwnd, NULL, TRUE);
Break
Case wm_mousemove://When a wm_mousemove message is processed, it will not go to the system message queue to remove the next one, so the mouse is not always moving will always produce wm_mousemove messages in the message queue, which can also produce other messages
if (Wparam&mk_lbutton && Icount<point_max)
{
pt[icount].x = Get_x_lparam (LPARAM),//More reliable than LoWord (LPARAM), LoWord (LPARAM) error in multi-screen display
Pt[icount++].y = Get_y_lparam (LPARAM);

HDC = GetDC (hwnd);
Setpixelv (hdc, Get_x_lparam (LPARAM), Get_y_lparam (LPARAM), 0);
ReleaseDC (hwnd, HDC);
}
Break
Case WM_LBUTTONUP:
InvalidateRect (hwnd, NULL, FALSE);//Do not erase background, generate WM_PAINT message
Break
Case WM_SIZE:
Cxclient = LoWord (LParam);
Cyclient = HiWord (LParam);
Break
Case WM_PAINT:
HDC = BeginPaint (hwnd, &PS);
GetClientRect (hwnd, &rect);

SetCursor (LoadCursor (NULL, idc_wait));
Windows saves a "display count" for the mouse cursor if the mouse is installed, it will initially be 0, otherwise-1
ShowCursor (true) increments the display count and displays the mouse cursor when it is not 0 o'clock
ShowCursor (TRUE);//1
for (x = 0; x < icount;x++)
{
for (y = x+1; y < icount;y++)
{
Movetoex (hdc, pt[x].x, PT[X].Y, NULL);
LineTo (hdc, pt[y].x, PT[Y].Y);
}
}
Reduce display count
ShowCursor (FALSE);//0
Make two pairs appear without affecting the operation of the mouse elsewhere

SetCursor (LoadCursor (NULL, Idc_arrow)); Toggle two Alternate pointers
After setting the mouse will display the style, do not need ShowCursor (true)
(without moving the mouse will not change, when the mouse movement will revert to the original cursor graph, because when the wm_mouseove is generated, the system will automatically change the mouse to the original (the cursor set at the time of registration)

EndPaint (hwnd, &PS);
Break
Case Wm_destroy:
PostQuitMessage (0);
return 0;
}


Return DefWindowProc (HWND, message, WParam, LParam);
}

Learn how Windows programming Day6 handles mouse movement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.