LINEDEMO程序绘制一个矩形、两条直线、一个椭圆和一个圆角矩形。该程序表明,定义了封闭矩形的这些函数确实对这些区域进行了填充,因为椭圆后面的线被隐藏了。

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

LINEDEMO显示结果

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!