ReactOS  0.4.12-dev-102-g4b7f1e0
fontview.c File Reference
#include "precomp.h"
#include <winnls.h>
#include <shellapi.h>
#include <windowsx.h>
#include <winreg.h>
#include "fontview.h"
#include "resource.h"
Include dependency graph for fontview.c:

Go to the source code of this file.

Functions

BOOL WINAPI GetFontResourceInfoW (LPCWSTR lpFileName, DWORD *pdwBufSize, void *lpBuffer, DWORD dwType)
 
DWORD FormatString (DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
 
static void ErrorMsgBox (HWND hParent, DWORD dwMessageId,...)
 
int WINAPI wWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
 
static LRESULT MainWnd_OnCreate (HWND hwnd)
 
static LRESULT MainWnd_OnSize (HWND hwnd)
 
static LRESULT MainWnd_OnPaint (HWND hwnd)
 
static LRESULT MainWnd_OnInstall (HWND hwnd)
 
static LRESULT MainWnd_OnPrev (HWND hwnd)
 
static LRESULT MainWnd_OnNext (HWND hwnd)
 
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 

Variables

HINSTANCE g_hInstance
 
INT g_FontIndex = 0
 
INT g_NumFonts = 0
 
LOGFONTW g_LogFonts [64]
 
LPCWSTR g_fileName
 
WCHAR g_FontTitle [1024] = L""
 
BOOL g_FontPrint = FALSE
 
static const WCHAR g_szFontViewClassName [] = L"FontViewWClass"
 

Function Documentation

◆ ErrorMsgBox()

static void ErrorMsgBox ( HWND  hParent,
DWORD  dwMessageId,
  ... 
)
static

Definition at line 75 of file fontview.c.

Referenced by MainWnd_OnInstall(), and wWinMain().

76 {
77  HLOCAL hMemCaption = NULL;
78  HLOCAL hMemText = NULL;
79  va_list args;
80 
81  va_start(args, dwMessageId);
83  NULL, dwMessageId, 0, (LPWSTR)&hMemText, 0, &args);
84  va_end(args);
85 
87  NULL, IDS_ERROR, 0, (LPWSTR)&hMemCaption, 0, NULL);
88 
89  MessageBoxW(hParent, hMemText, hMemCaption, MB_ICONERROR);
90 
91  LocalFree(hMemCaption);
92  LocalFree(hMemText);
93 }
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:48
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define MB_ICONERROR
Definition: winuser.h:781
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define IDS_ERROR
Definition: resource.h:18
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define args
Definition: format.c:66

◆ FormatString()

DWORD FormatString ( DWORD  dwFlags,
HINSTANCE  hInstance,
DWORD  dwStringId,
DWORD  dwLanguageId,
LPWSTR  lpBuffer,
DWORD  nSize,
va_list Arguments 
)

Definition at line 48 of file fontview.c.

Referenced by BmFatalErrorEx(), ErrorMsgBox(), EtfsOpen(), GetComCtl32Version(), GetExecutableVendor(), LoadXMLDocumentFromFile(), LoadXMLDocumentFromResource(), RequiredServicesDisablingDialogWndProc(), ServicesPageWndProc(), and UserpFormatMessages().

57 {
58  DWORD dwRet;
59  int len;
60  WCHAR Buffer[1000];
61 
62  len = LoadStringW(hInstance, dwStringId, (LPWSTR)Buffer, 1000);
63 
64  if (len)
65  {
68  dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments);
69  return dwRet;
70  }
71  return 0;
72 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:163
Definition: bufpool.h:45
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
GLenum GLsizei len
Definition: glext.h:6722
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ GetFontResourceInfoW()

BOOL WINAPI GetFontResourceInfoW ( LPCWSTR  lpFileName,
DWORD pdwBufSize,
void lpBuffer,
DWORD  dwType 
)

Referenced by wWinMain().

◆ MainWnd_OnCreate()

static LRESULT MainWnd_OnCreate ( HWND  hwnd)
static

Definition at line 273 of file fontview.c.

Referenced by MainWndProc().

