/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 5 example program 7
_ ## Author: xwlee
_ ## Time: 2007.06.20
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 5-7 clover
_ ## Clover. c file
### Using complex cropping areas, you can draw these lines directly, and let windows determine its endpoint
_ ## The program is only for verification
_##
_##
_ ## Clover. c -- clover drawing program using regions
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/
# Include <windows. h>
# Include <math. h>
# Define two_pi (2.0*3.14159)
Lresult callback wndproc (hwnd, uint, wparam, lparam );
Int winapi winmain (hinstance, hinstance hprevinstance,
Pstr szcmdline, int icmdshow)
{
Static tchar szappname [] = text ("clover ");
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 ("this program requires Windows NT! "),
Szappname, mb_iconerror );
Return 0;
}
Hwnd = createwindow (szappname, text ("draw a clover "),
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 imsg, wparam, lparam)
{
Static hrgn hrgnclip;
Static int cxclient, cyclient;
Double fangle, fradius;
Hcursor;
HDC;
Hrgn hrgntemp [6];
Int I;
Paintstruct pS;
Switch (imsg)
{
Case wm_size:
Cxclient = loword (lparam );
Cyclient = hiword (lparam );
Hcursor = setcursor (loadcursor (null, idc_wait ));
Showcursor (true );
If (hrgnclip)
Deleteobject (hrgnclip );
Hrgntemp [0] = createellipticrgn (0, cyclient/3,
Cxclient/2, 2 * cyclient/3 );
Hrgntemp [1] = createellipticrgn (cxclient/2, cyclient/3,
Cxclient, 2 * cyclient/3 );
Hrgntemp [2] = createellipticrgn (cxclient/3, 0,
2 * cxclient/3, cyclient/2 );
Hrgntemp [3] = createellipticrgn (cxclient/3, cyclient/2,
2 * cxclient/3, cyclient );
Hrgntemp [4] = createrectrgn (0, 0, 1, 1 );
Hrgntemp [5] = createrectrgn (0, 0, 1, 1 );
Hrgnclip = createrectrgn (0, 0, 1, 1 );
Combinergn (hrgntemp [4], hrgntemp [0], hrgntemp [1], rgn_or );
Combinergn (hrgntemp [5], hrgntemp [2], hrgntemp [3], rgn_or );
Combinergn (hrgnclip, hrgntemp [4], hrgntemp [5], rgn_xor );
For (I = 0; I <6; I ++)
Deleteobject (hrgntemp [I]);
Setcursor (hcursor );
Showcursor (false );
Return 0;
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Setviewportorgex (HDC, cxclient/2, cyclient/2, null );
Selectcliprgn (HDC, hrgnclip );
Fradius = _ hypot (cxclient/2.0, cyclient/2.0 );
For (fangle = 0.0; fangle <two_pi; fangle + = two_pi/360)
{
Movetoex (HDC, 0, 0, null );
Lineto (HDC, (INT) (fradius * Cos (fangle) + 0.5 ),
(INT) (-fradius * sin (fangle) + 0.5 ));
}
Endpaint (hwnd, & PS );
Return 0;
Case wm_destroy:
Deleteobject (hrgnclip );
Postquitmessage (0 );
Return 0;
}
Return defwindowproc (hwnd, imsg, wparam, lparam );
}