/*_##################################### #######################################
_##
_ ## Programming Windows Programming Design Guide-> Chapter 8 example program 1
_ ## Author: xwlee
_ ## Time: 2007.06.26
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 8-1 beeper1
_ ## Beeper1.c File
_ ## Simple Timer: An Example
_ ## The program is only for verification
_##
_##
_ ## Beeper1.c -- timer demo program No. 1
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/
# Include <windows. h>
# Define id_timer 1
Lresult callback wndproc (hwnd, uint, wparam, lparam );
Int winapi winmain (hinstance, hinstance hprevinstance,
Pstr szcmdline, int icmdshow)
{
Static tchar szappname [] = text ("beeper1 ");
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 ("beeper1 timer 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 fflipflop = false;
Hbrush;
HDC;
Paintstruct pS;
Rect RC;
Switch (Message)
{
Case wm_create:
Settimer (hwnd, id_timer, 1000, null );
Return 0;
Case wm_timer:
// Messagebeep (110 );
Beep (2000, 50 );
Fflipflop =! Fflipflop;
Invalidaterect (hwnd, null, false );
Return 0;
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
Getclientrect (hwnd, & rc );
Hbrush = createsolidbrush (fflipflop? RGB (255, 0): RGB ));
Fillrect (HDC, & rc, hbrush );
Endpaint (hwnd, & PS );
Deleteobject (hbrush );
Return 0;
Case wm_destroy:
Killtimer (hwnd, id_timer );
Postquitmessage (0 );
Return 0;
}
Return defwindowproc (hwnd, message, wparam, lparam );
}