6 * Copyright (C) 2007 Timo Kreuzer <timo <dot> kreuzer <at> reactos <dot> org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 HINSTANCE g_hInstance
;
26 EXTLOGFONTW g_ExtLogFontW
;
28 static const WCHAR g_szFontViewClassName
[] = L
"FontViewWClass";
30 /* Tye definition for the GetFontResourceInfo function */
31 typedef BOOL (WINAPI
*PGFRI
)(LPCWSTR
, DWORD
*, LPVOID
, DWORD
);
48 len
= LoadStringW(hInstance
, dwStringId
, (LPWSTR
)Buffer
, 1000);
52 dwFlags
|= FORMAT_MESSAGE_FROM_STRING
;
53 dwFlags
&= ~(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_FROM_SYSTEM
);
54 dwRet
= FormatMessageW(dwFlags
, Buffer
, 0, dwLanguageId
, lpBuffer
, nSize
, Arguments
);
61 ErrorMsgBox(HWND hParent
, DWORD dwCaptionID
, DWORD dwMessageId
, ...)
64 HLOCAL hMemCaption
= NULL
;
65 HLOCAL hMemText
= NULL
;
68 hModule
= GetModuleHandle(NULL
);
70 va_start(args
, dwMessageId
);
71 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
72 NULL
, dwMessageId
, 0, (LPWSTR
)&hMemText
, 0, &args
);
75 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
76 NULL
, dwCaptionID
, 0, (LPWSTR
)&hMemCaption
, 0, NULL
);
78 MessageBoxW(hParent
, hMemText
, hMemCaption
, MB_ICONERROR
);
80 LocalFree(hMemCaption
);
85 WinMain (HINSTANCE hThisInstance
,
86 HINSTANCE hPrevInstance
,
97 PGFRI GetFontResourceInfoW
;
99 g_hInstance
= hThisInstance
;
101 /* Get unicode command line */
102 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
105 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_BADCMD
, argv
[1]);
109 /* Try to add the font resource */
110 if (!AddFontResourceW(argv
[1]))
112 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, argv
[1]);
116 /* Load the GetFontResourceInfo function from gdi32.dll */
117 hDLL
= LoadLibraryW(L
"GDI32.DLL");
118 GetFontResourceInfoW
= (PGFRI
)GetProcAddress(hDLL
, "GetFontResourceInfoW");
120 /* Get the font name */
121 dwSize
= sizeof(g_ExtLogFontW
.elfFullName
);
122 if (!GetFontResourceInfoW(argv
[1], &dwSize
, g_ExtLogFontW
.elfFullName
, 1))
124 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, argv
[1]);
128 dwSize
= sizeof(LOGFONTW
);
129 if (!GetFontResourceInfoW(argv
[1], &dwSize
, &g_ExtLogFontW
.elfLogFont
, 2))
131 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, argv
[1]);
135 if (!Display_InitClass(hThisInstance
))
137 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
141 /* The main window class */
142 wincl
.cbSize
= sizeof (WNDCLASSEXW
);
143 wincl
.style
= CS_DBLCLKS
;
144 wincl
.lpfnWndProc
= MainWndProc
;
145 wincl
.cbClsExtra
= 0;
146 wincl
.cbWndExtra
= 0;
147 wincl
.hInstance
= hThisInstance
;
148 wincl
.hIcon
= LoadIcon (NULL
, IDI_APPLICATION
);
149 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
150 wincl
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
151 wincl
.lpszMenuName
= NULL
;
152 wincl
.lpszClassName
= g_szFontViewClassName
;
153 wincl
.hIconSm
= LoadIcon (NULL
, IDI_APPLICATION
);
155 /* Register the window class, and if it fails quit the program */
156 if (!RegisterClassExW (&wincl
))
158 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
162 /* The class is registered, let's create the main window */
163 hMainWnd
= CreateWindowExW(
164 0, /* Extended possibilites for variation */
165 g_szFontViewClassName
, /* Classname */
166 g_ExtLogFontW
.elfFullName
,/* Title Text */
167 WS_OVERLAPPEDWINDOW
, /* default window */
168 CW_USEDEFAULT
, /* Windows decides the position */
169 CW_USEDEFAULT
, /* where the window ends up on the screen */
170 544, /* The programs width */
171 375, /* and height in pixels */
172 HWND_DESKTOP
, /* The window is a child-window to desktop */
174 hThisInstance
, /* Program Instance handler */
175 NULL
/* No Window Creation data */
177 ShowWindow(hMainWnd
, nCmdShow
);
179 /* Main message loop */
180 while (GetMessage (&msg
, NULL
, 0, 0))
182 TranslateMessage(&msg
);
183 DispatchMessage(&msg
);
186 RemoveFontResourceW(argv
[1]);
192 MainWnd_OnCreate(HWND hwnd
)
194 WCHAR szQuit
[MAX_BUTTONNAME
];
195 WCHAR szPrint
[MAX_BUTTONNAME
];
196 WCHAR szString
[MAX_STRING
];
197 HWND hDisplay
, hButtonQuit
, hButtonPrint
;
199 /* create the display window */
200 hDisplay
= CreateWindowExW(
201 0, /* Extended style */
202 g_szFontDisplayClassName
, /* Classname */
203 L
"", /* Title text */
204 WS_CHILD
| WS_VSCROLL
, /* Window style */
206 HEADER_SIZE
, /* Y-Pos */
208 370-HEADER_SIZE
, /* Height */
210 (HMENU
)IDC_DISPLAY
, /* Identifier */
211 g_hInstance
, /* Program Instance handler */
212 NULL
/* Window Creation data */
215 LoadStringW(g_hInstance
, IDS_STRING
, szString
, MAX_STRING
);
216 SendMessage(hDisplay
, FVM_SETSTRING
, 0, (LPARAM
)szString
);
218 /* Init the display window with the font name */
219 SendMessage(hDisplay
, FVM_SETTYPEFACE
, 0, (LPARAM
)&g_ExtLogFontW
);
220 ShowWindow(hDisplay
, SW_SHOWNORMAL
);
222 /* Create the quit button */
223 LoadStringW(g_hInstance
, IDS_QUIT
, szQuit
, MAX_BUTTONNAME
);
224 hButtonQuit
= CreateWindowExW(
225 0, /* Extended style */
226 L
"button", /* Classname */
227 szQuit
, /* Title text */
228 WS_CHILD
| WS_VISIBLE
, /* Window style */
229 BUTTON_POS_X
, /* X-pos */
230 BUTTON_POS_Y
, /* Y-Pos */
231 BUTTON_WIDTH
, /* Width */
232 BUTTON_HEIGHT
, /* Height */
234 (HMENU
)IDC_QUIT
, /* Identifier */
235 g_hInstance
, /* Program Instance handler */
236 NULL
/* Window Creation data */
238 SendMessage(hButtonQuit
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
240 /* Create the print button */
241 LoadStringW(g_hInstance
, IDS_PRINT
, szPrint
, MAX_BUTTONNAME
);
242 hButtonPrint
= CreateWindowExW(
243 0, /* Extended style */
244 L
"button", /* Classname */
245 szPrint
, /* Title text */
246 WS_CHILD
| WS_VISIBLE
, /* Window style */
248 BUTTON_POS_Y
, /* Y-Pos */
249 BUTTON_WIDTH
, /* Width */
250 BUTTON_HEIGHT
, /* Height */
252 (HMENU
)IDC_PRINT
, /* Identifier */
253 g_hInstance
, /* Program Instance handler */
254 NULL
/* Window Creation data */
256 SendMessage(hButtonPrint
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
262 MainWnd_OnSize(HWND hwnd
)
266 GetClientRect(hwnd
, &rc
);
267 MoveWindow(GetDlgItem(hwnd
, IDC_PRINT
), rc
.right
- BUTTON_WIDTH
- BUTTON_POS_X
, BUTTON_POS_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
, TRUE
);
268 MoveWindow(GetDlgItem(hwnd
, IDC_DISPLAY
), 0, HEADER_SIZE
, rc
.right
, rc
.bottom
- HEADER_SIZE
, TRUE
);
274 MainWnd_OnPaint(HWND hwnd
)
280 hDC
= BeginPaint(hwnd
, &ps
);
281 GetClientRect(hwnd
, &rc
);
282 rc
.top
= HEADER_SIZE
- 2;
283 rc
.bottom
= HEADER_SIZE
;
284 FillRect(hDC
, &rc
, GetStockObject(GRAY_BRUSH
));
290 MainWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
295 return MainWnd_OnCreate(hwnd
);
298 return MainWnd_OnPaint(hwnd
);
301 return MainWnd_OnSize(hwnd
);
304 switch(LOWORD(wParam
))
307 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
311 MessageBox(hwnd
, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK
);
317 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
320 default: /* for messages that we don't deal with */
321 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);