/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 7 example program 1
_ ## Author: xwlee
_ ## Time: 2007.06.22
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 7-1 connect
_ ## Connect. c file
_ ## Simple mouse processing: An Example
_ ## The program is only for verification
_##
_##
_ ## Connect. c -- connect-the-dots mouse demo program
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/
# Include <windows. h>
# Define maxpointes 1000
Lresult callback wndproc (hwnd, uint, wparam, lparam );
Int winapi winmain (hinstance, hinstance hprevinstance,
Pstr szcmdline, int icmdshow)
{
Static tchar szappname [] = text ("Connect ");
Hwnd;
MSG;
Wndclass;
Wndclass. Style = cs_hredraw | cs_vredraw;
Wndclass. lpfnwndproc = wndproc;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hinstance = hinstance;
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. lpszmenuname = NULL;
Wndclass. lpszclassname = szappname;
If (! Registerclass (& wndclass ))
{
MessageBox (null, text ("program requires Windows NT! "),
Szappname, mb_iconerror );
Return 0;
}
Hwnd = createwindow (szappname, text ("connect-the-points mouse Demo "),
Ws_overlappedwindow,
Cw_usedefault, cw_usedefault,
Cw_usedefault, cw_usedefault,
Null, null, hinstance, null );
Showwindow (hwnd, icmdshow );
Updatewindow (hwnd );
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return msg. wparam;
}
Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Static point PT [maxpoints];
Static int icount;
HDC;
Int I, J;
Paintstruct pS;
Switch (Message)
{
Case wm_lbuttondown:
Icount = 0;
Invalidaterect (hwnd, null, true );
Return 0;
Case wm_mousemove:
If (wparam & mk_lbutton & icount <1000)
{
PT [icount]. x = loword (lparam );
PT [icount ++]. Y = hiword (lparam );
HDC = getdc (hwnd );
Setpixel (HDC, loword (lparam), hiword (lparam), 0 );
Releasedc (hwnd, HDC );
}
Return 0;
Case wm_lbuttonup:
Invalidaterect (hwnd, null, false );
Return 0;
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Setcursor (loadcursor (null, idc_wait ));
Showcursor (true );
For (I = 0; I <icount-1; I ++)
For (j = I + 1; j <icount; j ++)
{
Movetoex (HDC, PT [I]. X, PT [I]. Y, null );
Lineto (HDC, PT [J]. X, PT [J]. y );
}
Showcursor (false );
Setcursor (loadcursor (null, idc_arrow ));
Endpaint (hwnd, & PS );
Return 0;
Case wm_destroy:
Postquitmessage (0 );
Return 0;
}
Return defwindowproc (hwnd, message, wparam, lparam );
}