ReactOS  0.4.15-dev-1197-g8081ba9
shaptest.c
Go to the documentation of this file.
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 #include <assert.h>
14 
15 #ifndef ASSERT
16 #define ASSERT assert
17 #endif
18 
19 #define nelem(x) (sizeof (x) / sizeof *(x))
20 
23 
25 {
26  HPEN Pen, OldPen;
27  HBRUSH RedBrush, OldBrush;
28  DWORD Mode;
29  POINT PointsAlternate[] =
30  {
31  { 20, 80 },
32  { 60, 20 },
33  { 90, 80 },
34  { 20, 40 },
35  { 100, 40 }
36  };
37  POINT PointsWinding[] =
38  {
39  { 130, 80 },
40  { 170, 20 },
41  { 200, 80 },
42  { 130, 40 },
43  { 210, 40 }
44  };
45  POINT Tri1[] =
46  {
47  { 3, 3 },
48  { 5, 3 },
49  { 3, 5 }
50  };
51  POINT Tri2[] =
52  {
53  { 7, 3 },
54  { 7, 7 },
55  { 3, 7 },
56  };
57  POINT Square1[] =
58  {
59  { 1, 15 },
60  { 3, 15 },
61  { 3, 17 },
62  { 1, 17 }
63  };
64  POINT Square2[] =
65  {
66  { 5, 15 },
67  { 7, 15 },
68  { 7, 17 },
69  { 5, 17 }
70  };
71  POINT Square3[] =
72  {
73  { 1, 23 },
74  { 3, 23 },
75  { 3, 25 },
76  { 1, 25 }
77  };
78  POINT Square4[] =
79  {
80  { 5, 23 },
81  { 7, 23 },
82  { 7, 25 },
83  { 5, 25 }
84  };
85  POINT Square5[] =
86  {
87  { 1, 31 },
88  { 3, 31 },
89  { 3, 33 },
90  { 1, 33 }
91  };
92  POINT Square6[] =
93  {
94  { 5, 31 },
95  { 7, 31 },
96  { 7, 33 },
97  { 5, 33 }
98  };
99 
100  //create a pen to draw the shape
101  Pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0xff));
102  ASSERT(Pen);
103  RedBrush = CreateSolidBrush(RGB(0xff, 0, 0));
104  ASSERT(RedBrush);
105 
106  OldPen = (HPEN)SelectObject(hdc, Pen);
107  OldBrush = (HBRUSH)SelectObject(hdc, RedBrush);
108 
110 
111  RoundRect ( hdc, 32, 8, 48, 24, 8, 8 );
112 
114  Polygon(hdc,PointsAlternate,nelem(PointsAlternate));
115 
117  Polygon(hdc,PointsWinding,nelem(PointsWinding));
118 
119  Rectangle ( hdc, 1, 1, 10, 10 );
120  Polygon(hdc,Tri1,nelem(Tri1));
121  Polygon(hdc,Tri2,nelem(Tri2));
122 
123  Rectangle ( hdc, 1, 11, 4, 14 );
124  Rectangle ( hdc, 5, 11, 8, 14 );
125  Rectangle ( hdc, 9, 11, 12, 14 );
126  Rectangle ( hdc, 13, 11, 16, 14 );
127  Polygon(hdc,Square1,nelem(Square1));
128  Polygon(hdc,Square2,nelem(Square2));
129  Rectangle ( hdc, 1, 19, 4, 22 );
130  Rectangle ( hdc, 5, 19, 8, 22 );
131  Rectangle ( hdc, 9, 19, 12, 22 );
132  Rectangle ( hdc, 13, 19, 16, 22 );
133  Polygon(hdc,Square3,nelem(Square3));
134  Polygon(hdc,Square4,nelem(Square4));
135  Rectangle ( hdc, 1, 27, 4, 30 );
136  Rectangle ( hdc, 5, 27, 8, 30 );
137  Rectangle ( hdc, 9, 27, 12, 30 );
138  Rectangle ( hdc, 13, 27, 16, 30 );
139 
140  // switch to null pen to make surey they display correctly
141  DeleteObject ( SelectObject(hdc, OldPen) );
142  Pen = CreatePen ( PS_NULL, 0, 0 );
143  ASSERT(Pen);
144  OldPen = (HPEN)SelectObject(hdc, Pen);
145 
146  Polygon(hdc,Square5,nelem(Square5));
147  Polygon(hdc,Square6,nelem(Square6));
148  Rectangle ( hdc, 1, 35, 4, 38 );
149  Rectangle ( hdc, 5, 35, 8, 38 );
150  Rectangle ( hdc, 9, 35, 12, 38 );
151  Rectangle ( hdc, 13, 35, 16, 38 );
152 
153  //cleanup
155  DeleteObject ( SelectObject(hdc, OldPen) );
156  DeleteObject ( SelectObject(hdc, OldBrush) );
157 }
158 
159 
160 void shaptest( HDC hdc )
161 {
162  //Test the Polygon routine.
163  PolygonTest(hdc);
164 }
165 
166 
167 int WINAPI
169  HINSTANCE hPrevInstance,
170  LPSTR lpszCmdLine,
171  int nCmdShow)
172 {
173  WNDCLASS wc;
174  MSG msg;
175  HWND hWnd;
176 
177  wc.lpszClassName = "ShapTestClass";
179  wc.style = CS_VREDRAW | CS_HREDRAW;
180  wc.hInstance = hInstance;
184  wc.lpszMenuName = NULL;
185  wc.cbClsExtra = 0;
186  wc.cbWndExtra = 0;
187  if (RegisterClass(&wc) == 0)
188  {
189  fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
190  (unsigned int)GetLastError());
191  return(1);
192  }
193 
194  hWnd = CreateWindow("ShapTestClass",
195  "Shaptest",
197  0,
198  0,
201  NULL,
202  NULL,
203  hInstance,
204  NULL);
205  if (hWnd == NULL)
206  {
207  fprintf(stderr, "CreateWindow failed (last error 0x%X)\n",
208  (unsigned int)GetLastError());
209  return(1);
210  }
211 
215 
216  ShowWindow(hWnd, nCmdShow);
217 
218  while(GetMessage(&msg, NULL, 0, 0))
219  {
222  }
223 
224  DeleteObject(tf);
225 
226  return msg.wParam;
227 }
228 
230 {
231  PAINTSTRUCT ps;
232  HDC hDC;
233 
234  switch(msg)
235  {
236 
237  case WM_PAINT:
238  hDC = BeginPaint(hWnd, &ps);
239  shaptest( hDC );
240  EndPaint(hWnd, &ps);
241  break;
242 
243  case WM_DESTROY:
244  PostQuitMessage(0);
245  break;
246 
247  default:
248  return DefWindowProc(hWnd, msg, wParam, lParam);
249  }
250  return 0;
251 }
252 
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: shaptest.c:168
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define WINDING
Definition: constants.h:279
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define DEFAULT_QUALITY
Definition: wingdi.h:435
#define CreateWindow
Definition: winuser.h:5729
#define FF_DONTCARE
Definition: wingdi.h:447
_In_ ULONG Mode
Definition: hubbusif.h:303
BOOL Polygon(CONST PPOINT UnsafePoints, int Count, int polyFillMode)
Definition: polytest.cpp:730
#define RGB(r, g, b)
Definition: precomp.h:62
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:35
HWND hWnd
Definition: settings.c:17
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
int cbClsExtra
Definition: winuser.h:3140
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define CS_HREDRAW
Definition: winuser.h:648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
LPCSTR lpszMenuName
Definition: winuser.h:3146
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3145
HICON HCURSOR
Definition: windef.h:299
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
char * LPSTR
Definition: xmlstorage.h:182
WPARAM wParam
Definition: combotst.c:138
#define PS_SOLID
Definition: wingdi.h:585
int cbWndExtra
Definition: winuser.h:3141
#define nelem(x)
Definition: shaptest.c:19
HINSTANCE hInstance
Definition: charmap.c:20
#define ALTERNATE
Definition: constants.h:278
#define FALSE
Definition: types.h:117
BOOL WINAPI RoundRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define FIXED_PITCH
Definition: wingdi.h:443
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define TA_BASELINE
Definition: wingdi.h:927
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
HCURSOR hCursor
Definition: winuser.h:3144
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define GRAY_BRUSH
Definition: wingdi.h:897
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define CS_VREDRAW
Definition: winuser.h:653
int WINAPI SetPolyFillMode(_In_ HDC, _In_ int)
Definition: dc.c:1145
#define WINAPI
Definition: msvc.h:6
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WS_HSCROLL
Definition: pedump.c:628
#define WM_PAINT
Definition: winuser.h:1602
int WINAPI GetPolyFillMode(_In_ HDC)
#define ASSERT
Definition: shaptest.c:16
HDC hdc
Definition: main.c:9
LPCSTR lpszClassName
Definition: winuser.h:3147
#define LoadCursor
Definition: winuser.h:5787
HFONT WINAPI CreateFontA(_In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCSTR)
UINT style
Definition: winuser.h:3138
static HDC hDC
Definition: 3dtext.c:33
void PolygonTest(HDC hdc)
Definition: shaptest.c:24
HINSTANCE hInstance
Definition: winuser.h:3142
void shaptest(HDC hdc)
Definition: shaptest.c:160
unsigned int UINT
Definition: ndis.h:50
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define WS_VSCROLL
Definition: pedump.c:627
#define PS_NULL
Definition: wingdi.h:590
#define GetMessage
Definition: winuser.h:5765
#define FW_NORMAL
Definition: wingdi.h:372
WNDPROC lpfnWndProc
Definition: winuser.h:3139
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
FILE * stderr
#define RegisterClass
Definition: winuser.h:5811
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: shaptest.c:229
#define LoadIcon
Definition: winuser.h:5788
#define ANSI_CHARSET
Definition: wingdi.h:382
LONG_PTR LRESULT
Definition: windef.h:209
Definition: gdipluspen.h:22
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
HFONT tf
Definition: shaptest.c:21
HICON hIcon
Definition: winuser.h:3143