ReactOS 0.4.15-dev-5664-g3bf4ef6
primitives.cpp File Reference
#include <windows.h>
#include <cassert>
#include "mk_font.h"
Include dependency graph for primitives.cpp:

Go to the source code of this file.

Enumerations

enum  OutPrimitive {
  opLine , opBezier , opRectangle , opRoundRect ,
  opEllipse , opArc , opPie , opChord ,
  opCustom
}
 

Functions

LRESULT CALLBACK MainWndProc (HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
 
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow)
 
void DrawPrimitive (IN HDC hDC, IN const RECT &RPrimitive, IN OutPrimitive PrimitiveID)
 

Variables

HINSTANCE hInst
 
const charWndClassName = "GMainWnd"
 
HWND hListBox = NULL
 
HBRUSH hListBrush = NULL
 
HPEN hListPen = NULL
 
HFONT hListFont = NULL
 

Enumeration Type Documentation

◆ OutPrimitive

Enumerator
opLine 
opBezier 
opRectangle 
opRoundRect 
opEllipse 
opArc 
opPie 
opChord 
opCustom 

Definition at line 75 of file primitives.cpp.

75 {
78 };
@ opArc
Definition: primitives.cpp:77
@ opEllipse
Definition: primitives.cpp:77
@ opBezier
Definition: primitives.cpp:76
@ opChord
Definition: primitives.cpp:77
@ opLine
Definition: primitives.cpp:76
@ opRoundRect
Definition: primitives.cpp:76
@ opPie
Definition: primitives.cpp:77
@ opCustom
Definition: primitives.cpp:77
@ opRectangle
Definition: primitives.cpp:76

Function Documentation

◆ DrawPrimitive()

void DrawPrimitive ( IN HDC  hDC,
IN const RECT RPrimitive,
IN OutPrimitive  PrimitiveID 
)

Definition at line 80 of file primitives.cpp.

82{
83 RECT R = RPrimitive;
84 InflateRect(&R, -10, -10);
85
86 switch (PrimitiveID)
87 {
88 case opLine:
89 {
90 const POINT PLine[] = {{R.left, R.top}, {R.right, R.bottom}};
91 Polyline(hDC, PLine, 2);
92 break;
93 }
94 case opBezier:
95 {
96 const POINT PControlPoints[] = {
97 {R.left, R.top},
98 {(R.right - R.left) / 2, R.top},
99 {(R.right - R.left) / 2, R.bottom},
100 {R.right, R.bottom}
101 };
102 PolyBezier(hDC, PControlPoints, 4);
103 break;
104 }
105 case opRectangle:
106 {
107 Rectangle(hDC, R.left, R.top, R.right, R.bottom);
108 break;
109 }
110 case opRoundRect:
111 {
112 RoundRect(hDC, R.left, R.top, R.right, R.bottom, 20, 20);
113 break;
114 }
115 case opEllipse:
116 {
117 Ellipse(hDC, R.left, R.top, R.right, R.bottom);
118 break;
119 }
120 case opArc:
121 {
122 const POINT PRads[] = {
123 {(R.right - R.left) / 3 + R.left, R.top},
124 {(R.right - R.left) / 3 + R.left, R.bottom}
125 };
126 Arc(hDC, R.left, R.top, R.right, R.bottom,
127 PRads[0].x, PRads[0].y, PRads[1].x, PRads[1].y);
128 break;
129 }
130 case opPie:
131 {
132 const POINT PRads[] = {
133 {(R.right - R.left) / 3 + R.left, R.top},
134 {(R.right - R.left) / 3 + R.left, R.bottom}
135 };
136 Pie(hDC, R.left, R.top, R.right, R.bottom,
137 PRads[0].x, PRads[0].y, PRads[1].x, PRads[1].y);
138 break;
139 }
140 case opChord:
141 {
142 const POINT PRads[] = {
143 {(R.right - R.left) / 3 + R.left, R.top},
144 {(R.right - R.left) / 3 + R.left, R.bottom}
145 };
146 Chord(hDC, R.left, R.top, R.right, R.bottom,
147 PRads[0].x, PRads[0].y, PRads[1].x, PRads[1].y);
148 break;
149 }
150 case opCustom:
151 {
152 const POINT PVertices[] = {
153 {R.left, (R.bottom - R.top) / 2 + R.top},
154 {(R.right - R.left) / 2 + R.left, R.top},
155 {R.right, (R.bottom - R.top) / 2 + R.top},
156 {(R.right - R.left) / 2 + R.left, R.bottom}
157 };
158 Polygon(hDC, PVertices, 4);
159 break;
160 }
161 }
162}
static HDC hDC
Definition: 3dtext.c:33
Definition: arc.h:55
BOOL Polygon(CONST PPOINT UnsafePoints, int Count, int polyFillMode)
Definition: polytest.cpp:730
#define R(b, x)
Definition: sha2.c:134
BOOL WINAPI Chord(_In_ HDC hdc, _In_ INT xLeft, _In_ INT yTop, _In_ INT xRight, _In_ INT yBottom, _In_ INT xRadial1, _In_ INT yRadial1, _In_ INT xRadial2, _In_ INT yRadial2)
Definition: arc.c:119
BOOL WINAPI PolyBezier(_In_ HDC hdc, _In_reads_(cpt) const POINT *apt, _In_ DWORD cpt)
Definition: painting.c:263
BOOL WINAPI Polyline(_In_ HDC hdc, _In_reads_(cpt) const POINT *apt, _In_ int cpt)
BOOL WINAPI Ellipse(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI RoundRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI Pie(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ int)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)

