ReactOS  0.4.14-dev-606-g14ebc0b
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
 
BOOL g_DisableInstall = FALSE
 
static const WCHAR g_szFontViewClassName [] = L"FontViewWClass"
 

Function Documentation

◆ ErrorMsgBox()

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

Definition at line 76 of file fontview.c.

77 {
78  HLOCAL hMemCaption = NULL;
79  HLOCAL hMemText = NULL;
80  va_list args;
81 
82  va_start(args, dwMessageId);
84  NULL, dwMessageId, 0, (LPWSTR)&hMemText, 0, &args);
85  va_end(args);
86 
88  NULL, IDS_ERROR, 0, (LPWSTR)&hMemCaption, 0, NULL);
89 
90  MessageBoxW(hParent, hMemText, hMemCaption, MB_ICONERROR);
91 
92  LocalFree(hMemCaption);
93  LocalFree(hMemText);
94 }
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:49
Definition: match.c:390
#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
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
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

Referenced by MainWnd_OnInstall(), and wWinMain().

◆ FormatString()

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

Definition at line 49 of file fontview.c.

58 {
59  DWORD dwRet;
60  int len;
61  WCHAR Buffer[1000];
62 
63  len = LoadStringW(hInstance, dwStringId, (LPWSTR)Buffer, 1000);
64 
65  if (len)
66  {
69  dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments);
70  return dwRet;
71  }
72  return 0;
73 }
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
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)
HINSTANCE hInstance
Definition: charmap.c:20
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
Definition: bufpool.h:45
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
__wchar_t WCHAR
Definition: xmlstorage.h:180
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

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

◆ 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 285 of file fontview.c.

286 {
287  WCHAR szQuit[MAX_BUTTONNAME];
288  WCHAR szPrint[MAX_BUTTONNAME];
289  WCHAR szString[MAX_STRING];
290  WCHAR szPrevious[MAX_STRING];
291  WCHAR szNext[MAX_STRING];
292  HWND hDisplay, hButtonInstall, hButtonPrint, hButtonPrev, hButtonNext;
293 
294  /* create the display window */
295  hDisplay = CreateWindowExW(
296  0, /* Extended style */
297  g_szFontDisplayClassName, /* Classname */
298  L"", /* Title text */
299  WS_CHILD | WS_VSCROLL, /* Window style */
300  0, /* X-pos */
301  HEADER_SIZE, /* Y-Pos */
302  550, /* Width */
303  370-HEADER_SIZE, /* Height */
304  hwnd, /* Parent */
305  (HMENU)IDC_DISPLAY, /* Identifier */
306  g_hInstance, /* Program Instance handler */
307  NULL /* Window Creation data */
308  );
309 
311  SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
312 
313  /* Create the install button */
315  hButtonInstall = CreateWindowExW(
316  0, /* Extended style */
317  L"button", /* Classname */
318  szQuit, /* Title text */
319  WS_CHILD | WS_VISIBLE, /* Window style */
320  BUTTON_POS_X, /* X-pos */
321  BUTTON_POS_Y, /* Y-Pos */
322  BUTTON_WIDTH, /* Width */
323  BUTTON_HEIGHT, /* Height */
324  hwnd, /* Parent */
325  (HMENU)IDC_INSTALL, /* Identifier */
326  g_hInstance, /* Program Instance handler */
327  NULL /* Window Creation data */
328  );
330  EnableWindow(hButtonInstall, !g_DisableInstall);
331 
332  /* Create the print button */
334  hButtonPrint = CreateWindowExW(
335  0, /* Extended style */
336  L"button", /* Classname */
337  szPrint, /* Title text */
338  WS_CHILD | WS_VISIBLE, /* Window style */
339  450, /* X-pos */
340  BUTTON_POS_Y, /* Y-Pos */
341  BUTTON_WIDTH, /* Width */
342  BUTTON_HEIGHT, /* Height */
343  hwnd, /* Parent */
344  (HMENU)IDC_PRINT, /* Identifier */
345  g_hInstance, /* Program Instance handler */
346  NULL /* Window Creation data */
347  );
349 
350  /* Create the previous button */
352  hButtonPrev = CreateWindowExW(
353  0, /* Extended style */
354  L"button", /* Classname */
355  szPrevious, /* Title text */
356  WS_CHILD | WS_VISIBLE, /* Window style */
357  450, /* X-pos */
358  BUTTON_POS_Y, /* Y-Pos */
359  BUTTON_WIDTH, /* Width */
360  BUTTON_HEIGHT, /* Height */
361  hwnd, /* Parent */
362  (HMENU)IDC_PREV, /* Identifier */
363  g_hInstance, /* Program Instance handler */
364  NULL /* Window Creation data */
365  );
367 
368  /* Create the next button */
370  hButtonNext = CreateWindowExW(
371  0, /* Extended style */
372  L"button", /* Classname */
373  szNext, /* Title text */
374  WS_CHILD | WS_VISIBLE, /* Window style */
375  450, /* X-pos */
376  BUTTON_POS_Y, /* Y-Pos */
377  BUTTON_WIDTH, /* Width */
378  BUTTON_HEIGHT, /* Height */
379  hwnd, /* Parent */
380  (HMENU)IDC_NEXT, /* Identifier */
381  g_hInstance, /* Program Instance handler */
382  NULL /* Window Creation data */
383  );
385 
386  EnableWindow(hButtonPrev, FALSE);
387  if (g_NumFonts <= 1)
388  EnableWindow(hButtonNext, FALSE);
389 
390  /* Init the display window with the font name */
391  g_FontIndex = 0;
393  ShowWindow(hDisplay, SW_SHOWNORMAL);
394 
395  if (g_FontPrint)
397 
398  return 0;
399 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BUTTON_WIDTH
Definition: fontview.h:9
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
HINSTANCE g_hInstance
Definition: fontview.c:34
INT g_NumFonts
Definition: fontview.c:36
#define IDS_STRING
Definition: resource.h:11
#define IDC_NEXT
Definition: fontview.h:17
UINT_PTR WPARAM
Definition: windef.h:207
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)
BOOL g_DisableInstall
Definition: fontview.c:41
#define IDS_INSTALL
Definition: resource.h:9
#define IDS_NEXT
Definition: resource.h:13
#define BUTTON_POS_Y
Definition: fontview.h:8
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define FVM_SETTYPEFACE
Definition: display.h:4
#define PostMessage
Definition: winuser.h:5807
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDC_PREV
Definition: fontview.h:16
#define DEFAULT_GUI_FONT
Definition: wingdi.h:908
static const WCHAR L[]
Definition: oid.c:1250
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:1722
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:5818
#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

