ReactOS  0.4.15-dev-448-gd6c4411
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 }
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC
Definition: imagelist.c:92
BYTE lfCharSet
Definition: dimm.idl:50
#define DEFAULT_CHARSET
Definition: wingdi.h:383
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
#define EnumFontFamiliesEx
Definition: wingdi.h:4450
int CALLBACK MyEnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam)
Definition: enumfonts.cpp:82
FONTENUMPROCA FONTENUMPROC
Definition: wingdi.h:2901

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  {
160  AddScreenFonts();
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];
211  SNDMSG(hListBox, LB_GETTEXT, lpdis->itemID,
212  reinterpret_cast<LPARAM>(text));
213 
214  // extract the corresponding font handle
215  DWORD value =
216  SNDMSG(hListBox, LB_GETITEMDATA, lpdis->itemID, 0);
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 
262  PostQuitMessage(0);
263  break;
264  }
265  }
266  return DefWindowProc(hWnd, msg, wParam, lParam);
267 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define SNDMSG
Definition: enumfonts.cpp:20
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
const WCHAR * text
Definition: package.c:1827
#define LB_GETITEMDATA
Definition: winuser.h:2023
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define LBS_HASSTRINGS
Definition: pedump.c:684
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
HWND hWnd
Definition: settings.c:17
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define ODS_FOCUS
Definition: winuser.h:2524
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define WHITE_BRUSH
Definition: wingdi.h:901
#define WS_CHILD
Definition: pedump.c:617
WPARAM wParam
Definition: combotst.c:138
#define LBS_STANDARD
Definition: winuser.h:321
HFONT hFont
Definition: main.c:53
#define DrawText
Definition: winuser.h:5746
#define LBS_OWNERDRAWFIXED
Definition: pedump.c:682
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
#define DT_LEFT
Definition: winuser.h:534
const int ID_LISTBOX
Definition: enumfonts.cpp:28
#define CreateWindowEx
Definition: winuser.h:5730
#define TRANSPARENT
Definition: wingdi.h:949
COLORREF WINAPI GetTextColor(_In_ HDC)
Definition: text.c:831
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
#define DT_VCENTER
Definition: winuser.h:543
#define LB_GETCOUNT
Definition: winuser.h:2020
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define BLACK_BRUSH
Definition: wingdi.h:895
DWORD COLORREF
Definition: windef.h:300
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WM_MEASUREITEM
Definition: winuser.h:1628
#define index(s, c)
Definition: various.h:29
#define OPAQUE
Definition: wingdi.h:948
#define LB_GETTEXT
Definition: winuser.h:2031
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
#define DT_SINGLELINE
Definition: winuser.h:540
#define TEXT(s)
Definition: k32.h:26
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define PALETTERGB(r, g, b)
Definition: wingdi.h:2941
#define WM_DRAWITEM
Definition: winuser.h:1627
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define ODS_SELECTED
Definition: winuser.h:2520
#define WM_CREATE
Definition: winuser.h:1590
void AddScreenFonts()
Definition: enumfonts.cpp:110
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define WS_VISIBLE
Definition: pedump.c:620
HWND hListBox
Definition: enumfonts.cpp:27
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
HINSTANCE hInst
Definition: enumfonts.cpp:30

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 }
#define SNDMSG
Definition: enumfonts.cpp:20
#define TRUE
Definition: types.h:120
#define LB_FINDSTRINGEXACT
Definition: winuser.h:2017
#define LB_ADDSTRING
Definition: winuser.h:2013
BYTE elfFullName[LF_FULLFACESIZE]
Definition: wingdi.h:2696
HFONT hFont
Definition: main.c:53
#define LB_ERR
Definition: winuser.h:2407
LONG lfHeight
Definition: dimm.idl:42
LONG_PTR LPARAM
Definition: windef.h:208
GLuint index
Definition: glext.h:6031
LONG lfWidth
Definition: dimm.idl:43
#define LB_SETITEMDATA
Definition: winuser.h:2047
#define CreateFontIndirect
Definition: wingdi.h:4443
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
Definition: name.c:38
unsigned int ULONG
Definition: retypes.h:1
HWND hListBox
Definition: enumfonts.cpp:27
LOGFONTA elfLogFont
Definition: wingdi.h:2695
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1108

Referenced by AddScreenFonts().

◆ WinMain()

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

Definition at line 36 of file enumfonts.cpp.

38 {
39  hInst = hInstance;
40 
41  WNDCLASS wc;
42  memset(&wc, 0, sizeof(WNDCLASS));
43 
47  wc.hInstance = hInstance;
48  wc.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW);
49  wc.hbrBackground = reinterpret_cast<HBRUSH>(
50  COLOR_BTNFACE + 1
51  );
52 
53  if (RegisterClass(&wc))
54  {
55  HWND hWnd =
57  WndClassName, TEXT("Font Enumeration Demo"),
60  CW_USEDEFAULT, CW_USEDEFAULT, 295, 285,
61  NULL, NULL, hInst, NULL
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 }
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define CreateWindow
Definition: winuser.h:5729
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
#define CS_HREDRAW
Definition: winuser.h:648
HBRUSH hbrBackground
Definition: winuser.h:3145
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WS_CLIPCHILDREN
Definition: pedump.c:619
HINSTANCE hInstance
Definition: charmap.c:20
HCURSOR hCursor
Definition: winuser.h:3144
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define WS_CAPTION
Definition: pedump.c:624
#define CS_VREDRAW
Definition: winuser.h:653
#define WS_OVERLAPPED
Definition: pedump.c:615
#define COLOR_BTNFACE
Definition: winuser.h:918
LPCSTR lpszClassName
Definition: winuser.h:3147
UINT style
Definition: winuser.h:3138
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: enumfonts.cpp:142
#define TEXT(s)
Definition: k32.h:26
HINSTANCE hInstance
Definition: winuser.h:3142
#define GetMessage
Definition: winuser.h:5765
WNDPROC lpfnWndProc
Definition: winuser.h:3139
#define msg(x)
Definition: auth_time.c:54
#define RegisterClass
Definition: winuser.h:5811
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_SYSMENU
Definition: pedump.c:629
#define memset(x, y, z)
Definition: compat.h:39
HINSTANCE hInst
Definition: enumfonts.cpp:30
const char * WndClassName
Definition: enumfonts.cpp:31

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().