ReactOS 0.4.16-dev-306-g647d351
enumfonts.cpp File Reference
#include <windows.h>
#include <cassert>
Include dependency graph for enumfonts.cpp:

Go to the source code of this file.

Macros

#define SNDMSG   ::SendMessage
 

Functions

LRESULT CALLBACK MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow)
 
int CALLBACK MyEnumFontFamExProc (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
 
void AddScreenFonts ()
 

Variables

HWND hListBox = NULL
 
const int ID_LISTBOX = 101
 
HINSTANCE hInst
 
const charWndClassName = "GMainWnd"
 

Macro Definition Documentation

◆ SNDMSG

#define SNDMSG   ::SendMessage

Definition at line 20 of file enumfonts.cpp.

Function Documentation

◆ AddScreenFonts()

void AddScreenFonts ( )

Definition at line 110 of file enumfonts.cpp.

111{
112 // grab a handle to the screen's DC
113 HDC hScreenDC = GetDC(NULL);
114 try
115 {
116 //
117 // NOTE: Windows 95, 98 and Me requires that the lpLogfont
118 // (second) parameter of the EnumFontFamiliesEx function is
119 // non-NULL. This parameter can be NULL on Windows NT/2000.
120 //
121 LOGFONT lf = {0};
123
124 // enumerate the current screen fonts
126 hScreenDC, &lf,
128 0, 0
129 );
130 }
131 catch (...)
132 {
133 // release the screen's DC
134 ReleaseDC(NULL, hScreenDC);
135 }
136 // release the screen's DC
137 ReleaseDC(NULL, hScreenDC);
138}
#define NULL
Definition: types.h:112
int CALLBACK MyEnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
Definition: enumfonts.cpp:82
static HDC
Definition: imagelist.c:88
BYTE lfCharSet
Definition: dimm.idl:50
FONTENUMPROCA FONTENUMPROC
Definition: wingdi.h:2902
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define EnumFontFamiliesEx
Definition: wingdi.h:4451
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by MainWndProc().

◆ MainWndProc()