274 {
275  WCHAR szQuit[MAX_BUTTONNAME];
276  WCHAR szPrint[MAX_BUTTONNAME];
277  WCHAR szString[MAX_STRING];
278  WCHAR szPrevious[MAX_STRING];
279  WCHAR szNext[MAX_STRING];
280  HWND hDisplay, hButtonInstall, hButtonPrint, hButtonPrev, hButtonNext;
281 
282  /* create the display window */
283  hDisplay = CreateWindowExW(
284  0, /* Extended style */
285  g_szFontDisplayClassName, /* Classname */
286  L"", /* Title text */
287  WS_CHILD | WS_VSCROLL, /* Window style */
288  0, /* X-pos */
289  HEADER_SIZE, /* Y-Pos */
290  550, /* Width */
291  370-HEADER_SIZE, /* Height */
292  hwnd, /* Parent */
293  (HMENU)IDC_DISPLAY, /* Identifier */
294  g_hInstance, /* Program Instance handler */
295  NULL /* Window Creation data */
296  );
297 
299  SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
300 
301  /* Create the install button */
303  hButtonInstall = CreateWindowExW(
304  0, /* Extended style */
305  L"button", /* Classname */
306  szQuit, /* Title text */
307  WS_CHILD | WS_VISIBLE, /* Window style */
308  BUTTON_POS_X, /* X-pos */
309  BUTTON_POS_Y, /* Y-Pos */
310  BUTTON_WIDTH, /* Width */
311  BUTTON_HEIGHT, /* Height */
312  hwnd, /* Parent */
313  (HMENU)IDC_INSTALL, /* Identifier */
314  g_hInstance, /* Program Instance handler */
315  NULL /* Window Creation data */
316  );
318 
319  /* Create the print button */
321  hButtonPrint = CreateWindowExW(
322  0, /* Extended style */
323  L"button", /* Classname */
324  szPrint, /* Title text */
325  WS_CHILD | WS_VISIBLE, /* Window style */
326  450, /* X-pos */
327  BUTTON_POS_Y, /* Y-Pos */
328  BUTTON_WIDTH, /* Width */
329  BUTTON_HEIGHT, /* Height */
330  hwnd, /* Parent */
331  (HMENU)IDC_PRINT, /* Identifier */
332  g_hInstance, /* Program Instance handler */
333  NULL /* Window Creation data */
334  );
336 
337  /* Create the previous button */
339  hButtonPrev = CreateWindowExW(
340  0, /* Extended style */
341  L"button", /* Classname */
342  szPrevious, /* Title text */
343  WS_CHILD | WS_VISIBLE, /* Window style */
344  450, /* X-pos */
345  BUTTON_POS_Y, /* Y-Pos */
346  BUTTON_WIDTH, /* Width */
347  BUTTON_HEIGHT, /* Height */
348  hwnd, /* Parent */
349  (HMENU)IDC_PREV, /* Identifier */
350  g_hInstance, /* Program Instance handler */
351  NULL /* Window Creation data */
352  );
354 
355  /* Create the next button */
357  hButtonNext = CreateWindowExW(
358  0, /* Extended style */
359  L"button", /* Classname */
360  szNext, /* Title text */
361  WS_CHILD | WS_VISIBLE, /* Window style */
362  450, /* X-pos */
363  BUTTON_POS_Y, /* Y-Pos */
364  BUTTON_WIDTH, /* Width */
365  BUTTON_HEIGHT, /* Height */
366  hwnd, /* Parent */
367  (HMENU)IDC_NEXT, /* Identifier */
368  g_hInstance, /* Program Instance handler */
369  NULL /* Window Creation data */
370  );
372 
373  EnableWindow(hButtonPrev, FALSE);
374  if (g_NumFonts <= 1)
375  EnableWindow(hButtonNext, FALSE);
376 
377  /* Init the display window with the font name */
378  g_FontIndex = 0;
380  ShowWindow(hDisplay, SW_SHOWNORMAL);
381 
382  if (g_FontPrint)
383  PostMessage(hwnd, WM_COMMAND, IDC_PRINT, 0);
384 
385  return 0;
386 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BUTTON_WIDTH
Definition: fontview.h:9
#define TRUE
Definition: types.h:120
HINSTANCE g_hInstance
Definition: fontview.c:34
__wchar_t WCHAR
Definition: xmlstorage.h:180
INT g_NumFonts
Definition: fontview.c:36
#define IDS_STRING
Definition: resource.h:11
#define IDC_NEXT
Definition: fontview.h:17
BOOL g_FontPrint
Definition: fontview.c:40
#define WS_CHILD
Definition: pedump.c:617
#define IDS_PRINT
Definition: resource.h:10
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define BUTTON_POS_X
Definition: fontview.h:7
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
UINT_PTR WPARAM
Definition: windef.h:207
#define IDS_INSTALL
Definition: resource.h:9
#define IDS_NEXT
Definition: resource.h:13
#define BUTTON_POS_Y
Definition: fontview.h:8
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
#define FVM_SETTYPEFACE
Definition: display.h:4
#define PostMessage
Definition: winuser.h:5698
#define IDC_PREV
Definition: fontview.h:16
#define DEFAULT_GUI_FONT
Definition: wingdi.h:907
static const WCHAR L[]
Definition: oid.c:1087
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define IDC_DISPLAY
Definition: resource.h:19
LOGFONTW g_LogFonts[64]
Definition: fontview.c:37
#define WM_COMMAND
Definition: winuser.h:1716
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define FVM_SETSTRING
Definition: display.h:5
#define SW_SHOWNORMAL
Definition: winuser.h:764
#define BUTTON_HEIGHT
Definition: fontview.h:10
#define WS_VSCROLL
Definition: pedump.c:627
#define WM_SETFONT
Definition: winuser.h:1632
#define HEADER_SIZE
Definition: fontview.h:6
#define SendMessage
Definition: winuser.h:5709
#define MAX_BUTTONNAME
Definition: fontview.h:4
const WCHAR g_szFontDisplayClassName[]
Definition: display.c:34
#define IDS_PREVIOUS
Definition: resource.h:18
INT g_FontIndex
Definition: fontview.c:35
#define WS_VISIBLE
Definition: pedump.c:620
#define IDC_INSTALL
Definition: fontview.h:13
#define IDC_PRINT
Definition: fontview.h:14
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define MAX_STRING
Definition: doskey.c:43

◆ MainWnd_OnInstall()

static LRESULT MainWnd_OnInstall ( HWND  hwnd)
static

Definition at line 443 of file fontview.c.

Referenced by MainWndProc().

444 {
445  WCHAR szFullName[64];
446 
447  WCHAR szSrcPath[MAX_PATH];
448  WCHAR szDestPath[MAX_PATH];
450  LONG res;
451  HKEY hKey;
452 
453  SendDlgItemMessage(hwnd, IDC_DISPLAY, FVM_GETFULLNAME, 64, (LPARAM)szFullName);
454 // MessageBoxW(hwnd, szFullName, L"Debug", MB_OK);
455 
456  /* First, we have to find out if the font still exists */
458  {
459  /* Fail, if the source file does not exist */
461  return -1;
462  }
463 
464  /* Build the full destination file name */
465  GetFullPathNameW(g_fileName, MAX_PATH, szSrcPath, &pszFileName);
466 
467  GetWindowsDirectoryW(szDestPath, MAX_PATH);
468  wcscat(szDestPath, L"\\Fonts\\");
469  wcscat(szDestPath, pszFileName);
470 
471  /* Debug Message */
472 // MessageBoxW(hwnd, szDestPath, L"szDestPath", MB_OK);
473 // MessageBoxW(hwnd, pszFileName, L"pszFileExt", MB_OK);
474 
475  /* Check if the file already exists */
476  if (GetFileAttributesW(szDestPath) != INVALID_FILE_ATTRIBUTES)
477  {
478  MessageBoxW(hwnd, L"This font is already installed!", L"Already Installed", MB_OK);
479  return 0;
480  }
481 
482  /* Copy the font file */
483  if (!CopyFileW(g_fileName, szDestPath, TRUE))
484  {
485  MessageBoxW(hwnd,L"Failed to copy the font file!", L"File Error", MB_OK);
486  return -1;
487  }
488 
489  /* Open the fonts key */
491  L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
492  0,
494  &hKey);
495  if (res != ERROR_SUCCESS)
496  {
497  MessageBoxW(hwnd, L"Failed top open the fonts key!", L"Debug1", MB_OK);
498  return -1;
499  }
500 
501  /* Register the font */
502  res = RegSetValueExW(hKey,
503  szFullName,
504  0,
505  REG_SZ,
506  (LPBYTE)pszFileName,
507  (wcslen(pszFileName) + 1) * sizeof(WCHAR));
508  if (res != ERROR_SUCCESS)
509  {
510  MessageBoxW(hwnd, L"Failed to register the new font!", L"Debug2", MB_OK);
511  RegCloseKey(hKey);
512  return -1;
513  }
514 
515  /* Close the fonts key */
516  RegCloseKey(hKey);
517 
518  /* if all of this goes correctly, message the user about success */
519  MessageBoxW(hwnd, L"Font Installation Completed.", L"Success", MB_OK);
520 
521  return 0;
522 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint16_t * PWSTR
Definition: typedefs.h:54
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
#define IDS_ERROR_NOFONT
Definition: resource.h:5
#define SendDlgItemMessage
Definition: winuser.h:5708
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
LONG_PTR LPARAM
Definition: windef.h:208
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
LPCWSTR g_fileName
Definition: fontview.c:38
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
#define MAX_PATH
Definition: compat.h:26
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1087
#define IDC_DISPLAY
Definition: resource.h:19
static void ErrorMsgBox(HWND hParent, DWORD dwMessageId,...)
Definition: fontview.c:75
#define GetFileAttributes
Definition: winbase.h:3629
#define FVM_GETFULLNAME
Definition: display.h:6
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define MB_OK
Definition: winuser.h:784
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

◆ MainWnd_OnNext()

static LRESULT MainWnd_OnNext ( HWND  hwnd)
static

Definition at line 543 of file fontview.c.

Referenced by MainWndProc().

544 {
545  HWND hDisplay;
546  if (g_FontIndex + 1 < g_NumFonts)
547  {
548  ++g_FontIndex;
550  if (g_FontIndex == g_NumFonts - 1)
552 
553  hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
555  InvalidateRect(hDisplay, NULL, TRUE);
556  }
557  return 0;
558 }
#define TRUE
Definition: types.h:120
INT g_NumFonts
Definition: fontview.c:36
#define IDC_NEXT
Definition: fontview.h:17
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
#define FVM_SETTYPEFACE
Definition: display.h:4
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDC_PREV
Definition: fontview.h:16
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define IDC_DISPLAY
Definition: resource.h:19
LOGFONTW g_LogFonts[64]
Definition: fontview.c:37
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define SendMessage
Definition: winuser.h:5709
INT g_FontIndex
Definition: fontview.c:35

◆ MainWnd_OnPaint()

static LRESULT MainWnd_OnPaint ( HWND  hwnd)
static

Definition at line 427 of file fontview.c.

Referenced by MainWndProc().

428 {
429  HDC hDC;
430  PAINTSTRUCT ps;
431  RECT rc;
432 
433  hDC = BeginPaint(hwnd, &ps);
434  GetClientRect(hwnd, &rc);
435  rc.top = HEADER_SIZE - 2;
436  rc.bottom = HEADER_SIZE;
437  FillRect(hDC, &rc, GetStockObject(GRAY_BRUSH));
438  EndPaint(hwnd, &ps);
439  return 0;
440 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define HDC
Definition: msvc.h:22
LONG top
Definition: windef.h:297
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define GRAY_BRUSH
Definition: wingdi.h:896
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define HEADER_SIZE
Definition: fontview.h:6
LONG bottom
Definition: windef.h:299
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)

◆ MainWnd_OnPrev()

static LRESULT MainWnd_OnPrev ( HWND  hwnd)
static

Definition at line 525 of file fontview.c.

Referenced by MainWndProc().

526 {
527  HWND hDisplay;
528  if (g_FontIndex > 0)
529  {
530  --g_FontIndex;
532  if (g_FontIndex == 0)
534 
535  hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
537  InvalidateRect(hDisplay, NULL, TRUE);
538  }
539  return 0;
540 }
#define TRUE
Definition: types.h:120
#define IDC_NEXT
Definition: fontview.h:17
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
#define FVM_SETTYPEFACE
Definition: display.h:4
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDC_PREV
Definition: fontview.h:16
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define IDC_DISPLAY
Definition: resource.h:19
LOGFONTW g_LogFonts[64]
Definition: fontview.c:37
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define SendMessage
Definition: winuser.h:5709
INT g_FontIndex
Definition: fontview.c:35

◆ MainWnd_OnSize()

static LRESULT MainWnd_OnSize ( HWND  hwnd)
static

Definition at line 389 of file fontview.c.

Referenced by MainWndProc().

390 {
391  RECT rc;
392  HWND hInstall, hPrint, hPrev, hNext, hDisplay;
393  HDWP hDWP;
394 
395  GetClientRect(hwnd, &rc);
396 
397  hDWP = BeginDeferWindowPos(5);
398 
399  hInstall = GetDlgItem(hwnd, IDC_INSTALL);
400  if (hDWP)
402 
403  hPrint = GetDlgItem(hwnd, IDC_PRINT);
404  if (hDWP)
406 
407  hPrev = GetDlgItem(hwnd, IDC_PREV);
408  if (hDWP)
410 
411  hNext = GetDlgItem(hwnd, IDC_NEXT);
412  if (hDWP)
414 
415  hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
416  if (hDWP)
417  hDWP = DeferWindowPos(hDWP, hDisplay, NULL, 0, HEADER_SIZE, rc.right, rc.bottom - HEADER_SIZE, SWP_NOZORDER);
418 
419  EndDeferWindowPos(hDWP);
420 
421  InvalidateRect(hwnd, NULL, TRUE);
422 
423  return 0;
424 }
#define BUTTON_WIDTH
Definition: fontview.h:9
HDWP WINAPI BeginDeferWindowPos(_In_ int)
#define TRUE
Definition: types.h:120
#define IDC_NEXT
Definition: fontview.h:17
#define SWP_NOZORDER
Definition: winuser.h:1232
#define BUTTON_POS_X
Definition: fontview.h:7
LONG right
Definition: windef.h:298
#define BUTTON_POS_Y
Definition: fontview.h:8
BOOL WINAPI EndDeferWindowPos(_In_ HDWP)
smooth NULL
Definition: ftsmooth.c:416
HDWP WINAPI DeferWindowPos(_In_ HDWP, _In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDC_PREV
Definition: fontview.h:16
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define IDC_DISPLAY
Definition: resource.h:19
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define BUTTON_HEIGHT
Definition: fontview.h:10
#define HEADER_SIZE
Definition: fontview.h:6
LONG bottom
Definition: windef.h:299
#define IDC_INSTALL
Definition: fontview.h:13
#define IDC_PRINT
Definition: fontview.h:14
#define BUTTON_PADDING
Definition: fontview.h:11

◆ MainWndProc()

LRESULT CALLBACK MainWndProc ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 561 of file fontview.c.

Referenced by wWinMain().

562 {
563  switch (message)
564  {
565  case WM_CREATE:
566  return MainWnd_OnCreate(hwnd);
567 
568  case WM_PAINT:
569  return MainWnd_OnPaint(hwnd);
570 
571  case WM_SIZE:
572  return MainWnd_OnSize(hwnd);
573 
574  case WM_COMMAND:
575  switch(LOWORD(wParam))
576  {
577  case IDC_INSTALL:
578  return MainWnd_OnInstall(hwnd);
579 
580  case IDC_PRINT:
581  return Display_OnPrint(hwnd);
582 
583  case IDC_PREV:
584  return MainWnd_OnPrev(hwnd);
585 
586  case IDC_NEXT:
587  return MainWnd_OnNext(hwnd);
588  }
589  break;
590 
591  case WM_DESTROY:
592  PostQuitMessage (0); /* send a WM_QUIT to the message queue */
593  break;
594 
595  default: /* for messages that we don't deal with */
596  return DefWindowProcW(hwnd, message, wParam, lParam);
597  }
598 
599  return 0;
600 }
Definition: tftpd.h:59
static LRESULT MainWnd_OnSize(HWND hwnd)
Definition: fontview.c:389
#define IDC_NEXT
Definition: fontview.h:17
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static LRESULT MainWnd_OnPaint(HWND hwnd)
Definition: fontview.c:427
static LRESULT MainWnd_OnInstall(HWND hwnd)
Definition: fontview.c:443
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_SIZE
Definition: winuser.h:1593
#define IDC_PREV
Definition: fontview.h:16
#define WM_PAINT
Definition: winuser.h:1602
static LRESULT MainWnd_OnNext(HWND hwnd)
Definition: fontview.c:543
static LRESULT MainWnd_OnCreate(HWND hwnd)
Definition: fontview.c:273
#define WM_COMMAND
Definition: winuser.h:1716
static LRESULT MainWnd_OnPrev(HWND hwnd)
Definition: fontview.c:525
#define WM_CREATE
Definition: winuser.h:1590
#define IDC_INSTALL
Definition: fontview.h:13
#define IDC_PRINT
Definition: fontview.h:14
LRESULT Display_OnPrint(HWND hwnd)
Definition: display.c:437
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

◆ wWinMain()

int WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
int  nShowCmd 
)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Definition at line 96 of file fontview.c.

100 {
101  int argc;
102  INT i;
103  WCHAR** argv;
104  WCHAR szFileName[MAX_PATH] = L"";
105  DWORD dwSize;
106  HWND hMainWnd;
107  MSG msg;
108  WNDCLASSEXW wincl;
109  LPCWSTR fileName;
110 
111  switch (GetUserDefaultUILanguage())
112  {
115  break;
116 
117  default:
118  break;
119  }
120 
121  g_hInstance = hThisInstance;
122 
123  /* Get unicode command line */
124  argv = CommandLineToArgvW(GetCommandLineW(), &argc);
125  if (argc < 2)
126  {
127  OPENFILENAMEW fontOpen;
128  WCHAR filter[MAX_PATH*2], dialogTitle[MAX_PATH];
129 
130  LoadStringW(NULL, IDS_OPEN, dialogTitle, ARRAYSIZE(dialogTitle));
131  LoadStringW(NULL, IDS_FILTER_LIST, filter, ARRAYSIZE(filter));
132 
133  /* Clears out any values of fontOpen before we use it */
134  ZeroMemory(&fontOpen, sizeof(fontOpen));
135 
136  /* Sets up the open dialog box */
137  fontOpen.lStructSize = sizeof(fontOpen);
138  fontOpen.hwndOwner = NULL;
139  fontOpen.lpstrFilter = filter;
140  fontOpen.lpstrFile = szFileName;
141  fontOpen.lpstrTitle = dialogTitle;
142  fontOpen.nMaxFile = MAX_PATH;
144  fontOpen.lpstrDefExt = L"ttf";
145 
146  /* Opens up the Open File dialog box in order to chose a font file. */
147  if(GetOpenFileNameW(&fontOpen))
148  {
149  fileName = fontOpen.lpstrFile;
150  g_fileName = fileName;
151  } else {
152  /* If the user decides to close out of the open dialog effectively
153  exiting the program altogether */
154  return 0;
155  }
156  }
157  else
158  {
159  /* Try to add the font resource from command line */
160 // fileName = argv[1];
161  if (argc == 2)
162  {
163  fileName = argv[1];
164  }
165  else
166  {
167  /* Windows fontview supports the /p option, which displays print dialog */
168  fileName = argv[2];
169  if (wcscmp(argv[1], L"/p") == 0)
170  {
171  g_FontPrint = TRUE;
172  }
173  else
174  {
175  fileName = argv[1];
176  }
177  }
178  g_fileName = fileName;
179  }
180 
181  if (!AddFontResourceW(fileName))
182  {
183  ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
184  return -1;
185  }
186 
187  /* Get the font name */
188  dwSize = sizeof(g_LogFonts);
189  ZeroMemory(g_LogFonts, sizeof(g_LogFonts));
190  if (!GetFontResourceInfoW(fileName, &dwSize, g_LogFonts, 2))
191  {
192  ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
193  return -1;
194  }
195  g_NumFonts = 0;
196  for (i = 0; i < ARRAYSIZE(g_LogFonts); ++i)
197  {
198  if (g_LogFonts[i].lfFaceName[0] == 0)
199  break;
200 
201  ++g_NumFonts;
202  }
203  if (g_NumFonts == 0)
204  {
205  ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
206  return -1;
207  }
208 
209  /* get font title */
210  dwSize = sizeof(g_FontTitle);
212  GetFontResourceInfoW(fileName, &dwSize, g_FontTitle, 1);
213 
214  if (!Display_InitClass(hThisInstance))
215  {
217  return -1;
218  }
219 
220  /* The main window class */
221  wincl.cbSize = sizeof (WNDCLASSEXW);
222  wincl.style = CS_DBLCLKS;
223  wincl.lpfnWndProc = MainWndProc;
224  wincl.cbClsExtra = 0;
225  wincl.cbWndExtra = 0;
226  wincl.hInstance = hThisInstance;
228  wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
229  wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
230  wincl.lpszMenuName = NULL;
233 
234  /* Register the window class, and if it fails quit the program */
235  if (!RegisterClassExW (&wincl))
236  {
238  return 0;
239  }
240 
241  /* The class is registered, let's create the main window */
242  hMainWnd = CreateWindowExW(
243  0, /* Extended possibilities for variation */
244  g_szFontViewClassName, /* Classname */
245  g_FontTitle, /* Title Text */
246  WS_OVERLAPPEDWINDOW, /* default window */
247  CW_USEDEFAULT, /* Windows decides the position */
248  CW_USEDEFAULT, /* where the window ends up on the screen */
249  544, /* The programs width */
250  375, /* and height in pixels */
251  HWND_DESKTOP, /* The window is a child-window to desktop */
252  NULL, /* No menu */
253  hThisInstance, /* Program Instance handler */
254  NULL /* No Window Creation data */
255  );
256  ShowWindow(hMainWnd, nCmdShow);
257 
258  /* Main message loop */
259  while (GetMessage (&msg, NULL, 0, 0))
260  {
261  if (IsDialogMessage(hMainWnd, &msg))
262  continue;
263  TranslateMessage(&msg);
264  DispatchMessage(&msg);
265  }
266 
267  RemoveFontResourceW(argv[1]);
268 
269  return (int)msg.wParam;
270 }
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define OFN_EXPLORER
Definition: commdlg.h:104
static int argc
Definition: ServiceArgs.c:12
#define MAKEINTRESOURCE
Definition: winuser.h:591
DWORD Flags
Definition: commdlg.h:373
#define DispatchMessage
Definition: winuser.h:5631
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:561
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
LPCWSTR lpstrFilter
Definition: commdlg.h:363
int cbWndExtra
Definition: winuser.h:3173
#define LAYOUT_RTL
Definition: wingdi.h:1352
HINSTANCE g_hInstance
Definition: fontview.c:34
__wchar_t WCHAR
Definition: xmlstorage.h:180
INT g_NumFonts
Definition: fontview.c:36
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define SUBLANG_DEFAULT
Definition: nls.h:168
LPWSTR lpstrFile
Definition: commdlg.h:367
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
HICON hIcon
Definition: winuser.h:3175
#define IDS_ERROR_NOFONT
Definition: resource.h:5
BOOL g_FontPrint
Definition: fontview.c:40
struct _WNDCLASSEXW WNDCLASSEXW
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IsDialogMessage
Definition: winuser.h:5675
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
#define LANG_HEBREW
Definition: nls.h:67
#define IDS_OPEN
Definition: resource.h:12
static char ** argv
Definition: ServiceArgs.c:11
DWORD lStructSize
Definition: commdlg.h:360
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
int WINAPI AddFontResourceW(_In_ LPCWSTR pszFilename)
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LPCWSTR lpstrDefExt
Definition: commdlg.h:376
LPCWSTR lpszMenuName
Definition: winuser.h:3178
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2043
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4221
#define CW_USEDEFAULT
Definition: winuser.h:225
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:76
#define IDI_TT
Definition: resource.h:21
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR g_szFontViewClassName[]
Definition: fontview.c:42
int cbClsExtra
Definition: winuser.h:3172
LPCWSTR g_fileName
Definition: fontview.c:38
WCHAR g_FontTitle[1024]
Definition: fontview.c:39
LPCWSTR lpszClassName
Definition: winuser.h:3179
#define IDS_ERROR_NOCLASS
Definition: resource.h:6
#define IDS_FILTER_LIST
Definition: resource.h:7
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: fontview.c:561
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1686
LPCWSTR lpstrTitle
Definition: commdlg.h:372
HBRUSH hbrBackground
Definition: winuser.h:3177
UINT cbSize
Definition: winuser.h:3169
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD nMaxFile
Definition: commdlg.h:368
BOOL WINAPI RemoveFontResourceW(_In_ LPCWSTR)
HINSTANCE hInstance
Definition: winuser.h:3174
HWND hMainWnd
Definition: magnifier.c:33
HWND hwndOwner
Definition: commdlg.h:361
static const WCHAR L[]
Definition: oid.c:1087
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
LOGFONTW g_LogFonts[64]
Definition: fontview.c:37
static void ErrorMsgBox(HWND hParent, DWORD dwMessageId,...)
Definition: fontview.c:75
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
HCURSOR hCursor
Definition: winuser.h:3176
#define CS_DBLCLKS
Definition: winuser.h:646
UINT style
Definition: winuser.h:3170
#define LoadCursor
Definition: winuser.h:5678
WNDPROC lpfnWndProc
Definition: winuser.h:3171
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define GetModuleHandle
Definition: winbase.h:3641
#define HWND_DESKTOP
Definition: winuser.h:1195
#define GetMessage
Definition: winuser.h:5656
HICON hIconSm
Definition: winuser.h:3180
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
BOOL Display_InitClass(HINSTANCE hInstance)
Definition: display.c:55
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define MAKELANGID(p, s)
Definition: nls.h:15
#define COLOR_BACKGROUND
Definition: hardware.h:164
BOOL WINAPI GetFontResourceInfoW(LPCWSTR lpFileName, DWORD *pdwBufSize, void *lpBuffer, DWORD dwType)
#define LoadIcon
Definition: winuser.h:5679
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Variable Documentation

◆ g_fileName

LPCWSTR g_fileName

Definition at line 38 of file fontview.c.

Referenced by MainWnd_OnInstall(), and wWinMain().

◆ g_FontIndex

INT g_FontIndex = 0

Definition at line 35 of file fontview.c.

Referenced by MainWnd_OnCreate(), MainWnd_OnNext(), and MainWnd_OnPrev().

◆ g_FontPrint

BOOL g_FontPrint = FALSE

Definition at line 40 of file fontview.c.

Referenced by MainWnd_OnCreate(), and wWinMain().

◆ g_FontTitle

WCHAR g_FontTitle[1024] = L""

Definition at line 39 of file fontview.c.

Referenced by wWinMain().

◆ g_hInstance

HINSTANCE g_hInstance

Definition at line 34 of file fontview.c.

◆ g_LogFonts

LOGFONTW g_LogFonts[64]

Definition at line 37 of file fontview.c.

Referenced by wWinMain().

◆ g_NumFonts

INT g_NumFonts = 0

Definition at line 36 of file fontview.c.

Referenced by MainWnd_OnCreate(), MainWnd_OnNext(), and wWinMain().

◆ g_szFontViewClassName

const WCHAR g_szFontViewClassName[] = L"FontViewWClass"
static

Definition at line 42 of file fontview.c.

Referenced by wWinMain().