ReactOS 0.4.15-dev-5666-gc548b97
enumfonts.cpp
Go to the documentation of this file.
1
2// ------------------------------------------------------------------
3// Windows 2000 Graphics API Black Book
4// Chapter 4 - Listing 4.2 (Font Enumeration 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 <cassert>
17
18
19#ifndef SNDMSG
20#define SNDMSG ::SendMessage
21#endif /* ifndef SNDMSG */
22
23
24//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25
26
28const int ID_LISTBOX = 101;
29
31const char* WndClassName = "GMainWnd";
34
35
37 int nCmdShow)
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}
79//-------------------------------------------------------------------------
80
81
83 NEWTEXTMETRICEX* lpntme, int FontType, LPARAM lParam)
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}
107//-------------------------------------------------------------------------
108
109
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}
139//-------------------------------------------------------------------------
140
141
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}
268//-------------------------------------------------------------------------
269
270
271
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
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define APIENTRY
Definition: api.h:79
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
const WCHAR * text
Definition: package.c:1799
const int ID_LISTBOX
Definition: enumfonts.cpp:28
int CALLBACK MyEnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
Definition: enumfonts.cpp:82
const char * WndClassName
Definition: enumfonts.cpp:31
HINSTANCE hInst
Definition: enumfonts.cpp:30
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: enumfonts.cpp:142
#define SNDMSG
Definition: enumfonts.cpp:20
HWND hListBox
Definition: enumfonts.cpp:27
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow)
Definition: enumfonts.cpp:36
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
unsigned int ULONG
Definition: retypes.h:1
static HDC
Definition: imagelist.c:92
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:60
unsigned int UINT
Definition: ndis.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPED
Definition: pedump.c:615
#define WS_SYSMENU
Definition: pedump.c:629
#define LBS_OWNERDRAWFIXED
Definition: pedump.c:682
#define LBS_HASSTRINGS
Definition: pedump.c:684
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
BYTE lfCharSet
Definition: dimm.idl:50
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
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
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
Definition: pdh_main.c:94
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
HGDIOBJ WINAPI GetStockObject(_In_ int)
FONTENUMPROCA FONTENUMPROC
Definition: wingdi.h:2902
COLORREF WINAPI GetTextColor(_In_ HDC)
Definition: text.c:861
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1109
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define PALETTERGB(r, g, b)
Definition: wingdi.h:2942
#define TRANSPARENT
Definition: wingdi.h:950
#define WHITE_BRUSH
Definition: wingdi.h:902
#define EnumFontFamiliesEx
Definition: wingdi.h:4451
#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 CreateFontIndirect
Definition: wingdi.h:4444
#define LB_ERR
Definition: winuser.h:2422
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CS_VREDRAW
Definition: winuser.h:653
#define CreateWindowEx
Definition: winuser.h:5745
#define LB_GETCOUNT
Definition: winuser.h:2028
#define ODS_SELECTED
Definition: winuser.h:2535
#define LB_FINDSTRINGEXACT
Definition: winuser.h:2025
#define LB_GETITEMDATA
Definition: winuser.h:2031
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define LB_GETTEXT
Definition: winuser.h:2039
#define WM_CREATE
Definition: winuser.h:1598
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
#define CS_HREDRAW
Definition: winuser.h:648
#define LB_ADDSTRING
Definition: winuser.h:2021
#define WM_DRAWITEM
Definition: winuser.h:1635
#define DrawText
Definition: winuser.h:5761
#define CreateWindow
Definition: winuser.h:5744
#define GetMessage
Definition: winuser.h:5780
#define DT_LEFT
Definition: winuser.h:534
#define LBS_STANDARD
Definition: winuser.h:321
BOOL WINAPI UpdateWindow(_In_ HWND)
HDC WINAPI GetDC(_In_opt_ HWND)
#define WM_MEASUREITEM
Definition: winuser.h:1636
#define DT_VCENTER
Definition: winuser.h:543
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LB_SETITEMDATA
Definition: winuser.h:2055
#define RegisterClass
Definition: winuser.h:5826
#define WM_DESTROY
Definition: winuser.h:1599
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define DispatchMessage
Definition: winuser.h:5755
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define ODS_FOCUS
Definition: winuser.h:2539
#define COLOR_BTNFACE
Definition: winuser.h:922
CHAR * LPTSTR
Definition: xmlstorage.h:192