3 dec 26, 2001 -- gditest bug fix by Richard Campbell
8 extern BOOL STDCALL GdiDllInitialize(HANDLE hInstance, DWORD Event, LPVOID Reserved);
10 void __stdcall Background (HDC Desktop)
15 Pen = CreatePen(PS_SOLID, 1, RGB(64, 64, 128));
17 SelectObject (Desktop, Pen);
19 MoveToEx (Desktop, 0, 0, NULL);
20 LineTo (Desktop, 640, 480);
21 for (y = 479, x = 0; x < 640; x+=42)
23 MoveToEx (Desktop, 0, 0, NULL);
24 LineTo (Desktop, x, y);
26 for (y = 0, x = 639; y < 480; y+=42)
28 MoveToEx (Desktop, 0, 0, NULL);
29 LineTo (Desktop, x, y);
34 HDC Desktop, MyDC, DC24;
35 HPEN RedPen, GreenPen, BluePen, WhitePen;
36 HBITMAP MyBitmap, DIB24;
38 BITMAPINFOHEADER BitInf;
40 HRGN hRgn1, hRgn2, hRgn3;
41 HBRUSH BlueBrush, DefBrush;
43 // Set up a DC called Desktop that accesses DISPLAY
44 Desktop = CreateDCA("DISPLAY", NULL, NULL, NULL);
46 printf("Can't create desktop\n");
55 BlueBrush = CreateSolidBrush( RGB(0, 0, 0xff) );
56 DefBrush = SelectObject( Desktop, BlueBrush );
58 hRgn1 = CreateRectRgn( 1, 2, 100, 101 );
59 hRgn2 = CreateRectRgn( 10, 20, 150, 151 );
60 hRgn3 = CreateRectRgn( 1, 1, 1, 1);
61 CombineRgn( hRgn3, hRgn1, hRgn2, RGN_XOR );
63 PaintRgn( Desktop, hRgn3 );
64 SelectObject( Desktop, DefBrush );
65 DeleteObject( BlueBrush );
67 // Create a blue pen and select it into the DC
68 BluePen = CreatePen(PS_SOLID, 8, RGB(0, 0, 0xff));
69 SelectObject(Desktop, BluePen);
71 // Draw a shape on the DC
72 MoveToEx(Desktop, 50, 50, NULL);
73 LineTo(Desktop, 200, 60);
74 LineTo(Desktop, 200, 300);
75 LineTo(Desktop, 50, 50);
76 MoveToEx(Desktop, 50, 50, NULL);
77 LineTo(Desktop, 200, 50);
79 WhitePen = CreatePen(PS_SOLID, 3, RGB(0xff, 0xff, 0xff));
80 SelectObject(Desktop, WhitePen);
82 MoveToEx(Desktop, 20, 70, NULL);
83 LineTo(Desktop, 500, 70);
84 MoveToEx(Desktop, 70, 20, NULL);
85 LineTo(Desktop, 70, 150);
88 GreenPen = CreatePen(PS_SOLID, 3, RGB(0, 0xff, 0));
89 RedPen = CreatePen(PS_SOLID, 3, RGB(0xff, 0, 0));
91 hf = CreateFontA(24, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
92 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
93 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Helmet");
94 SelectObject(Desktop, hf);
95 SetTextColor(Desktop, RGB(0xff, 0, 0));
96 TextOutA(Desktop, 70, 70, "React", 5);
97 SetTextColor(Desktop, RGB(0, 0xff, 0));
98 TextOutA(Desktop, 140, 70, "OS", 2);
100 tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
101 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
102 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
103 SelectObject(Desktop, tf);
104 SetTextColor(Desktop, RGB(0xff, 0xff, 0xff));
105 TextOutA(Desktop, 70, 90, "This is a test of ReactOS text, using the FreeType 2 library!", 61);
107 // TEST 1: Copy from the VGA into a device compatible DC, draw on it, then blt it to the VGA again
108 MyDC = CreateCompatibleDC(Desktop);
109 MyBitmap = CreateCompatibleBitmap(Desktop, 151, 251);
110 SelectObject(MyDC, MyBitmap);
111 BitBlt(MyDC, 0, 0, 151, 251, Desktop, 50, 50, SRCCOPY); // can we say 151, 251 since bottom corner is not inclusive?
113 SelectObject(MyDC, GreenPen);
114 Rectangle(MyDC, 10, 10, 50, 50);
116 // TEST 2: Copy from the device compatible DC into a 24BPP bitmap, draw on it, then blt to the VGA again
117 BitInf.biSize = sizeof(BITMAPINFOHEADER);
118 BitInf.biWidth = 152;
119 BitInf.biHeight = -252; // it's top down (since BI_RGB is used, the sign is operative of direction)
121 BitInf.biBitCount = 24;
122 BitInf.biCompression = BI_RGB;
123 BitInf.biSizeImage = 0;
124 BitInf.biXPelsPerMeter = 0;
125 BitInf.biYPelsPerMeter = 0;
126 BitInf.biClrUsed = 0;
127 BitInf.biClrImportant = 0;
128 BitPalInf.bmiHeader = BitInf;
129 DIB24 = (HBITMAP) CreateDIBSection(NULL, &BitPalInf, DIB_RGB_COLORS, NULL, NULL, 0);
130 DC24 = CreateCompatibleDC(NULL);
131 SelectObject(DC24, DIB24);
133 BitBlt(DC24, 0, 0, 101, 201, MyDC, 0, 0, SRCCOPY);
134 SelectObject(DC24, RedPen);
135 Rectangle(DC24, 80, 90, 100, 110);
136 MoveToEx(DC24, 80, 90, NULL);
137 LineTo(DC24, 100, 110);
138 BitBlt(Desktop, 200, 200, 110, 120, DC24, 0, 0, SRCCOPY);
140 Sleep( 10000 ); // fixme delay only 10000 (for 10 seconds)
141 // Free up everything
146 void DumpRgnData( HRGN hRgn )
151 size = GetRegionData( hRgn, 0, NULL );
153 printf("GetRegionData returned 0\n");
156 rgnData = (LPRGNDATA) malloc( size );
157 ret = GetRegionData( hRgn, size, rgnData );
159 printf("GetRegionData( hRgn, size, rgnData ) returned 0\n");
162 printf("Bounds: left=%d top=%d right=%d bottom=%d, count: %d, type: %i\n\n",
163 rgnData->rdh.rcBound.left, rgnData->rdh.rcBound.top, rgnData->rdh.rcBound.right, rgnData->rdh.rcBound.bottom,
164 rgnData->rdh.nCount, rgnData->rdh.iType);
165 printf("Rects:\t i \t left \t top \t right \t bottom\n");
166 for ( i = 0; i < rgnData->rdh.nCount; i++ ) {
167 PRECT pr = (PRECT) rgnData->Buffer + i;
168 printf("\t %d \t %d \t %d \t %d \t %d\n", i, pr->left, pr->top, pr->right, pr->bottom );
175 HRGN hRgn1, hRgn2, hRgn3;
179 hRgn1 = CreateRectRgn( 1, 2, 100, 101 );
180 if( hRgn1 == NULL ) {
181 printf("Failed at hRgn1 = CreateRectRgn( 1, 2, 100, 101 )\n");
184 i = GetRgnBox( hRgn1, &Rect );
186 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
189 printf("GetRgnBox( hRgn1, &Rect ): i=%d, left=%d top=%d right=%d bottom=%d\n\n",
190 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
192 DumpRgnData( hRgn1 );
194 hRgn2 = CreateRectRgn( 51, 53, 150, 152 );
195 if( hRgn2 == NULL ) {
196 printf("Failed at hRgn2 = CreateRectRgn( 51, 53, 150, 152 )\n");
199 i = GetRgnBox( hRgn2, &Rect );
201 printf("Failed GetRgnBox( hRgn2, &Rect )\n");
204 printf("GetRgnBox( hRgn2, &Rect ): i=%d, left=%d top=%d right=%d bottom=%d\n\n",
205 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
207 DumpRgnData( hRgn2 );
209 if( EqualRgn( hRgn1, hRgn2 ) == TRUE ){
210 printf("\t hRgn1, hRgn2 are equal\n");
213 printf("\t hRgn1, hRgn2 are NOT equal\n\n");
216 i = OffsetRgn(hRgn1,50,51);
218 printf("Failed OffsetRgn(hRgn1,50,51)\n");
222 i = GetRgnBox( hRgn1, &Rect );
224 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
227 printf("After offset\nGetRgnBox( hRgn1, &Rect ): i=%d, left=%d top=%d right=%d bottom=%d\n\n",
228 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
230 if( EqualRgn( hRgn1, hRgn2 ) == TRUE ){
231 printf("\t hRgn1, hRgn2 are equal after offset\n");
234 printf("\t hRgn1, hRgn2 are NOT equal after offset!\n\n");
237 i = SetRectRgn(hRgn1, 10, 11, 110, 111 );
239 printf("Failed SetRectRgn(hRgn1... )\n");
242 i = GetRgnBox( hRgn1, &Rect );
244 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
247 printf("after SetRectRgn(hRgn1, 10, 11, 110, 111 ):\n i=%d, left=%d top=%d right=%d bottom=%d\n\n",
248 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
250 hRgn3 = CreateRectRgn( 1, 1, 1, 1);
251 i = CombineRgn( hRgn3, hRgn1, hRgn2, RGN_AND );
253 printf("Fail: CombineRgn( hRgn3, hRgn1, hRgn2, RGN_AND ). LastError: %d\n", GetLastError);
257 if( GetRgnBox( hRgn3, &Rect )==0 ){
258 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
261 printf("After CombineRgn( hRgn3, hRgn1, hRgn2, RGN_AND ): \nGetRgnBox( hRgn3, &Rect ): CR_i=%d, left=%d top=%d right=%d bottom=%d\n\n",
262 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
263 DumpRgnData( hRgn3 );
265 i = CombineRgn( hRgn3, hRgn1, hRgn2, RGN_OR );
267 printf("Fail: CombineRgn( hRgn3, hRgn1, hRgn2, RGN_OR ). LastError: %d\n", GetLastError);
271 if( GetRgnBox( hRgn3, &Rect )==0 ){
272 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
275 printf("After CombineRgn( hRgn3, hRgn1, hRgn2, RGN_OR ): \nGetRgnBox( hRgn3, &Rect ): CR_i=%d, left=%d top=%d right=%d bottom=%d\n\n",
276 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
277 DumpRgnData( hRgn3 );
279 i = CombineRgn( hRgn3, hRgn1, hRgn2, RGN_DIFF );
281 printf("Fail: CombineRgn( hRgn3, hRgn1, hRgn2, RGN_DIFF ). LastError: %d\n", GetLastError);
285 if( GetRgnBox( hRgn3, &Rect )==0 ){
286 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
289 printf("After CombineRgn( hRgn3, hRgn1, hRgn2, RGN_DIFF ): \nGetRgnBox( hRgn3, &Rect ): CR_i=%d, left=%d top=%d right=%d bottom=%d\n\n",
290 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
291 DumpRgnData( hRgn3 );
293 i = CombineRgn( hRgn3, hRgn1, hRgn2, RGN_XOR );
295 printf("Fail: CombineRgn( hRgn3, hRgn1, hRgn2, RGN_XOR ). LastError: %d\n", GetLastError);
299 if( GetRgnBox( hRgn3, &Rect )==0 ){
300 printf("Failed GetRgnBox( hRgn3, &Rect )\n");
303 printf("After CombineRgn( hRgn3, hRgn1, hRgn2, RGN_XOR ): \nGetRgnBox( hRgn3, &Rect ): CR_i=%d, left=%d top=%d right=%d bottom=%d\n\n",
304 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
305 DumpRgnData( hRgn3 );
307 i = CombineRgn( hRgn1, hRgn3, hRgn2, RGN_COPY );
309 printf("Fail: CombineRgn( hRgn1, hRgn3, hRgn2, RGN_COPY ). LastError: %d\n", GetLastError);
313 if( GetRgnBox( hRgn1, &Rect )==0 ){
314 printf("Failed GetRgnBox( hRgn1, &Rect )\n");
317 printf("After CombineRgn( hRgn1, hRgn3, hRgn2, RGN_COPY ): \nGetRgnBox( hRgn1, &Rect ): CR_i=%d, left=%d top=%d right=%d bottom=%d\n\n",
318 i, Rect.left, Rect.top, Rect.right, Rect.bottom );
319 DumpRgnData( hRgn1 );
322 DeleteObject( hRgn1 );
323 DeleteObject( hRgn2 );
324 DeleteObject( hRgn3 );
325 printf("region test finished\n");
328 int main (int argc, char* argv[])
330 printf("Entering GDITest..\n");
331 printf("use gditest for older tests\n");
332 printf("use gditest 1 for region test\n");
334 GdiDllInitialize (NULL, DLL_PROCESS_ATTACH, NULL);
338 if( !strncmp( argv[1], "1", 1 ) ) {