Referenced by MainWndProc().

◆ MainWnd_OnInstall()

static LRESULT MainWnd_OnInstall ( HWND  hwnd)
static

Definition at line 456 of file fontview.c.

457 {
458  WCHAR szFullName[64];
459 
460  WCHAR szSrcPath[MAX_PATH];
461  WCHAR szDestPath[MAX_PATH];
463  LONG res;
464  HKEY hKey;
465 
467 // MessageBoxW(hwnd, szFullName, L"Debug", MB_OK);
468 
469  /* First, we have to find out if the font still exists */
471  {
472  /* Fail, if the source file does not exist */
474  return -1;
475  }
476 
477  /* Build the full destination file name */
479 
480  GetWindowsDirectoryW(szDestPath, MAX_PATH);
481  wcscat(szDestPath, L"\\Fonts\\");
482  wcscat(szDestPath, pszFileName);
483 
484  /* Debug Message */
485 // MessageBoxW(hwnd, szDestPath, L"szDestPath", MB_OK);
486 // MessageBoxW(hwnd, pszFileName, L"pszFileExt", MB_OK);
487 
488  /* Check if the file already exists */
489  if (GetFileAttributesW(szDestPath) != INVALID_FILE_ATTRIBUTES)
490  {
491  MessageBoxW(hwnd, L"This font is already installed!", L"Already Installed", MB_OK);
492  return 0;
493  }
494 
495  /* Copy the font file */
496  if (!CopyFileW(g_fileName, szDestPath, TRUE))
497  {
498  MessageBoxW(hwnd,L"Failed to copy the font file!", L"File Error", MB_OK);
499  return -1;
500  }
501 
502  /* Open the fonts key */
504  L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
505  0,
507  &hKey);
508  if (res != ERROR_SUCCESS)
509  {
510  MessageBoxW(hwnd, L"Failed top open the fonts key!", L"Debug1", MB_OK);
511  return -1;
512  }
513 
514  /* Register the font */
515  res = RegSetValueExW(hKey,
516  szFullName,
517  0,
518  REG_SZ,
520  (wcslen(pszFileName) + 1) * sizeof(WCHAR));
521  if (res != ERROR_SUCCESS)
522  {
523  MessageBoxW(hwnd, L"Failed to register the new font!", L"Debug2", MB_OK);
524  RegCloseKey(hKey);
525  return -1;
526  }
527 
528  /* Close the fonts key */
529  RegCloseKey(hKey);
530 
531  /* Broadcast WM_FONTCHANGE message */
533 
534  /* if all of this goes correctly, message the user about success */
535  MessageBoxW(hwnd, L"Font Installation Completed.", L"Success", MB_OK);
536 
537  return 0;
538 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
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:5817
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
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
LONG_PTR LPARAM
Definition: windef.h:208
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:4895
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
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
#define WM_FONTCHANGE
Definition: winuser.h:1615
static const WCHAR L[]
Definition: oid.c:1250
#define IDC_DISPLAY
Definition: resource.h:19
static void ErrorMsgBox(HWND hParent, DWORD dwMessageId,...)
Definition: fontview.c:76
#define GetFileAttributes
Definition: winbase.h:3649
#define FVM_GETFULLNAME
Definition: display.h:6
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
_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:3366
#define HWND_BROADCAST
Definition: winuser.h:1190
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