LRESULT CALLBACK MainWndProc ( HWND  hWnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 142 of file enumfonts.cpp.

144{
145 switch (msg)
146 {
147 case WM_CREATE:
148 {
149 hListBox =
151 WS_EX_CLIENTEDGE, TEXT("LISTBOX"), TEXT(""),
154 20, 10, 250, 250,
155 hWnd, reinterpret_cast<HMENU>(ID_LISTBOX),
156 hInst, NULL
157 );
158 if (hListBox)
159 {
161 }
162 }
163 case WM_MEASUREITEM:
164 {
165 // grab a pointer to the MEASUREITEMSTRUCT structure
166 LPMEASUREITEMSTRUCT lpmis =
167 reinterpret_cast<LPMEASUREITEMSTRUCT>(lParam);
168
169 // test the identifier of the control that
170 // the message is meant for
171 if ((int)lpmis->CtlID == ID_LISTBOX)
172 {
173 // adjust the height
174 lpmis->itemHeight = 25;
175
176 return TRUE;
177 }
178 break;
179 }
180 case WM_DRAWITEM:
181 {
182 // grab a pointer to the DRAWITEMSTRUCT structure
183 LPDRAWITEMSTRUCT lpdis =
184 reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);
185
186 // test the identifier of the control that
187 // the message is meant for
188 if ((int)lpdis->CtlID == ID_LISTBOX)
189 {
190 COLORREF OldColor = GetTextColor(lpdis->hDC);
191 int stock = WHITE_BRUSH;
192
193 // if the item is currently selected
194 if (lpdis->itemState & ODS_SELECTED)
195 {
196 // set the text color to white and
197 // the background color to black
198 COLORREF clrWhite = PALETTERGB(255, 255, 255);
199 OldColor = SetTextColor(lpdis->hDC, clrWhite);
200 stock = BLACK_BRUSH;
201 }
202 FillRect(
203 lpdis->hDC, &lpdis->rcItem,
204 static_cast<HBRUSH>(GetStockObject(stock))
205 );
206
207 if ((int)lpdis->itemID != -1)
208 {
209 // extract the item's text
210 char text[MAX_PATH];
212 reinterpret_cast<LPARAM>(text));
213
214 // extract the corresponding font handle
215 DWORD value =
217 HFONT hFont = reinterpret_cast<HFONT>(value);
218
219 // select the corresponding font
220 // into the device context
221 HFONT HOldFont = static_cast<HFONT>(
222 SelectObject(lpdis->hDC, hFont)
223 );
224
225 // render the text transparently
226 SetBkMode(lpdis->hDC, TRANSPARENT);
227
228 // render the text
229 RECT RText = lpdis->rcItem;
230 InflateRect(&RText, -2, -2);
231 DrawText(lpdis->hDC, text, strlen(text), &RText,
233
234 // restore the previous font
235 SelectObject(lpdis->hDC, HOldFont);
236 }
237
238 // render the focus rectangle
239 if (lpdis->itemState & ODS_FOCUS)
240 {
241 DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
242 }
243
244 // restore the previous color/mode
245 SetTextColor(lpdis->hDC, OldColor);
246 SetBkMode(lpdis->hDC, OPAQUE);
247
248 return TRUE;
249 }
250 break;
251 }
252 case WM_DESTROY:
253 {
254 // delete each created font object
255 int count = SNDMSG(hListBox, LB_GETCOUNT, 0, 0);
256 for (int index = 0; index < count; ++index)
257 {
259 DeleteObject(reinterpret_cast<HFONT>(value));
260 }
261
263 break;
264 }
265 }
267}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
#define index(s, c)
Definition: various.h:29
HFONT hFont
Definition: main.c:53
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
const WCHAR * text
Definition: package.c:1794
const int ID_LISTBOX
Definition: enumfonts.cpp:28
HINSTANCE hInst
Definition: enumfonts.cpp:30
#define SNDMSG
Definition: enumfonts.cpp:20
HWND hListBox
Definition: enumfonts.cpp:27
void AddScreenFonts()
Definition: enumfonts.cpp:110
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint index
Definition: glext.h:6031
#define TEXT(s)
Definition: k32.h:26
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define WS_CHILD
Definition: pedump.c:617
#define LBS_OWNERDRAWFIXED
Definition: pedump.c:682
#define LBS_HASSTRINGS
Definition: pedump.c:684
#define WS_VISIBLE
Definition: pedump.c:620
#define DefWindowProc
Definition: ros2win.h:31
Definition: pdh_main.c:94
LONG_PTR LPARAM
Definition: windef.h:208
DWORD COLORREF
Definition: windef.h:300
HGDIOBJ WINAPI GetStockObject(_In_ int)
COLORREF WINAPI GetTextColor(_In_ HDC)
Definition: text.c:861
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define PALETTERGB(r, g, b)
Definition: wingdi.h:2942
#define TRANSPARENT
Definition: wingdi.h:950
#define WHITE_BRUSH
Definition: wingdi.h:902
#define OPAQUE
Definition: wingdi.h:949
#define BLACK_BRUSH
Definition: wingdi.h:896
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
#define CreateWindowEx
Definition: winuser.h:5767
#define LB_GETCOUNT
Definition: winuser.h:2041
#define ODS_SELECTED
Definition: winuser.h:2548
#define LB_GETITEMDATA
Definition: winuser.h:2044
#define LB_GETTEXT
Definition: winuser.h:2052
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
#define WM_DRAWITEM
Definition: winuser.h:1648
#define DrawText
Definition: winuser.h:5783
#define DT_LEFT
Definition: winuser.h:534
#define LBS_STANDARD
Definition: winuser.h:321
#define WM_MEASUREITEM
Definition: winuser.h:1649
#define DT_VCENTER
Definition: winuser.h:543
#define WM_DESTROY
Definition: winuser.h:1612
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define ODS_FOCUS
Definition: winuser.h:2552