Referenced by DECLARE_INTERFACE_(), and MainWndProc().

◆ MainWndProc()

LRESULT CALLBACK MainWndProc ( HWND  HWnd,
UINT  Msg,
WPARAM  WParam,
LPARAM  LParam 
)

Definition at line 171 of file primitives.cpp.

173{
174 switch (msg)
175 {
176 case WM_CREATE:
177 {
178 hListBox =
180 WS_EX_CLIENTEDGE, TEXT("LISTBOX"), TEXT(""),
184 0, 0, 640, 480,
186 );
187 assert(hListBox != NULL);
188
190 hListBox, GWL_ID, reinterpret_cast<LONG_PTR>(hListBox)
191 );
192
194 reinterpret_cast<LPARAM>(TEXT("Line")));
196 reinterpret_cast<LPARAM>(TEXT("Bezier Curve")));
198 reinterpret_cast<LPARAM>(TEXT("Rectangle")));
200 reinterpret_cast<LPARAM>(TEXT("Rounded Rectangle")));
202 reinterpret_cast<LPARAM>(TEXT("Ellipse")));
204 reinterpret_cast<LPARAM>(TEXT("Arc")));
206 reinterpret_cast<LPARAM>(TEXT("Pie Slice")));
208 reinterpret_cast<LPARAM>(TEXT("Chord")));
210 reinterpret_cast<LPARAM>(TEXT("Custom")));
211
212 hListBrush = CreateSolidBrush(PALETTERGB(64, 192, 64));
213 hListPen = CreatePen(PS_SOLID, 3, PALETTERGB(0, 0, 0));
214 HDC hScreenDC = GetDC(NULL);
215#if 0
216 try
217#endif
218 {
219 // MakeFont() from Chapter 4
221 hScreenDC, "Impact", 20, ANSI_CHARSET,
223 );
224 }
225#if 0
226 catch (...)
227#endif
228 {
229 ReleaseDC(NULL, hScreenDC);
230 }
231 ReleaseDC(NULL, hScreenDC);
232
233 break;
234 }
235 case WM_MEASUREITEM:
236 {
237 LPMEASUREITEMSTRUCT lpmis =
238 reinterpret_cast<LPMEASUREITEMSTRUCT>(lParam);
239 assert(lpmis != NULL);
240
241 if (lpmis->CtlID == reinterpret_cast<UINT_PTR>(hListBox))
242 {
243 lpmis->itemHeight = 150;
244 return TRUE;
245 }
246 break;
247 }
248 case WM_DRAWITEM:
249 {
250 LPDRAWITEMSTRUCT lpdis =
251 reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
252 assert(lpdis != NULL);
253
254 if (lpdis->CtlID == reinterpret_cast<UINT_PTR>(hListBox))
255 {
256 SaveDC(lpdis->hDC);
257#if 0
258 try
259#endif
260 {
261 SelectObject(lpdis->hDC, hListBrush);
262 SelectObject(lpdis->hDC, hListPen);
263 SelectObject(lpdis->hDC, hListFont);
264
265 bool selected = (lpdis->itemState & ODS_SELECTED);
266 COLORREF clrText = GetSysColor(
268 );
271 );
272
273 // fill the background
274 FillRect(lpdis->hDC, &lpdis->rcItem, hListBrush);
275
276 // render the output primitive
277 RECT RPrimitive = lpdis->rcItem;
278 InflateRect(&RPrimitive, -5, -5);
279 RPrimitive.right = static_cast<int>(
280 0.6 * lpdis->rcItem.right + 0.5
281 );
282 FillRect(
283 lpdis->hDC, &RPrimitive,
284 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1)
285 );
287 lpdis->hDC, RPrimitive,
288 static_cast<OutPrimitive>(lpdis->itemID)
289 );
290 if (selected) InvertRect(lpdis->hDC, &RPrimitive);
291 DrawEdge(lpdis->hDC, &RPrimitive, EDGE_SUNKEN, BF_RECT);
292
293 // render the text
294 TCHAR text[13];
295 if (SNDMSG(hListBox, LB_GETTEXT, lpdis->itemID,
296 reinterpret_cast<LPARAM>(&text)) != LB_ERR)
297 {
298 RECT RText = RPrimitive;
299 RText.left = RPrimitive.right;
300 RText.right = lpdis->rcItem.right;
301
302 SelectObject(lpdis->hDC, hListFont);
303 SetBkMode(lpdis->hDC, TRANSPARENT);
304 SetTextColor(lpdis->hDC, clrText);
305
306 DrawText(lpdis->hDC, text, -1, &RText,
308 }
309
310 // indicate keyboard focus
311 if (lpdis->itemState & ODS_FOCUS)
312 {
313 RECT RFocus = lpdis->rcItem;
314 InflateRect(&RFocus, -1, -1);
315 DrawFocusRect(lpdis->hDC, &RFocus);
316 }
317 }
318#if 0
319 catch (...)
320#endif
321 {
322 RestoreDC(lpdis->hDC, -1);
323 }
324 RestoreDC(lpdis->hDC, -1);
325 return TRUE;
326 }
327 break;
328 }
329 case WM_SIZE:
330 {
333 );
334 return 0;
335 }
336 case WM_DESTROY:
337 {
341
343 return 0;
344 }
345 }
347}
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static char selected[MAX_PATH+1]
Definition: dirdlg.c:7
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
const WCHAR * text
Definition: package.c:1799
#define assert(x)
Definition: debug.h:53
pKey DeleteObject()
#define TEXT(s)
Definition: k32.h:26
static HDC
Definition: imagelist.c:92
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
static const ULONG FS_BOLD
Definition: mk_font.h:25
HFONT MakeFont(IN HDC hDestDC, IN LPCSTR typeface_name, IN int point_size, IN const BYTE charset, IN const DWORD style)
Definition: mk_font.cpp:23
static const ULONG FS_UNDERLINE
Definition: mk_font.h:27
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define LBS_OWNERDRAWFIXED
Definition: pedump.c:682
#define LBS_HASSTRINGS
Definition: pedump.c:684
#define WS_VSCROLL
Definition: pedump.c:627
#define WS_VISIBLE
Definition: pedump.c:620
#define LBS_NOINTEGRALHEIGHT
Definition: pedump.c:686
HPEN hListPen
Definition: primitives.cpp:168
HINSTANCE hInst
Definition: primitives.cpp:23
OutPrimitive
Definition: primitives.cpp:75
HFONT hListFont
Definition: primitives.cpp:169
HWND hListBox
Definition: primitives.cpp:166
HBRUSH hListBrush
Definition: primitives.cpp:167
void DrawPrimitive(IN HDC hDC, IN const RECT &RPrimitive, IN OutPrimitive PrimitiveID)
Definition: primitives.cpp:80
#define DefWindowProc
Definition: ros2win.h:31
LONG right
Definition: windef.h:308
LONG left
Definition: windef.h:306
#define SetWindowLongPtr
Definition: treelist.c:70
#define SNDMSG
Definition: treelist.h:31
#define HIWORD(l)
Definition: typedefs.h:247
LONG_PTR LPARAM
Definition: windef.h:208
DWORD COLORREF
Definition: windef.h:300
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
#define PALETTERGB(r, g, b)
Definition: wingdi.h:2942
#define TRANSPARENT
Definition: wingdi.h:950
BOOL WINAPI RestoreDC(_In_ HDC, _In_ int)
#define ANSI_CHARSET
Definition: wingdi.h:383
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define PS_SOLID
Definition: wingdi.h:586
int WINAPI SaveDC(_In_ HDC)
#define LB_ERR
Definition: winuser.h:2422
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CreateWindowEx
Definition: winuser.h:5745
DWORD WINAPI GetSysColor(_In_ int)
#define ODS_SELECTED
Definition: winuser.h:2535
#define EDGE_SUNKEN
Definition: winuser.h:451
#define COLOR_WINDOW
Definition: winuser.h:912
#define DT_CENTER
Definition: winuser.h:527
#define LB_GETTEXT
Definition: winuser.h:2039
#define COLOR_WINDOWTEXT
Definition: winuser.h:915
#define WM_CREATE
Definition: winuser.h:1598
#define GWL_ID
Definition: winuser.h:853
BOOL WINAPI InvertRect(_In_ HDC, _In_ LPCRECT)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1601
#define COLOR_HIGHLIGHT
Definition: winuser.h:920
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
#define LB_ADDSTRING
Definition: winuser.h:2021
#define WM_DRAWITEM
Definition: winuser.h:1635
#define DrawText
Definition: winuser.h:5761
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
#define COLOR_HIGHLIGHTTEXT
Definition: winuser.h:921
HDC WINAPI GetDC(_In_opt_ HWND)
#define WM_MEASUREITEM
Definition: winuser.h:1636
#define DT_VCENTER
Definition: winuser.h:543
#define WM_DESTROY
Definition: winuser.h:1599
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
#define BF_RECT
Definition: winuser.h:462
#define ODS_FOCUS
Definition: winuser.h:2539
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
#define COLOR_BTNFACE
Definition: winuser.h:922
char TCHAR
Definition: xmlstorage.h:189