Referenced by MainWndProc().

◆ MainWnd_OnNext()

static LRESULT MainWnd_OnNext ( HWND  hwnd)
static

Definition at line 559 of file fontview.c.

560 {
561  HWND hDisplay;
562  if (g_FontIndex + 1 < g_NumFonts)
563  {
564  ++g_FontIndex;
566  if (g_FontIndex == g_NumFonts - 1)
568 
569  hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
571  InvalidateRect(hDisplay, NULL, TRUE);
572  }
573  return 0;
574 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
INT g_NumFonts
Definition: fontview.c:36
#define IDC_NEXT
Definition: fontview.h:17
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#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:5818
INT g_FontIndex
Definition: fontview.c:35

Referenced by MainWndProc().

◆ MainWnd_OnPaint()

static LRESULT MainWnd_OnPaint ( HWND  hwnd)
static

Definition at line 440 of file fontview.c.

441 {
442  HDC hDC;
443  PAINTSTRUCT ps;
444  RECT rc;
445 
446  hDC = BeginPaint(hwnd, &ps);
447  GetClientRect(hwnd, &rc);
448  rc.top = HEADER_SIZE - 2;
449  rc.bottom = HEADER_SIZE;
451  EndPaint(hwnd, &ps);
452  return 0;
453 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
static HDC
Definition: imagelist.c:92
LONG top
Definition: windef.h:307
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define GRAY_BRUSH
Definition: wingdi.h:897
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:309
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)

Referenced by MainWndProc().

◆ MainWnd_OnPrev()

static LRESULT MainWnd_OnPrev ( HWND  hwnd)
static

Definition at line 541 of file fontview.c.

542 {
543  HWND hDisplay;
544  if (g_FontIndex > 0)
545  {
546  --g_FontIndex;
548  if (g_FontIndex == 0)
550 
551  hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
553  InvalidateRect(hDisplay, NULL, TRUE);
554  }
555  return 0;
556 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
#define IDC_NEXT
Definition: fontview.h:17
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#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:5818
INT g_FontIndex
Definition: fontview.c:35

Referenced by MainWndProc().

◆ MainWnd_OnSize()

static LRESULT MainWnd_OnSize ( HWND  hwnd)
static

Definition at line 402 of file fontview.c.

403 {
404  RECT rc;
405  HWND hInstall, hPrint, hPrev, hNext, hDisplay;
406  HDWP hDWP;
407 
408  GetClientRect(hwnd, &rc);
409 
410  hDWP = BeginDeferWindowPos(5);
411 
412  hInstall = GetDlgItem(hwnd, IDC_INSTALL);
413  if (hDWP)
415 
416  hPrint = GetDlgItem(hwnd, IDC_PRINT);
417  if (hDWP)
419 
420  hPrev = GetDlgItem(hwnd, IDC_PREV);
421  if (hDWP)
423 
424  hNext = GetDlgItem(hwnd, IDC_NEXT);
425  if (hDWP)
427 
428  hDisplay = GetDlgItem(hwnd, IDC_DISPLAY);
429  if (hDWP)
430  hDWP = DeferWindowPos(hDWP, hDisplay, NULL, 0, HEADER_SIZE, rc.right, rc.bottom - HEADER_SIZE, SWP_NOZORDER);
431 
432  EndDeferWindowPos(hDWP);
433 
435 
436  return 0;
437 }
#define BUTTON_WIDTH
Definition: fontview.h:9
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
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:308
#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:309
#define IDC_INSTALL
Definition: fontview.h:13
#define IDC_PRINT
Definition: fontview.h:14
#define BUTTON_PADDING
Definition: fontview.h:11

Referenced by MainWndProc().

◆ MainWndProc()

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

Definition at line 577 of file fontview.c.

578 {
579  switch (message)
580  {
581  case WM_CREATE:
582  return MainWnd_OnCreate(hwnd);
583 
584  case WM_PAINT:
585  return MainWnd_OnPaint(hwnd);
586 
587  case WM_SIZE:
588  return MainWnd_OnSize(hwnd);
589 
590  case WM_COMMAND:
591  switch(LOWORD(wParam))
592  {
593  case IDC_INSTALL:
594  return MainWnd_OnInstall(hwnd);
595 
596  case IDC_PRINT:
597  return Display_OnPrint(hwnd);
598 
599  case IDC_PREV:
600  return MainWnd_OnPrev(hwnd);
601 
602  case IDC_NEXT:
603  return MainWnd_OnNext(hwnd);
604  }
605  break;
606 
607  case WM_DESTROY:
608  PostQuitMessage (0); /* send a WM_QUIT to the message queue */
609  break;
610 
611  default: /* for messages that we don't deal with */
613  }
614 
615  return 0;
616 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
Definition: tftpd.h:59
static LRESULT MainWnd_OnSize(HWND hwnd)
Definition: fontview.c:402
#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:440
static LRESULT MainWnd_OnInstall(HWND hwnd)
Definition: fontview.c:456
#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:559
static LRESULT MainWnd_OnCreate(HWND hwnd)
Definition: fontview.c:285
#define WM_COMMAND
Definition: winuser.h:1722
static LRESULT MainWnd_OnPrev(HWND hwnd)
Definition: fontview.c:541
#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)

Referenced by wWinMain().

◆ 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 97 of file fontview.c.

101 {
102  int argc;
103  INT i;
104  WCHAR** argv;
105  WCHAR szFileName[MAX_PATH] = L"";
106  DWORD dwSize;
107  HWND hMainWnd;
108  MSG msg;
109  WNDCLASSEXW wincl;
110  LPCWSTR fileName;
111 
112  switch (GetUserDefaultUILanguage())
113  {
116  break;
117 
118  default:
119  break;
120  }
121 
122  g_hInstance = hThisInstance;
123 
124  /* Get unicode command line */
126  if (argc < 2)
127  {
128  OPENFILENAMEW fontOpen;
129  WCHAR filter[MAX_PATH*2], dialogTitle[MAX_PATH];
130 
131  LoadStringW(NULL, IDS_OPEN, dialogTitle, ARRAYSIZE(dialogTitle));
133 
134  /* Clears out any values of fontOpen before we use it */
135  ZeroMemory(&fontOpen, sizeof(fontOpen));
136 
137  /* Sets up the open dialog box */
138  fontOpen.lStructSize = sizeof(fontOpen);
139  fontOpen.hwndOwner = NULL;
140  fontOpen.lpstrFilter = filter;
141  fontOpen.lpstrFile = szFileName;
142  fontOpen.lpstrTitle = dialogTitle;
143  fontOpen.nMaxFile = MAX_PATH;
145  fontOpen.lpstrDefExt = L"ttf";
146 
147  /* Opens up the Open File dialog box in order to chose a font file. */
148  if(GetOpenFileNameW(&fontOpen))
149  {
150  fileName = fontOpen.lpstrFile;
151  g_fileName = fileName;
152  } else {
153  /* If the user decides to close out of the open dialog effectively
154  exiting the program altogether */
155  return 0;
156  }
157  }
158  else
159  {
160  /* Try to add the font resource from command line */
161  for (i = 1; i < argc; ++i)
162  {
163  // Treat the last argument as filename
164  if (i + 1 == argc)
165  {
166  fileName = argv[i];
167  }
168  else if (argv[i][0] == '/' || argv[i][0] == '-')
169  {
170  switch (argv[i][1])
171  {
172  case 'p':
173  case 'P':
174  g_FontPrint = TRUE;
175  break;
176  case 'd':
177  case 'D':
179  break;
180  default:
181  fileName = argv[i];
182  break;
183  }
184  }
185  else
186  {
187  fileName = argv[i];
188  }
189  }
190  g_fileName = fileName;
191  }
192 
193  if (!AddFontResourceW(fileName))
194  {
195  ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
196  return -1;
197  }
198 
199  /* Get the font name */
200  dwSize = sizeof(g_LogFonts);
201  ZeroMemory(g_LogFonts, sizeof(g_LogFonts));
202  if (!GetFontResourceInfoW(fileName, &dwSize, g_LogFonts, 2))
203  {
204  ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
205  return -1;
206  }
207  g_NumFonts = 0;
208  for (i = 0; i < ARRAYSIZE(g_LogFonts); ++i)
209  {
210  if (g_LogFonts[i].lfFaceName[0] == 0)
211  break;
212 
213  ++g_NumFonts;
214  }
215  if (g_NumFonts == 0)
216  {
217  ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
218  return -1;
219  }
220 
221  /* get font title */
222  dwSize = sizeof(g_FontTitle);
224  GetFontResourceInfoW(fileName, &dwSize, g_FontTitle, 1);
225 
226  if (!Display_InitClass(hThisInstance))
227  {
229  return -1;
230  }
231 
232  /* The main window class */
233  wincl.cbSize = sizeof (WNDCLASSEXW);
234  wincl.style = CS_DBLCLKS;
235  wincl.lpfnWndProc = MainWndProc;
236  wincl.cbClsExtra = 0;
237  wincl.cbWndExtra = 0;
238  wincl.hInstance = hThisInstance;
240  wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
241  wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
242  wincl.lpszMenuName = NULL;
245 
246  /* Register the window class, and if it fails quit the program */
247  if (!RegisterClassExW (&wincl))
248  {
250  return 0;
251  }
252 
253  /* The class is registered, let's create the main window */
255  0, /* Extended possibilities for variation */
256  g_szFontViewClassName, /* Classname */
257  g_FontTitle, /* Title Text */
258  WS_OVERLAPPEDWINDOW, /* default window */
259  CW_USEDEFAULT, /* Windows decides the position */
260  CW_USEDEFAULT, /* where the window ends up on the screen */
261  544, /* The programs width */
262  375, /* and height in pixels */
263  HWND_DESKTOP, /* The window is a child-window to desktop */
264  NULL, /* No menu */
265  hThisInstance, /* Program Instance handler */
266  NULL /* No Window Creation data */
267  );
268  ShowWindow(hMainWnd, nCmdShow);
269 
270  /* Main message loop */
271  while (GetMessage (&msg, NULL, 0, 0))
272  {
274  continue;
277  }
278 
280 
281  return (int)msg.wParam;
282 }
#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:5740
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:806
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define TRUE
Definition: types.h:120
LPCWSTR lpstrFilter
Definition: commdlg.h:363
int cbWndExtra
Definition: winuser.h:3195
#define LAYOUT_RTL
Definition: wingdi.h:1370
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
HINSTANCE g_hInstance
Definition: fontview.c:34
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
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1642
HICON hIcon
Definition: winuser.h:3197
#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:5784
#define argv
Definition: mplay32.c:18
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
DWORD lStructSize
Definition: commdlg.h:360
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
int WINAPI AddFontResourceW(_In_ LPCWSTR pszFilename)
BOOL g_DisableInstall
Definition: fontview.c:41
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LPCWSTR lpstrDefExt
Definition: commdlg.h:376
LPCWSTR lpszMenuName
Definition: winuser.h:3200
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4565
#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:43
int cbClsExtra
Definition: winuser.h:3194
LPCWSTR g_fileName
Definition: fontview.c:38
WCHAR g_FontTitle[1024]
Definition: fontview.c:39
LPCWSTR lpszClassName
Definition: winuser.h:3201
#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:577
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1716
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPCWSTR lpstrTitle
Definition: commdlg.h:372
HBRUSH hbrBackground
Definition: winuser.h:3199
UINT cbSize
Definition: winuser.h:3191
#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:3196
HWND hMainWnd
Definition: magnifier.c:32
HWND hwndOwner
Definition: commdlg.h:361
static const WCHAR L[]
Definition: oid.c:1250
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:76
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
HCURSOR hCursor
Definition: winuser.h:3198
#define CS_DBLCLKS
Definition: winuser.h:646
UINT style
Definition: winuser.h:3192
#define LoadCursor
Definition: winuser.h:5787
WNDPROC lpfnWndProc
Definition: winuser.h:3193
#define GetModuleHandle
Definition: winbase.h:3661
#define HWND_DESKTOP
Definition: winuser.h:1195
#define GetMessage
Definition: winuser.h:5765
HICON hIconSm
Definition: winuser.h:3202
#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:5788
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_DisableInstall

BOOL g_DisableInstall = FALSE

Definition at line 41 of file fontview.c.

Referenced by MainWnd_OnCreate(), and wWinMain().

◆ 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.

Referenced by MainWnd_OnCreate(), and wWinMain().

◆ g_LogFonts

LOGFONTW g_LogFonts[64]

Definition at line 37 of file fontview.c.

Referenced by MainWnd_OnCreate(), MainWnd_OnNext(), MainWnd_OnPrev(), and 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 43 of file fontview.c.

Referenced by wWinMain().