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
, ...)
63 HLOCAL hMemCaption
= NULL
;
64 HLOCAL hMemText
= NULL
;
67 va_start(args
, dwMessageId
);
68 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
69 NULL
, dwMessageId
, 0, (LPWSTR
)&hMemText
, 0, &args
);
72 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
73 NULL
, dwCaptionID
, 0, (LPWSTR
)&hMemCaption
, 0, NULL
);
75 MessageBoxW(hParent
, hMemText
, hMemCaption
, MB_ICONERROR
);
77 LocalFree(hMemCaption
);
82 WinMain (HINSTANCE hThisInstance
,
83 HINSTANCE hPrevInstance
,
94 PGFRI GetFontResourceInfoW
;
96 g_hInstance
= hThisInstance
;
98 /* Get unicode command line */
99 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
102 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_BADCMD
, argv
[1]);
106 /* Try to add the font resource */
107 if (!AddFontResourceW(argv
[1]))
109 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, argv
[1]);
113 /* Load the GetFontResourceInfo function from gdi32.dll */
114 hDLL
= LoadLibraryW(L
"GDI32.DLL");
115 GetFontResourceInfoW
= (PGFRI
)GetProcAddress(hDLL
, "GetFontResourceInfoW");
117 /* Get the font name */
118 dwSize
= sizeof(g_ExtLogFontW
.elfFullName
);
119 if (!GetFontResourceInfoW(argv
[1], &dwSize
, g_ExtLogFontW
.elfFullName
, 1))
121 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, argv
[1]);
125 dwSize
= sizeof(LOGFONTW
);
126 if (!GetFontResourceInfoW(argv
[1], &dwSize
, &g_ExtLogFontW
.elfLogFont
, 2))
128 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, argv
[1]);
132 if (!Display_InitClass(hThisInstance
))
134 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
138 /* The main window class */
139 wincl
.cbSize
= sizeof (WNDCLASSEXW
);
140 wincl
.style
= CS_DBLCLKS
;
141 wincl
.lpfnWndProc
= MainWndProc
;
142 wincl
.cbClsExtra
= 0;
143 wincl
.cbWndExtra
= 0;
144 wincl
.hInstance
= hThisInstance
;
145 wincl
.hIcon
= LoadIcon (NULL
, IDI_APPLICATION
);
146 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
147 wincl
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
148 wincl
.lpszMenuName
= NULL
;
149 wincl
.lpszClassName
= g_szFontViewClassName
;
150 wincl
.hIconSm
= LoadIcon (NULL
, IDI_APPLICATION
);
152 /* Register the window class, and if it fails quit the program */
153 if (!RegisterClassExW (&wincl
))
155 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
159 /* The class is registered, let's create the main window */
160 hMainWnd
= CreateWindowExW(
161 0, /* Extended possibilites for variation */
162 g_szFontViewClassName
, /* Classname */
163 g_ExtLogFontW
.elfFullName
,/* Title Text */
164 WS_OVERLAPPEDWINDOW
, /* default window */
165 CW_USEDEFAULT
, /* Windows decides the position */
166 CW_USEDEFAULT
, /* where the window ends up on the screen */
167 544, /* The programs width */
168 375, /* and height in pixels */
169 HWND_DESKTOP
, /* The window is a child-window to desktop */
171 hThisInstance
, /* Program Instance handler */
172 NULL
/* No Window Creation data */
174 ShowWindow(hMainWnd
, nCmdShow
);
176 /* Main message loop */
177 while (GetMessage (&msg
, NULL
, 0, 0))
179 TranslateMessage(&msg
);
180 DispatchMessage(&msg
);
183 RemoveFontResourceW(argv
[1]);
189 MainWnd_OnCreate(HWND hwnd
)
191 WCHAR szQuit
[MAX_BUTTONNAME
];
192 WCHAR szPrint
[MAX_BUTTONNAME
];
193 WCHAR szString
[MAX_STRING
];
194 HWND hDisplay
, hButtonQuit
, hButtonPrint
;
196 /* create the display window */
197 hDisplay
= CreateWindowExW(
198 0, /* Extended style */
199 g_szFontDisplayClassName
, /* Classname */
200 L
"", /* Title text */
201 WS_CHILD
| WS_VSCROLL
, /* Window style */
203 HEADER_SIZE
, /* Y-Pos */
205 370-HEADER_SIZE
, /* Height */
207 (HMENU
)IDC_DISPLAY
, /* Identifier */
208 g_hInstance
, /* Program Instance handler */
209 NULL
/* Window Creation data */
212 LoadStringW(g_hInstance
, IDS_STRING
, szString
, MAX_STRING
);
213 SendMessage(hDisplay
, FVM_SETSTRING
, 0, (LPARAM
)szString
);
215 /* Init the display window with the font name */
216 SendMessage(hDisplay
, FVM_SETTYPEFACE
, 0, (LPARAM
)&g_ExtLogFontW
);
217 ShowWindow(hDisplay
, SW_SHOWNORMAL
);
219 /* Create the quit button */
220 LoadStringW(g_hInstance
, IDS_QUIT
, szQuit
, MAX_BUTTONNAME
);
221 hButtonQuit
= CreateWindowExW(
222 0, /* Extended style */
223 L
"button", /* Classname */
224 szQuit
, /* Title text */
225 WS_CHILD
| WS_VISIBLE
, /* Window style */
226 BUTTON_POS_X
, /* X-pos */
227 BUTTON_POS_Y
, /* Y-Pos */
228 BUTTON_WIDTH
, /* Width */
229 BUTTON_HEIGHT
, /* Height */
231 (HMENU
)IDC_QUIT
, /* Identifier */
232 g_hInstance
, /* Program Instance handler */
233 NULL
/* Window Creation data */
235 SendMessage(hButtonQuit
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
237 /* Create the print button */
238 LoadStringW(g_hInstance
, IDS_PRINT
, szPrint
, MAX_BUTTONNAME
);
239 hButtonPrint
= CreateWindowExW(
240 0, /* Extended style */
241 L
"button", /* Classname */
242 szPrint
, /* Title text */
243 WS_CHILD
| WS_VISIBLE
, /* Window style */
245 BUTTON_POS_Y
, /* Y-Pos */
246 BUTTON_WIDTH
, /* Width */
247 BUTTON_HEIGHT
, /* Height */
249 (HMENU
)IDC_PRINT
, /* Identifier */
250 g_hInstance
, /* Program Instance handler */
251 NULL
/* Window Creation data */
253 SendMessage(hButtonPrint
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
259 MainWnd_OnSize(HWND hwnd
)
263 GetClientRect(hwnd
, &rc
);
264 MoveWindow(GetDlgItem(hwnd
, IDC_PRINT
), rc
.right
- BUTTON_WIDTH
- BUTTON_POS_X
, BUTTON_POS_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
, TRUE
);
265 MoveWindow(GetDlgItem(hwnd
, IDC_DISPLAY
), 0, HEADER_SIZE
, rc
.right
, rc
.bottom
- HEADER_SIZE
, TRUE
);
271 MainWnd_OnPaint(HWND hwnd
)
277 hDC
= BeginPaint(hwnd
, &ps
);
278 GetClientRect(hwnd
, &rc
);
279 rc
.top
= HEADER_SIZE
- 2;
280 rc
.bottom
= HEADER_SIZE
;
281 FillRect(hDC
, &rc
, GetStockObject(GRAY_BRUSH
));
287 MainWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
292 return MainWnd_OnCreate(hwnd
);
295 return MainWnd_OnPaint(hwnd
);
298 return MainWnd_OnSize(hwnd
);
301 switch(LOWORD(wParam
))
304 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
308 MessageBox(hwnd
, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK
);
314 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
317 default: /* for messages that we don't deal with */
318 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);