Referenced by WinMain().

◆ WinMain()

int APIENTRY WinMain ( HINSTANCE  hInstance,
HINSTANCE  ,
LPTSTR  ,
int  nCmdShow 
)

Definition at line 29 of file primitives.cpp.

31{
33
34 WNDCLASS wc;
35 memset(&wc, 0, sizeof(WNDCLASS));
36
40 wc.hInstance = hInst;
42 wc.hbrBackground = reinterpret_cast<HBRUSH>(
44 );
45
46 if (RegisterClass(&wc))
47 {
48 HWND hWnd =
50 WndClassName, TEXT("Output Primitives Demo"),
55 );
56
57 if (hWnd)
58 {
59 ShowWindow(hWnd, nCmdShow);
61
62 MSG msg;
63 while (GetMessage(&msg, NULL, 0, 0))
64 {
67 }
68 }
69 }
70 return 0;
71}
HINSTANCE hInstance
Definition: charmap.c:19
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_CLIPCHILDREN
Definition: pedump.c:619
const char * WndClassName
Definition: primitives.cpp:24
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: primitives.cpp:171
#define memset(x, y, z)
Definition: compat.h:39
HBRUSH hbrBackground
Definition: winuser.h:3160
HINSTANCE hInstance
Definition: winuser.h:3157
HCURSOR hCursor
Definition: winuser.h:3159
UINT style
Definition: winuser.h:3153
LPCSTR lpszClassName
Definition: winuser.h:3162
WNDPROC lpfnWndProc
Definition: winuser.h:3154
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define CS_VREDRAW
Definition: winuser.h:653
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CS_HREDRAW
Definition: winuser.h:648
#define IDC_ARROW
Definition: winuser.h:682
#define CreateWindow
Definition: winuser.h:5744
#define GetMessage
Definition: winuser.h:5780
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5802
#define CW_USEDEFAULT
Definition: winuser.h:225
#define RegisterClass
Definition: winuser.h:5826
#define DispatchMessage
Definition: winuser.h:5755

Variable Documentation

◆ hInst

HINSTANCE hInst

Definition at line 23 of file primitives.cpp.

Referenced by MainWndProc(), and WinMain().

◆ hListBox

HWND hListBox = NULL

Definition at line 166 of file primitives.cpp.

Referenced by MainWndProc().

◆ hListBrush

HBRUSH hListBrush = NULL

Definition at line 167 of file primitives.cpp.

Referenced by MainWndProc().

◆ hListFont

HFONT hListFont = NULL

Definition at line 169 of file primitives.cpp.

Referenced by MainWndProc().

◆ hListPen

HPEN hListPen = NULL

Definition at line 168 of file primitives.cpp.

Referenced by MainWndProc().

◆ WndClassName

const char* WndClassName = "GMainWnd"

Definition at line 24 of file primitives.cpp.

Referenced by WinMain().