/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 7 example Program 2
_ ## Author: xwlee
_ ## Time: 2007.06.22
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 7-2 checker1
_ ## Checker1.c File
_ ## Simple mouse processing: An Example
_ ## The program is only for verification
_##
_##
_ ## Checker1.c -- connect-the-dots mouse demo program
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/
# Include <windows. h>
# Define divisions 10
Lresult callback wndproc (hwnd, uint, wparam, lparam );
Int winapi winmain (hinstance, hinstance hprevinstance, pstr sz1_line, int icmdshow)
{Static tchar szappname [] = text ("checker1 ");
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 ("checker1 mouse hit-test 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 bool fstate [divisions] [divisions];
Static int cxblock, cyblock;
HDC;
Int X, Y;
Paintstruct pS;
Rect;
Switch (Message)
{
Case wm_size:
Cxblock = loword (lparam)/divisions;
Cyblock = hiword (lparam)/divisions;
Return 0;
Case wm_lbuttondown:
X = loword (lparam)/cxblock;
Y = hiword (lparam)/cyblock;
If (x <divisions & Y <divisions)
{
Fstate [x] [Y] ^ = 1;
Rect. Left = x * cxblock;
Rect. Top = y * cyblock;
Rect. Right = (x + 1) * cxblock;
Rect. Bottom = (Y + 1) * cyblock;
Invalidaterect (hwnd, & rect, false );
}
Else
Messagebeep (0 );
Return 0;
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
For (x = 0; x <divisions; X ++)
For (y = 0; y <divisions; y ++)
{
Rectangle (HDC, x * cxblock, y * cyblock,
(X + 1) * cxblock, (Y + 1) * cyblock );
If (fstate [x] [Y])
{
Movetoex (HDC, x * cxblock, y * cyblock, null );
Lineto (HDC, (x + 1) * cxblock, (Y + 1) * cyblock );
Movetoex (HDC, x * cxblock, (Y + 1) * cyblock, null );
Lineto (HDC, (x + 1) * cxblock, y * cyblock );
}
}
Endpaint (hwnd, & PS );
Return 0;
Case wm_destroy:
Postquitmessage (0 );
Return 0;
}
Return defwindowproc (hwnd, message, wparam, lparam );
}