Referenced by WinMain().

◆ MyEnumFontFamExProc()

int CALLBACK MyEnumFontFamExProc ( ENUMLOGFONTEX lpelfe,
NEWTEXTMETRICEX lpntme,
int  FontType,
LPARAM  lParam 
)

Definition at line 82 of file enumfonts.cpp.

84{
85 if (FontType == TRUETYPE_FONTTYPE)
86 {
87 // if the typeface name is not already in the list
88 LPARAM name = reinterpret_cast<LPARAM>(lpelfe->elfFullName);
90 {
91 // add each font to the list box
93
94 // fix the size of the font
95 lpelfe->elfLogFont.lfHeight = -20;
96 lpelfe->elfLogFont.lfWidth = 0;
97
98 // create a new font and store its handle
99 // as the data of the newly added item
102 reinterpret_cast<LPARAM>(hFont));
103 }
104 }
105 return TRUE;
106}
Definition: name.c:39
LOGFONTA elfLogFont
Definition: wingdi.h:2696
BYTE elfFullName[LF_FULLFACESIZE]
Definition: wingdi.h:2697
LONG lfHeight
Definition: wingdi.h:1881
LONG lfWidth
Definition: wingdi.h:1882
uint32_t ULONG
Definition: typedefs.h:59
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1109
#define CreateFontIndirect
Definition: wingdi.h:4444
#define LB_ERR
Definition: winuser.h:2435
#define LB_FINDSTRINGEXACT
Definition: winuser.h:2038
#define LB_ADDSTRING
Definition: winuser.h:2034
#define LB_SETITEMDATA
Definition: winuser.h:2068

Referenced by AddScreenFonts().

◆ WinMain()

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

Definition at line 36 of file enumfonts.cpp.

38{
40
41 WNDCLASS wc;
42 memset(&wc, 0, sizeof(WNDCLASS));
43
48 wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
49 wc.hbrBackground = reinterpret_cast<HBRUSH>(
51 );
52
53 if (RegisterClass(&wc))
54 {
55 HWND hWnd =
57 WndClassName, TEXT("Font Enumeration Demo"),
62 );
63
64 if (hWnd)
65 {
66 ShowWindow(hWnd, nCmdShow);
68
69 MSG msg;
70 while (GetMessage(&msg, NULL, 0, 0))
71 {
74 }
75 }
76 }
77 return 0;
78}
HINSTANCE hInstance
Definition: charmap.c:19
const char * WndClassName
Definition: enumfonts.cpp:31
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: enumfonts.cpp:142
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPED
Definition: pedump.c:615
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define memset(x, y, z)
Definition: compat.h:39
HBRUSH hbrBackground
Definition: winuser.h:3173
HINSTANCE hInstance
Definition: winuser.h:3170
HCURSOR hCursor
Definition: winuser.h:3172
UINT style
Definition: winuser.h:3166
LPCSTR lpszClassName
Definition: winuser.h:3175
WNDPROC lpfnWndProc
Definition: winuser.h:3167
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#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 CreateWindow
Definition: winuser.h:5766
#define GetMessage
Definition: winuser.h:5802
BOOL WINAPI UpdateWindow(_In_ HWND)
#define CW_USEDEFAULT
Definition: winuser.h:225
#define RegisterClass
Definition: winuser.h:5848
#define DispatchMessage
Definition: winuser.h:5777
#define COLOR_BTNFACE
Definition: winuser.h:931

Variable Documentation

◆ hInst

HINSTANCE hInst

Definition at line 30 of file enumfonts.cpp.

Referenced by MainWndProc(), and WinMain().

◆ hListBox

◆ ID_LISTBOX

const int ID_LISTBOX = 101

Definition at line 28 of file enumfonts.cpp.

Referenced by MainWndProc().

◆ WndClassName

const char* WndClassName = "GMainWnd"

Definition at line 31 of file enumfonts.cpp.

Referenced by WinMain().