Programming Windows Programming Design Guide-> Chapter 8 example Program 2

Source: Internet
Author: User

/*_##################################### #######################################
_##
### Programming Windows Programming Design Guide-> Chapter 8 example Program 2
_ ## Author: xwlee
_ ## Time: 2007.06.26
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Program 8-2 beeper2
_ ## Beeper2.c File
_ ## Simple Timer: An Example
_ ## The program is only for verification
_##
_##
_ ## Beeper2.c -- timer demo program No. 2
_ ## (C) Charles Petzold, 1998
_##
_####################################### ###################################*/
# Include <windows. h>
# Define id_timer 1

Lresult callback wndproc (hwnd, uint, wparam, lparam );
Void callback timerproc (hwnd, uint, uint, DWORD );

Int winapi winmain (hinstance, hinstance hprevinstance,
Pstr szcmdline, int icmdshow)
{
Static char szappname [] = "beeper2 ";
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, "beeper2 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)
{
Switch (Message)
{
Case wm_create:
Settimer (hwnd, id_timer, 1000, timerproc); // here
Return 0;

Case wm_destroy:
Killtimer (hwnd, id_timer );
Postquitmessage (0 );
Return 0;
}
Return defwindowproc (hwnd, message, wparam, lparam );
}

Void callback timerproc (hwnd, uint message, uint itimerid, DWORD dwtime)
{
Static bool fflipflop = false;
Hbrush;
HDC;
Rect RC;

Messagebeep (-1 );
Beep (5000,100 );

Fflipflop =! Fflipflop;

Getclientrect (hwnd, & rc );
HDC = getdc (hwnd );
Hbrush = createsolidbrush (fflipflop? RGB (255, 0): RGB ));

Fillrect (HDC, & rc, hbrush );
Releasedc (hwnd, HDC );
 
Deleteobject (hbrush );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.