This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / apps / tests / shaptest / shaptest.c
1 /*
2  * COPYRIGHT:         See COPYING in the top level directory
3  * AUTHOR:            See gditest-- (initial changes by Mark Tempel)
4  * shaptest
5  *
6  * This is a windowed application that should draw two polygons. One
7  * is drawn with ALTERNATE fill, the other is drawn with WINDING fill.
8  * This is used to test out the Polygon() implementation.
9  */
10
11 #include <windows.h>
12 #include <stdio.h>
13
14
15 HFONT tf;
16 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
17
18 void __stdcall PolygonTest(HDC Desktop)
19 {
20         HPEN BluePen;  
21         HPEN OldPen;
22         HBRUSH RedBrush;
23         HBRUSH OldBrush;
24         POINT lpPointsAlternate[5];
25         POINT lpPointsWinding[5];
26         DWORD Mode;
27
28         //create a pen to draw the shape
29         BluePen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0xff));
30         RedBrush = CreateSolidBrush(RGB(0xff, 0, 0));
31
32         //initialize a set of points for alternate.
33         lpPointsAlternate[0].x = 20;
34         lpPointsAlternate[0].y = 80; //{20,80};
35         lpPointsAlternate[1].x = 60;
36         lpPointsAlternate[1].y = 20; //{60,20};
37         lpPointsAlternate[2].x = 90;
38         lpPointsAlternate[2].y = 80; //{90,80};
39         lpPointsAlternate[3].x = 20;
40         lpPointsAlternate[3].y = 40; //{20,40};
41         lpPointsAlternate[4].x = 100;
42         lpPointsAlternate[4].y = 40; //{100,40};
43
44         //initialize a set of points for winding.
45         lpPointsWinding[0].x = 130;
46         lpPointsWinding[0].y = 80; //{130,80};
47         lpPointsWinding[1].x = 170;
48         lpPointsWinding[1].y = 20; //{170,20};
49         lpPointsWinding[2].x = 200;
50         lpPointsWinding[2].y = 80; //{200,80};
51         lpPointsWinding[3].x = 130;
52         lpPointsWinding[3].y = 40; //{130,40};
53         lpPointsWinding[4].x = 210;
54         lpPointsWinding[4].y = 40; //{210,40};
55
56         OldPen = (HPEN)SelectObject(Desktop, BluePen);
57         OldBrush = (HBRUSH)SelectObject(Desktop, RedBrush);
58
59         Mode = GetPolyFillMode(Desktop);
60
61         SetPolyFillMode(Desktop, ALTERNATE);
62         Polygon(Desktop,lpPointsAlternate,5);
63
64         SetPolyFillMode(Desktop, WINDING);
65         Polygon(Desktop,lpPointsWinding,5);
66         
67         //cleanup
68         SetPolyFillMode(Desktop, Mode);
69         SelectObject(Desktop, OldPen);
70         SelectObject(Desktop, OldBrush);
71         DeleteObject(BluePen);
72         DeleteObject(RedBrush);
73
74 }
75
76
77 void shaptest( HDC DevCtx ){
78   HDC  Desktop, MyDC, DC24;
79   HPEN  RedPen, GreenPen, BluePen, WhitePen;
80   HBITMAP  MyBitmap, DIB24;
81   HFONT  hf, tf;
82   BITMAPINFOHEADER BitInf;
83   BITMAPINFO BitPalInf;
84   HRGN hRgn1, hRgn2, hRgn3;
85   HBRUSH BlueBrush, DefBrush;
86   int sec,Xmod,Ymod;
87   char tbuf[5];
88
89
90   BlueBrush = CreateSolidBrush( RGB(0, 0, 0xff) );
91   DefBrush = SelectObject( DevCtx, BlueBrush );
92
93   SelectObject( DevCtx, DefBrush );
94   DeleteObject( BlueBrush );
95
96   // Create a blue pen and select it into the DC
97   BluePen = CreatePen(PS_SOLID, 8, RGB(0, 0, 0xff));
98   SelectObject(DevCtx, BluePen);
99
100   //Test the Polygon routine.
101   PolygonTest(DevCtx);
102 }
103
104
105 int WINAPI 
106 WinMain(HINSTANCE hInstance,
107         HINSTANCE hPrevInstance,
108         LPSTR lpszCmdLine,
109         int nCmdShow)
110 {
111   WNDCLASS wc;
112   MSG msg;
113   HWND hWnd;
114
115   wc.lpszClassName = "ShapTestClass";
116   wc.lpfnWndProc = MainWndProc;
117   wc.style = CS_VREDRAW | CS_HREDRAW;
118   wc.hInstance = hInstance;
119   wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
120   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
121   wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
122   wc.lpszMenuName = NULL;
123   wc.cbClsExtra = 0;
124   wc.cbWndExtra = 0;
125   if (RegisterClass(&wc) == 0)
126     {
127       fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
128               GetLastError());
129       return(1);
130     }
131
132   hWnd = CreateWindow("ShapTestClass",
133                       "Shaptest",
134                       WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
135                       0,
136                       0,
137                       CW_USEDEFAULT,
138                       CW_USEDEFAULT,
139                       NULL,
140                       NULL,
141                       hInstance,
142                       NULL);
143   if (hWnd == NULL)
144     {
145       fprintf(stderr, "CreateWindow failed (last error 0x%X)\n",
146               GetLastError());
147       return(1);
148     }
149
150         tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
151                 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
152                 DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
153
154   ShowWindow(hWnd, nCmdShow);
155
156   while(GetMessage(&msg, NULL, 0, 0))
157   {
158     TranslateMessage(&msg);
159     DispatchMessage(&msg);
160   }
161
162   DeleteObject(tf);
163
164   return msg.wParam;
165 }
166
167 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
168 {
169         PAINTSTRUCT ps;
170         HDC hDC;
171         RECT clr, wir;
172         char spr[100], sir[100];
173
174         switch(msg)
175         {
176         
177         case WM_PAINT:
178           hDC = BeginPaint(hWnd, &ps);
179           shaptest( hDC );
180           EndPaint(hWnd, &ps);
181           break;
182
183         case WM_DESTROY:
184           PostQuitMessage(0);
185           break;
186
187         default:
188           return DefWindowProc(hWnd, msg, wParam, lParam);
189         }
190         return 0;
191 }
192