#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