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