mirror of
https://github.com/reactos/reactos.git
synced 2024-10-30 19:41:57 +00:00
b20ceda590
svn path=/trunk/; revision=36346
328 lines
8.8 KiB
C
328 lines
8.8 KiB
C
/*
|
|
* fontview
|
|
*
|
|
* fontview.c
|
|
*
|
|
* Copyright (C) 2007 Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include "fontview.h"
|
|
|
|
HINSTANCE g_hInstance;
|
|
EXTLOGFONTW g_ExtLogFontW;
|
|
|
|
static const WCHAR g_szFontViewClassName[] = L"FontViewWClass";
|
|
|
|
/* Tye definition for the GetFontResourceInfo function */
|
|
typedef BOOL (WINAPI *PGFRI)(LPCWSTR, DWORD *, LPVOID, DWORD);
|
|
|
|
DWORD
|
|
FormatString(
|
|
DWORD dwFlags,
|
|
HINSTANCE hInstance,
|
|
DWORD dwStringId,
|
|
DWORD dwLanguageId,
|
|
LPWSTR lpBuffer,
|
|
DWORD nSize,
|
|
va_list* Arguments
|
|
)
|
|
{
|
|
DWORD dwRet;
|
|
int len;
|
|
WCHAR Buffer[1000];
|
|
|
|
len = LoadStringW(hInstance, dwStringId, (LPWSTR)Buffer, 1000);
|
|
|
|
if (len)
|
|
{
|
|
dwFlags |= FORMAT_MESSAGE_FROM_STRING;
|
|
dwFlags &= ~(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM);
|
|
dwRet = FormatMessageW(dwFlags, Buffer, 0, dwLanguageId, lpBuffer, nSize, Arguments);
|
|
return dwRet;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
ErrorMsgBox(HWND hParent, DWORD dwCaptionID, DWORD dwMessageId, ...)
|
|
{
|
|
HMODULE hModule;
|
|
HLOCAL hMemCaption = NULL;
|
|
HLOCAL hMemText = NULL;
|
|
va_list args;
|
|
|
|
hModule = GetModuleHandle(NULL);
|
|
|
|
va_start(args, dwMessageId);
|
|
FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
|
NULL, dwMessageId, 0, (LPWSTR)&hMemText, 0, &args);
|
|
va_end(args);
|
|
|
|
FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
|
NULL, dwCaptionID, 0, (LPWSTR)&hMemCaption, 0, NULL);
|
|
|
|
MessageBoxW(hParent, hMemText, hMemCaption, MB_ICONERROR);
|
|
|
|
LocalFree(hMemCaption);
|
|
LocalFree(hMemText);
|
|
}
|
|
|
|
int WINAPI
|
|
WinMain (HINSTANCE hThisInstance,
|
|
HINSTANCE hPrevInstance,
|
|
LPSTR lpCmdLine,
|
|
int nCmdShow)
|
|
{
|
|
int argc;
|
|
WCHAR** argv;
|
|
DWORD dwSize;
|
|
HWND hMainWnd;
|
|
MSG msg;
|
|
WNDCLASSEXW wincl;
|
|
HINSTANCE hDLL;
|
|
PGFRI GetFontResourceInfoW;
|
|
|
|
g_hInstance = hThisInstance;
|
|
|
|
/* Get unicode command line */
|
|
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
if (argc < 2)
|
|
{
|
|
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_BADCMD, argv[1]);
|
|
return -1;
|
|
}
|
|
|
|
/* Try to add the font resource */
|
|
if (!AddFontResourceW(argv[1]))
|
|
{
|
|
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]);
|
|
return -1;
|
|
}
|
|
|
|
/* Load the GetFontResourceInfo function from gdi32.dll */
|
|
hDLL = LoadLibraryW(L"GDI32.DLL");
|
|
GetFontResourceInfoW = (PGFRI)GetProcAddress(hDLL, "GetFontResourceInfoW");
|
|
|
|
/* Get the font name */
|
|
dwSize = sizeof(g_ExtLogFontW.elfFullName);
|
|
if (!GetFontResourceInfoW(argv[1], &dwSize, g_ExtLogFontW.elfFullName, 1))
|
|
{
|
|
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]);
|
|
return -1;
|
|
}
|
|
|
|
dwSize = sizeof(LOGFONTW);
|
|
if (!GetFontResourceInfoW(argv[1], &dwSize, &g_ExtLogFontW.elfLogFont, 2))
|
|
{
|
|
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, argv[1]);
|
|
return -1;
|
|
}
|
|
|
|
if (!Display_InitClass(hThisInstance))
|
|
{
|
|
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOCLASS);
|
|
return -1;
|
|
}
|
|
|
|
/* The main window class */
|
|
wincl.cbSize = sizeof (WNDCLASSEXW);
|
|
wincl.style = CS_DBLCLKS;
|
|
wincl.lpfnWndProc = MainWndProc;
|
|
wincl.cbClsExtra = 0;
|
|
wincl.cbWndExtra = 0;
|
|
wincl.hInstance = hThisInstance;
|
|
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
|
|
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
|
|
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
|
|
wincl.lpszMenuName = NULL;
|
|
wincl.lpszClassName = g_szFontViewClassName;
|
|
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
|
|
|
|
/* Register the window class, and if it fails quit the program */
|
|
if (!RegisterClassExW (&wincl))
|
|
{
|
|
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOCLASS);
|
|
return 0;
|
|
}
|
|
|
|
/* The class is registered, let's create the main window */
|
|
hMainWnd = CreateWindowExW(
|
|
0, /* Extended possibilites for variation */
|
|
g_szFontViewClassName, /* Classname */
|
|
g_ExtLogFontW.elfFullName,/* Title Text */
|
|
WS_OVERLAPPEDWINDOW, /* default window */
|
|
CW_USEDEFAULT, /* Windows decides the position */
|
|
CW_USEDEFAULT, /* where the window ends up on the screen */
|
|
544, /* The programs width */
|
|
375, /* and height in pixels */
|
|
HWND_DESKTOP, /* The window is a child-window to desktop */
|
|
NULL, /* No menu */
|
|
hThisInstance, /* Program Instance handler */
|
|
NULL /* No Window Creation data */
|
|
);
|
|
ShowWindow(hMainWnd, nCmdShow);
|
|
|
|
/* Main message loop */
|
|
while (GetMessage (&msg, NULL, 0, 0))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
|
|
RemoveFontResourceW(argv[1]);
|
|
|
|
return msg.wParam;
|
|
}
|
|
|
|
static LRESULT
|
|
MainWnd_OnCreate(HWND hwnd)
|
|
{
|
|
WCHAR szQuit[MAX_BUTTONNAME];
|
|
WCHAR szPrint[MAX_BUTTONNAME];
|
|
WCHAR szString[MAX_STRING];
|
|
HWND hDisplay, hButtonQuit, hButtonPrint;
|
|
|
|
/* create the display window */
|
|
hDisplay = CreateWindowExW(
|
|
0, /* Extended style */
|
|
g_szFontDisplayClassName, /* Classname */
|
|
L"", /* Title text */
|
|
WS_CHILD | WS_VSCROLL, /* Window style */
|
|
0, /* X-pos */
|
|
HEADER_SIZE, /* Y-Pos */
|
|
550, /* Width */
|
|
370-HEADER_SIZE, /* Height */
|
|
hwnd, /* Parent */
|
|
(HMENU)IDC_DISPLAY, /* Identifier */
|
|
g_hInstance, /* Program Instance handler */
|
|
NULL /* Window Creation data */
|
|
);
|
|
|
|
LoadStringW(g_hInstance, IDS_STRING, szString, MAX_STRING);
|
|
SendMessage(hDisplay, FVM_SETSTRING, 0, (LPARAM)szString);
|
|
|
|
/* Init the display window with the font name */
|
|
SendMessage(hDisplay, FVM_SETTYPEFACE, 0, (LPARAM)&g_ExtLogFontW);
|
|
ShowWindow(hDisplay, SW_SHOWNORMAL);
|
|
|
|
/* Create the quit button */
|
|
LoadStringW(g_hInstance, IDS_QUIT, szQuit, MAX_BUTTONNAME);
|
|
hButtonQuit = CreateWindowExW(
|
|
0, /* Extended style */
|
|
L"button", /* Classname */
|
|
szQuit, /* Title text */
|
|
WS_CHILD | WS_VISIBLE, /* Window style */
|
|
BUTTON_POS_X, /* X-pos */
|
|
BUTTON_POS_Y, /* Y-Pos */
|
|
BUTTON_WIDTH, /* Width */
|
|
BUTTON_HEIGHT, /* Height */
|
|
hwnd, /* Parent */
|
|
(HMENU)IDC_QUIT, /* Identifier */
|
|
g_hInstance, /* Program Instance handler */
|
|
NULL /* Window Creation data */
|
|
);
|
|
SendMessage(hButtonQuit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
|
|
|
|
/* Create the print button */
|
|
LoadStringW(g_hInstance, IDS_PRINT, szPrint, MAX_BUTTONNAME);
|
|
hButtonPrint = CreateWindowExW(
|
|
0, /* Extended style */
|
|
L"button", /* Classname */
|
|
szPrint, /* Title text */
|
|
WS_CHILD | WS_VISIBLE, /* Window style */
|
|
450, /* X-pos */
|
|
BUTTON_POS_Y, /* Y-Pos */
|
|
BUTTON_WIDTH, /* Width */
|
|
BUTTON_HEIGHT, /* Height */
|
|
hwnd, /* Parent */
|
|
(HMENU)IDC_PRINT, /* Identifier */
|
|
g_hInstance, /* Program Instance handler */
|
|
NULL /* Window Creation data */
|
|
);
|
|
SendMessage(hButtonPrint, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static LRESULT
|
|
MainWnd_OnSize(HWND hwnd)
|
|
{
|
|
RECT rc;
|
|
|
|
GetClientRect(hwnd, &rc);
|
|
MoveWindow(GetDlgItem(hwnd, IDC_PRINT), rc.right - BUTTON_WIDTH - BUTTON_POS_X, BUTTON_POS_Y, BUTTON_WIDTH, BUTTON_HEIGHT, TRUE);
|
|
MoveWindow(GetDlgItem(hwnd, IDC_DISPLAY), 0, HEADER_SIZE, rc.right, rc.bottom - HEADER_SIZE, TRUE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static LRESULT
|
|
MainWnd_OnPaint(HWND hwnd)
|
|
{
|
|
HDC hDC;
|
|
PAINTSTRUCT ps;
|
|
RECT rc;
|
|
|
|
hDC = BeginPaint(hwnd, &ps);
|
|
GetClientRect(hwnd, &rc);
|
|
rc.top = HEADER_SIZE - 2;
|
|
rc.bottom = HEADER_SIZE;
|
|
FillRect(hDC, &rc, GetStockObject(GRAY_BRUSH));
|
|
EndPaint(hwnd, &ps);
|
|
return 0;
|
|
}
|
|
|
|
LRESULT CALLBACK
|
|
MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
switch (message)
|
|
{
|
|
case WM_CREATE:
|
|
return MainWnd_OnCreate(hwnd);
|
|
|
|
case WM_PAINT:
|
|
return MainWnd_OnPaint(hwnd);
|
|
|
|
case WM_SIZE:
|
|
return MainWnd_OnSize(hwnd);
|
|
|
|
case WM_COMMAND:
|
|
switch(LOWORD(wParam))
|
|
{
|
|
case IDC_QUIT:
|
|
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
|
|
break;
|
|
|
|
case IDC_PRINT:
|
|
MessageBox(hwnd, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK);
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
|
|
break;
|
|
|
|
default: /* for messages that we don't deal with */
|
|
return DefWindowProcW(hwnd, message, wParam, lParam);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* EOF */
|