ReactOS 0.4.15-dev-8390-g075894b
txtscale.cpp
Go to the documentation of this file.
1
2// ------------------------------------------------------------------
3// Windows 2000 Graphics API Black Book
4// Chapter 8 - Listing 8.1 (Scaled Text Demo)
5//
6// Created by Damon Chandler <dmc27@ee.cornell.edu>
7// Updates can be downloaded at: <www.coriolis.com>
8//
9// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10// if you have any questions about this code.
11// ------------------------------------------------------------------
12
13
14//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
15#include <windows.h>
16#include <commctrl.h>
17#include <cassert>
18
19// for the MakeFont() function...
20#include "mk_font.h"
21//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
22
23
25const char* WndClassName = "GMainWnd";
27 LPARAM LParam);
28
29
31 int nCmdShow)
32{
34
35 WNDCLASS wc;
36 memset(&wc, 0, sizeof(WNDCLASS));
37
41 wc.hInstance = hInst;
43 wc.hbrBackground = reinterpret_cast<HBRUSH>(
45 );
46
47 if (RegisterClass(&wc))
48 {
49 HWND hWnd =
51 WndClassName, TEXT("Scaled Text Demo"),
56 );
57
58 if (hWnd)
59 {
60 ShowWindow(hWnd, nCmdShow);
62
63 MSG msg;
64 while (GetMessage(&msg, NULL, 0, 0))
65 {
68 }
69 }
70 }
71 return 0;
72}
73//-------------------------------------------------------------------------
74
75
78double scale = 0.0;
79LPCSTR pText = TEXT("The Scaled Text!");
80
83{
84 switch (msg)
85 {
86 case WM_CREATE:
87 {
89 icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
91
93
94 hTrackBar =
100 10, 260, 375, 40,
102 );
103
107
108 // create the TrueType (scalable) font
109 HDC hDC = GetDC(hWnd);
110 try
111 {
112 // see Chapter 4 for the definition of MakeFont
113 hTTFont = font::MakeFont(hDC, "Impact", 72);
114 if (!hTTFont) throw;
115 }
116 catch (...)
117 {
119 }
121 break;
122 }
123 case WM_HSCROLL:
124 {
125 if (reinterpret_cast<HWND>(lParam) == hTrackBar)
126 {
127 //
128 // adjust the scaling factor according to
129 // the position of the trackbar's slider
130 //
131 scale = static_cast<double>(
132 (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0
133 );
134 InvalidateRect(hWnd, NULL, true);
135 }
136 break;
137 }
138 case WM_ERASEBKGND:
139 {
141
142 HDC hDC = reinterpret_cast<HDC>(wParam);
143 HFONT hOldFont = static_cast<HFONT>(
145 );
146 try
147 {
149
150 // open a path bracket
151 if (!BeginPath(hDC)) throw;
152
153 // record the text to the path
154 TextOut(hDC, 10, 10, pText, lstrlen(pText));
155
156 // close the path bracket and
157 // select the path into hDC
158 EndPath(hDC);
159
160 // determine the number of endpoints in the path
161 const int num_points = GetPath(hDC, NULL, NULL, 0);
162 if (num_points > 0)
163 {
164 // make room for the POINTs and vertex types
165 POINT* pPEnds = new POINT[num_points];
166 unsigned char* pTypes = new unsigned char[num_points];
167 try
168 {
169 // get the path's description
170 int num_got = GetPath(hDC, pPEnds, pTypes, num_points);
171 if (num_got > 0)
172 {
173 // start a new path bracket
174 if (!BeginPath(hDC)) throw;
175
176 // scale each point in the description
177 int iPoint;
178 for (iPoint = 0; iPoint < num_got; ++iPoint)
179 {
180 pPEnds[iPoint].x = static_cast<LONG>(
181 scale * pPEnds[iPoint].x + 0.5
182 );
183 pPEnds[iPoint].y = static_cast<LONG>(
184 scale * pPEnds[iPoint].y + 0.5
185 );
186 }
187
188 for (iPoint = 0; iPoint < num_points; ++iPoint)
189 {
190 // handle the MoveToEx case
191 if (pTypes[iPoint] == PT_MOVETO)
192 {
193 MoveToEx(
194 hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL
195 );
196 }
197 // handle the LineTo case
198 else if (
199 pTypes[iPoint] == PT_LINETO ||
200 pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE)
201 )
202 {
203 LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y);
204 }
205 // handle the PolyBezierTo case
206 else if (
207 pTypes[iPoint] == PT_BEZIERTO ||
208 pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE)
209 )
210 {
211 PolyBezierTo(hDC, pPEnds + iPoint, 3);
212 iPoint += 2;
213 }
214 }
215
216 // close the new path bracket
217 EndPath(hDC);
218
219 // stroke and fill the new path
221 }
222 }
223 catch (...)
224 {
225 // clean up
226 delete [] pTypes;
227 delete [] pPEnds;
228 throw;
229 }
230 // clean up
231 delete [] pTypes;
232 delete [] pPEnds;
233 }
234 // ...
235 }
236 catch (...)
237 {
238 SelectObject(hDC, hOldFont);
239 }
240 SelectObject(hDC, hOldFont);
241 return res;
242 }
243 case WM_SIZE:
244 {
246 hTrackBar,
247 0, HIWORD(lParam) - 40, LOWORD(lParam), 40,
248 false
249 );
250 break;
251 }
252 case WM_DESTROY:
253 {
254 // clean up
257 break;
258 }
259 }
261}
262//-------------------------------------------------------------------------
263
264
265
266
static HDC hDC
Definition: 3dtext.c:33
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
struct @1626 Msg[]
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define APIENTRY
Definition: api.h:79
#define CALLBACK
Definition: compat.h:35
#define assert(x)
Definition: debug.h:53
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint res
Definition: glext.h:9613
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9032
#define TEXT(s)
Definition: k32.h:26
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
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
unsigned int UINT
Definition: ndis.h:50
_In_ UINT iPoint
Definition: ntgdi.h:2197
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
long LONG
Definition: pedump.c:60
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define TBS_FIXEDLENGTH
Definition: commctrl.h:2025
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
#define TBM_GETPOS
Definition: commctrl.h:2031
#define TBS_BOTH
Definition: commctrl.h:2022
#define TBS_HORZ
Definition: commctrl.h:2017
#define TBS_ENABLESELRANGE
Definition: commctrl.h:2024
#define TBS_AUTOTICKS
Definition: commctrl.h:2015
#define TBM_SETRANGEMAX
Definition: commctrl.h:2039
#define ICC_BAR_CLASSES
Definition: commctrl.h:60
#define TBM_SETTHUMBLENGTH
Definition: commctrl.h:2057
#define TRACKBAR_CLASS
Definition: commctrl.h:2013
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
HBRUSH hbrBackground
Definition: winuser.h:3170
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
UINT style
Definition: winuser.h:3163
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
#define SNDMSG
Definition: treelist.h:31
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
LPCSTR pText
Definition: txtscale.cpp:79
const char * WndClassName
Definition: txtscale.cpp:25
HWND hTrackBar
Definition: txtscale.cpp:76
HINSTANCE hInst
Definition: txtscale.cpp:24
HFONT hTTFont
Definition: txtscale.cpp:77
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: txtscale.cpp:81
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow)
Definition: txtscale.cpp:30
#define HIWORD(l)
Definition: typedefs.h:247
#define lstrlen
Definition: winbase.h:3876
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI PolyBezierTo(_In_ HDC hdc, _In_reads_(cpt) const POINT *apt, _In_ DWORD cpt)
Definition: painting.c:281
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
#define PT_LINETO
Definition: wingdi.h:885
#define TRANSPARENT
Definition: wingdi.h:950
#define PT_CLOSEFIGURE
Definition: wingdi.h:887
#define PT_MOVETO
Definition: wingdi.h:884
BOOL WINAPI StrokeAndFillPath(_In_ HDC)
#define PT_BEZIERTO
Definition: wingdi.h:886
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
BOOL WINAPI EndPath(_In_ HDC)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
BOOL WINAPI BeginPath(_In_ HDC hdc)
#define TextOut
Definition: wingdi.h:4483
int WINAPI GetPath(_In_ HDC hdc, _Out_writes_opt_(cpt) LPPOINT apt, _Out_writes_opt_(cpt) LPBYTE aj, int cpt)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_ERASEBKGND
Definition: winuser.h:1625
#define CS_VREDRAW
Definition: winuser.h:658
#define WM_HSCROLL
Definition: winuser.h:1743
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1611
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define CreateWindow
Definition: winuser.h:5763
#define GetMessage
Definition: winuser.h:5799
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5821
HDC WINAPI GetDC(_In_opt_ HWND)
#define CW_USEDEFAULT
Definition: winuser.h:225
#define RegisterClass
Definition: winuser.h:5845
#define WM_DESTROY
Definition: winuser.h:1609
#define DispatchMessage
Definition: winuser.h:5774
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
BOOL WINAPI MoveWindow(_In_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ BOOL)
#define COLOR_BTNFACE
Definition: winuser.h:928
const char * LPCSTR
Definition: xmlstorage.h:183
CHAR * LPTSTR
Definition: xmlstorage.h:192