ReactOS 0.4.15-dev-7788-g1ad9096
txtscale.cpp File Reference
#include <windows.h>
#include <commctrl.h>
#include <cassert>
#include "mk_font.h"
Include dependency graph for txtscale.cpp:

Go to the source code of this file.

Functions

LRESULT CALLBACK MainWndProc (HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
 
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow)
 

Variables

HINSTANCE hInst
 
const charWndClassName = "GMainWnd"
 
HWND hTrackBar = NULL
 
HFONT hTTFont = NULL
 
double scale = 0.0
 
LPCSTR pText = TEXT("The Scaled Text!")
 

Function Documentation

◆ MainWndProc()

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

Definition at line 81 of file txtscale.cpp.

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}
static HDC hDC
Definition: 3dtext.c:33
#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
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#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
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
_In_ UINT iPoint
Definition: ntgdi.h:2197
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
long LONG
Definition: pedump.c:60
#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
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
#define SNDMSG
Definition: treelist.h:31
LPCSTR pText
Definition: txtscale.cpp:79
HWND hTrackBar
Definition: txtscale.cpp:76
HINSTANCE hInst
Definition: txtscale.cpp:24
HFONT hTTFont
Definition: txtscale.cpp:77
#define HIWORD(l)
Definition: typedefs.h:247
#define lstrlen
Definition: winbase.h:3811
LONG_PTR LRESULT
Definition: windef.h:209
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:1539
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 WM_HSCROLL
Definition: winuser.h:1743
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1611
#define CreateWindow
Definition: winuser.h:5754
HDC WINAPI GetDC(_In_opt_ HWND)
#define WM_DESTROY
Definition: winuser.h:1609
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)

Referenced by WinMain().

◆ WinMain()

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

Definition at line 30 of file txtscale.cpp.

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}
HINSTANCE hInstance
Definition: charmap.c:19
#define TEXT(s)
Definition: k32.h:26
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#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
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
const char * WndClassName
Definition: txtscale.cpp:25
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: txtscale.cpp:81
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
#define CW_USEDEFAULT
Definition: winuser.h:225
#define RegisterClass
Definition: winuser.h:5836
#define DispatchMessage
Definition: winuser.h:5765
#define COLOR_BTNFACE
Definition: winuser.h:928

Variable Documentation

◆ hInst

HINSTANCE hInst

Definition at line 24 of file txtscale.cpp.

Referenced by MainWndProc(), and WinMain().

◆ hTrackBar

HWND hTrackBar = NULL

Definition at line 76 of file txtscale.cpp.

Referenced by MainWndProc().

◆ hTTFont

HFONT hTTFont = NULL

Definition at line 77 of file txtscale.cpp.

Referenced by MainWndProc().

◆ pText

◆ scale

double scale = 0.0

Definition at line 78 of file txtscale.cpp.

◆ WndClassName

const char* WndClassName = "GMainWnd"

Definition at line 25 of file txtscale.cpp.

Referenced by WinMain().