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
;
29 static const WCHAR g_szFontViewClassName
[] = L
"FontViewWClass";
31 /* Tye definition for the GetFontResourceInfo function */
32 typedef BOOL (WINAPI
*PGFRI
)(LPCWSTR
, DWORD
*, LPVOID
, DWORD
);
49 len
= LoadStringW(hInstance
, dwStringId
, (LPWSTR
)Buffer
, 1000);
53 dwFlags
|= FORMAT_MESSAGE_FROM_STRING
;
54 dwFlags
&= ~(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_FROM_SYSTEM
);
55 dwRet
= FormatMessageW(dwFlags
, Buffer
, 0, dwLanguageId
, lpBuffer
, nSize
, Arguments
);
62 ErrorMsgBox(HWND hParent
, DWORD dwCaptionID
, DWORD dwMessageId
, ...)
64 HLOCAL hMemCaption
= NULL
;
65 HLOCAL hMemText
= NULL
;
68 va_start(args
, dwMessageId
);
69 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
70 NULL
, dwMessageId
, 0, (LPWSTR
)&hMemText
, 0, &args
);
73 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
74 NULL
, dwCaptionID
, 0, (LPWSTR
)&hMemCaption
, 0, NULL
);
76 MessageBoxW(hParent
, hMemText
, hMemCaption
, MB_ICONERROR
);
78 LocalFree(hMemCaption
);
83 WinMain (HINSTANCE hThisInstance
,
84 HINSTANCE hPrevInstance
,
95 PGFRI GetFontResourceInfoW
;
98 g_hInstance
= hThisInstance
;
100 /* Get unicode command line */
101 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
104 OPENFILENAMEW fontOpen
;
105 WCHAR szFileName
[MAX_PATH
] = L
"";
106 HLOCAL dialogTitle
= NULL
;
108 /* Gets the title for the dialog box ready */
109 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
110 NULL
, IDS_OPEN
, 0, (LPWSTR
)&dialogTitle
, 0, NULL
);
112 /* Clears out any values of fontOpen before we use it */
113 ZeroMemory(&fontOpen
, sizeof(fontOpen
));
115 /* Sets up the open dialog box */
116 fontOpen
.lStructSize
= sizeof(fontOpen
);
117 fontOpen
.hwndOwner
= NULL
;
118 fontOpen
.lpstrFilter
= L
"TrueType Font (*.ttf)\0*.ttf\0"
119 L
"All Files (*.*)\0*.*\0";
120 fontOpen
.lpstrFile
= szFileName
;
121 fontOpen
.lpstrTitle
= dialogTitle
;
122 fontOpen
.nMaxFile
= MAX_PATH
;
123 fontOpen
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
124 fontOpen
.lpstrDefExt
= L
"ttf";
126 /* Opens up the Open File dialog box in order to chose a font file. */
127 if(GetOpenFileNameW(&fontOpen
))
129 fileName
= fontOpen
.lpstrFile
;
130 g_fileName
= fileName
;
132 /* If the user decides to close out of the open dialog effectively
133 exiting the program altogether */
137 LocalFree(dialogTitle
);
141 /* Try to add the font resource from command line */
143 g_fileName
= fileName
;
146 if (!AddFontResourceW(fileName
))
148 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, fileName
);
152 /* Load the GetFontResourceInfo function from gdi32.dll */
153 hDLL
= LoadLibraryW(L
"GDI32.DLL");
154 GetFontResourceInfoW
= (PGFRI
)GetProcAddress(hDLL
, "GetFontResourceInfoW");
156 /* Get the font name */
157 dwSize
= sizeof(g_ExtLogFontW
.elfFullName
);
158 if (!GetFontResourceInfoW(fileName
, &dwSize
, g_ExtLogFontW
.elfFullName
, 1))
160 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, fileName
);
164 dwSize
= sizeof(LOGFONTW
);
165 if (!GetFontResourceInfoW(fileName
, &dwSize
, &g_ExtLogFontW
.elfLogFont
, 2))
167 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, fileName
);
171 if (!Display_InitClass(hThisInstance
))
173 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
177 /* The main window class */
178 wincl
.cbSize
= sizeof (WNDCLASSEXW
);
179 wincl
.style
= CS_DBLCLKS
;
180 wincl
.lpfnWndProc
= MainWndProc
;
181 wincl
.cbClsExtra
= 0;
182 wincl
.cbWndExtra
= 0;
183 wincl
.hInstance
= hThisInstance
;
184 wincl
.hIcon
= LoadIcon (NULL
, IDI_APPLICATION
);
185 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
186 wincl
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
187 wincl
.lpszMenuName
= NULL
;
188 wincl
.lpszClassName
= g_szFontViewClassName
;
189 wincl
.hIconSm
= LoadIcon (NULL
, IDI_APPLICATION
);
191 /* Register the window class, and if it fails quit the program */
192 if (!RegisterClassExW (&wincl
))
194 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
198 /* The class is registered, let's create the main window */
199 hMainWnd
= CreateWindowExW(
200 0, /* Extended possibilites for variation */
201 g_szFontViewClassName
, /* Classname */
202 g_ExtLogFontW
.elfFullName
,/* Title Text */
203 WS_OVERLAPPEDWINDOW
, /* default window */
204 CW_USEDEFAULT
, /* Windows decides the position */
205 CW_USEDEFAULT
, /* where the window ends up on the screen */
206 544, /* The programs width */
207 375, /* and height in pixels */
208 HWND_DESKTOP
, /* The window is a child-window to desktop */
210 hThisInstance
, /* Program Instance handler */
211 NULL
/* No Window Creation data */
213 ShowWindow(hMainWnd
, nCmdShow
);
215 /* Main message loop */
216 while (GetMessage (&msg
, NULL
, 0, 0))
218 TranslateMessage(&msg
);
219 DispatchMessage(&msg
);
222 RemoveFontResourceW(argv
[1]);
224 return (int)msg
.wParam
;
228 MainWnd_OnCreate(HWND hwnd
)
230 WCHAR szQuit
[MAX_BUTTONNAME
];
231 WCHAR szPrint
[MAX_BUTTONNAME
];
232 WCHAR szString
[MAX_STRING
];
233 HWND hDisplay
, hButtonInstall
, hButtonPrint
;
235 /* create the display window */
236 hDisplay
= CreateWindowExW(
237 0, /* Extended style */
238 g_szFontDisplayClassName
, /* Classname */
239 L
"", /* Title text */
240 WS_CHILD
| WS_VSCROLL
, /* Window style */
242 HEADER_SIZE
, /* Y-Pos */
244 370-HEADER_SIZE
, /* Height */
246 (HMENU
)IDC_DISPLAY
, /* Identifier */
247 g_hInstance
, /* Program Instance handler */
248 NULL
/* Window Creation data */
251 LoadStringW(g_hInstance
, IDS_STRING
, szString
, MAX_STRING
);
252 SendMessage(hDisplay
, FVM_SETSTRING
, 0, (LPARAM
)szString
);
254 /* Init the display window with the font name */
255 SendMessage(hDisplay
, FVM_SETTYPEFACE
, 0, (LPARAM
)&g_ExtLogFontW
);
256 ShowWindow(hDisplay
, SW_SHOWNORMAL
);
258 /* Create the quit button */
259 LoadStringW(g_hInstance
, IDS_INSTALL
, szQuit
, MAX_BUTTONNAME
);
260 hButtonInstall
= CreateWindowExW(
261 0, /* Extended style */
262 L
"button", /* Classname */
263 szQuit
, /* Title text */
264 WS_CHILD
| WS_VISIBLE
, /* Window style */
265 BUTTON_POS_X
, /* X-pos */
266 BUTTON_POS_Y
, /* Y-Pos */
267 BUTTON_WIDTH
, /* Width */
268 BUTTON_HEIGHT
, /* Height */
270 (HMENU
)IDC_INSTALL
, /* Identifier */
271 g_hInstance
, /* Program Instance handler */
272 NULL
/* Window Creation data */
274 SendMessage(hButtonInstall
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
276 /* Create the print button */
277 LoadStringW(g_hInstance
, IDS_PRINT
, szPrint
, MAX_BUTTONNAME
);
278 hButtonPrint
= CreateWindowExW(
279 0, /* Extended style */
280 L
"button", /* Classname */
281 szPrint
, /* Title text */
282 WS_CHILD
| WS_VISIBLE
, /* Window style */
284 BUTTON_POS_Y
, /* Y-Pos */
285 BUTTON_WIDTH
, /* Width */
286 BUTTON_HEIGHT
, /* Height */
288 (HMENU
)IDC_PRINT
, /* Identifier */
289 g_hInstance
, /* Program Instance handler */
290 NULL
/* Window Creation data */
292 SendMessage(hButtonPrint
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
298 MainWnd_OnSize(HWND hwnd
)
302 GetClientRect(hwnd
, &rc
);
303 MoveWindow(GetDlgItem(hwnd
, IDC_PRINT
), rc
.right
- BUTTON_WIDTH
- BUTTON_POS_X
, BUTTON_POS_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
, TRUE
);
304 MoveWindow(GetDlgItem(hwnd
, IDC_DISPLAY
), 0, HEADER_SIZE
, rc
.right
, rc
.bottom
- HEADER_SIZE
, TRUE
);
310 MainWnd_OnPaint(HWND hwnd
)
316 hDC
= BeginPaint(hwnd
, &ps
);
317 GetClientRect(hwnd
, &rc
);
318 rc
.top
= HEADER_SIZE
- 2;
319 rc
.bottom
= HEADER_SIZE
;
320 FillRect(hDC
, &rc
, GetStockObject(GRAY_BRUSH
));
326 MainWnd_OnInstall(HWND hwnd
)
330 /* First, we have to find out if the font still exists. */
331 fontExists
= GetFileAttributes((LPCSTR
)g_fileName
);
332 if (fontExists
!= 0xFFFFFFFF) /* If the file does not exist */
334 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, g_fileName
);
338 //CopyFile(g_fileName, NULL, TRUE);
340 MessageBox(hwnd
, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK
);
346 MainWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
351 return MainWnd_OnCreate(hwnd
);
354 return MainWnd_OnPaint(hwnd
);
357 return MainWnd_OnSize(hwnd
);
360 switch(LOWORD(wParam
))
363 return MainWnd_OnInstall(hwnd
);
367 return Display_OnPrint(hwnd
);
373 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
376 default: /* for messages that we don't deal with */
377 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);