当前位置:亚洲城ca88 > 亚洲城 > 第八章 沙漏(BEEPEOdyssey1)

第八章 沙漏(BEEPEOdyssey1)

文章作者:亚洲城 上传时间:2019-11-03

亚洲城 1亚洲城 2

 1 *-------------------------------------
 2     BEEPER1.C -- Timer Demo Program No.1
 3     (c) Charles Petzold, 1998
 4     -------------------------------------*/
 5 
 6 #include <Windows.h>
 7 
 8 #define ID_TIMER 1
 9 
10     LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
11 
12 int WINAPI WinMain( __in HINSTANCE hInstance
13     , __in_opt HINSTANCE hPrevInstance
14     , __in LPSTR lpCmdLine
15     , __in int nShowCmd )
16 {
17     static TCHAR szAppName[] = TEXT("Bepper1");
18     HWND hwnd;
19     MSG msg;
20     WNDCLASS wndclass;
21 
22     wndclass.style = CS_HREDRAW | CS_VREDRAW;
23     wndclass.lpfnWndProc = WndProc;
24     wndclass.cbClsExtra = 0;
25     wndclass.cbWndExtra = 0;
26     wndclass.hInstance = hInstance;
27     wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
28     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
29     wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
30     wndclass.lpszMenuName = NULL;
31     wndclass.lpszClassName = szAppName;
32 
33     if (!RegisterClass(&wndclass))
34     {
35         MessageBox(NULL, TEXT("Program requires Windows NT!")
36             , szAppName, MB_ICONERROR);
37         return 0;
38     }
39 
40     hwnd = CreateWindow(szAppName, TEXT("Beeper1 Timer Demo")
41         , WS_OVERLAPPEDWINDOW
42         , CW_USEDEFAULT, CW_USEDEFAULT
43         , CW_USEDEFAULT, CW_USEDEFAULT
44         , NULL, NULL, hInstance, NULL);
45 
46     ShowWindow(hwnd, nShowCmd);
47     UpdateWindow(hwnd);
48 
49     while (GetMessage(&msg, NULL, 0, 0))
50     {
51         TranslateMessage(&msg);
52         DispatchMessage(&msg);
53     }
54 
55     return msg.wParam;
56 }
57 
58 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
59 {
60     static BOOL fFlipFlop = FALSE;
61     HBRUSH hBrush;
62     HDC hdc;
63     PAINTSTRUCT ps;
64     RECT rc;
65 
66     switch (message)
67     {
68     case WM_CREATE:
69         SetTimer(hwnd, ID_TIMER, 1000, NULL);
70         return 0;
71 
72     case WM_TIMER:
73         MessageBeep(-1);
74         fFlipFlop = !fFlipFlop;
75         InvalidateRect(hwnd, NULL, FALSE);
76         return 0;
77 
78     case WM_PAINT:
79         hdc = BeginPaint(hwnd, &ps);
80 
81         GetClientRect(hwnd, &rc);
82         hBrush = CreateSolidBrush(fFlipFlop ? RGB(255, 0, 0) : RGB(0, 0, 255));
83         FillRect(hdc, &rc, hBrush);
84 
85         EndPaint(hwnd, &ps);
86         DeleteObject(hBrush);
87         return 0;
88 
89     case WM_DESTROY:
90         KillTimer(hwnd, ID_TIMER);
91         PostQuitMessage(0);
92         return 0;
93     }
94 
95     return DefWindowProc(hwnd, message, wParam, lParam);
96 }

亚洲城,BEEPER1.C

 

本文由亚洲城ca88发布于亚洲城,转载请注明出处:第八章 沙漏(BEEPEOdyssey1)

关键词: 亚洲城ca88