Patch by Jonathon Wilson:
[reactos.git] / reactos / apps / tests / lineclip / lineclip.c
1 #include <windows.h>
2 #include <stdio.h>
3
4 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
5
6 int WINAPI
7 WinMain(HINSTANCE hInstance,
8 HINSTANCE hPrevInstance,
9 LPSTR lpszCmdLine,
10 int nCmdShow)
11 {
12 WNDCLASS wc;
13 MSG msg;
14 HWND hWnd;
15
16 wc.lpszClassName = "ClipClass";
17 wc.lpfnWndProc = MainWndProc;
18 wc.style = CS_VREDRAW | CS_HREDRAW;
19 wc.hInstance = hInstance;
20 wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
21 wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
22 wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
23 wc.lpszMenuName = NULL;
24 wc.cbClsExtra = 0;
25 wc.cbWndExtra = 0;
26 if (RegisterClass(&wc) == 0)
27 {
28 fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
29 GetLastError());
30 return(1);
31 }
32
33 hWnd = CreateWindow("ClipClass",
34 "Line clipping test",
35 WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
36 0,
37 0,
38 CW_USEDEFAULT,
39 CW_USEDEFAULT,
40 NULL,
41 NULL,
42 hInstance,
43 NULL);
44 if (hWnd == NULL)
45 {
46 fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
47 GetLastError());
48 return(1);
49 }
50
51 ShowWindow(hWnd, nCmdShow);
52
53 while(GetMessage(&msg, NULL, 0, 0))
54 {
55 TranslateMessage(&msg);
56 DispatchMessage(&msg);
57 }
58
59 return msg.wParam;
60 }
61
62 static void
63 DrawLines(HDC hDC)
64 {
65 static struct
66 {
67 int fromx;
68 int fromy;
69 int tox;
70 int toy;
71 }
72 points[ ] =
73 {
74 { 50, 99, 125, 99 },
75 { 160, 99, 190, 99 },
76 { 300, 99, 225, 99 },
77 { 50, 100, 125, 100 },
78 { 160, 100, 190, 100 },
79 { 300, 100, 225, 100 },
80 { 50, 125, 300, 125 },
81 { 50, 149, 125, 149 },
82 { 160, 149, 190, 149 },
83 { 300, 149, 225, 149 },
84 { 50, 150, 125, 150 },
85 { 160, 150, 190, 150 },
86 { 300, 150, 225, 150 },
87 { 160, 249, 190, 249 },
88 { 160, 250, 190, 250 },
89 { 149, 50, 149, 125 },
90 { 149, 160, 149, 190 },
91 { 149, 300, 149, 225 },
92 { 150, 50, 150, 125 },
93 { 150, 160, 150, 190 },
94 { 150, 300, 150, 225 },
95 { 199, 50, 199, 125 },
96 { 199, 160, 199, 190 },
97 { 199, 300, 199, 225 },
98 { 200, 50, 200, 125 },
99 { 200, 160, 200, 190 },
100 { 200, 300, 200, 225 },
101 { 175, 50, 175, 300 },
102 { 50, 55, 300, 290 },
103 { 300, 295, 50, 60 },
104 { 50, 290, 300, 55 },
105 { 300, 60, 50, 295 },
106 { 55, 50, 290, 300 },
107 { 295, 300, 60, 50 },
108 { 55, 300, 290, 50 },
109 { 295, 50, 60, 300 }
110 };
111 int i;
112
113 for (i = 0; i < sizeof(points) / sizeof(points[0]); i++)
114 {
115 MoveToEx(hDC, points[i].fromx, points[i].fromy, NULL);
116 LineTo(hDC, points[i].tox, points[i].toy);
117 }
118 }
119
120 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
121 {
122 PAINTSTRUCT ps;
123 HDC hDC;
124 RECT clr;
125 HRGN ClipRgn, ExcludeRgn;
126 RECT Rect;
127
128 switch(msg)
129 {
130 case WM_PAINT:
131 GetClientRect(hWnd, &clr);
132 ClipRgn = CreateRectRgnIndirect(&clr);
133 hDC = BeginPaint(hWnd, &ps);
134 Rect.left = 100;
135 Rect.top = 100;
136 Rect.right = 250;
137 Rect.bottom = 150;
138 FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00)));
139 ExcludeRgn = CreateRectRgnIndirect(&Rect);
140 CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF);
141 DeleteObject(ExcludeRgn);
142 Rect.left = 150;
143 Rect.top = 150;
144 Rect.right = 200;
145 Rect.bottom = 250;
146 FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00)));
147 SelectObject(hDC, CreatePen(PS_SOLID, 0, RGB(0xFF, 0xFF, 0x00)));
148 DrawLines(hDC);
149 SelectObject(hDC, CreatePen(PS_SOLID, 0, RGB(0x00, 0x00, 0xFF)));
150 ExcludeRgn = CreateRectRgnIndirect(&Rect);
151 CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF);
152 DeleteObject(ExcludeRgn);
153 SelectClipRgn(hDC, ClipRgn);
154 DrawLines(hDC);
155 EndPaint(hWnd, &ps);
156 break;
157
158 case WM_DESTROY:
159 PostQuitMessage(0);
160 break;
161
162 default:
163 return DefWindowProc(hWnd, msg, wParam, lParam);
164 }
165 return 0;
166 }