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 switch (GetUserDefaultUILanguage())
100 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
101 SetProcessDefaultLayout(LAYOUT_RTL
);
108 g_hInstance
= hThisInstance
;
110 /* Get unicode command line */
111 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
114 OPENFILENAMEW fontOpen
;
115 WCHAR szFileName
[MAX_PATH
] = L
"";
116 HLOCAL dialogTitle
= NULL
;
118 /* Gets the title for the dialog box ready */
119 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
120 NULL
, IDS_OPEN
, 0, (LPWSTR
)&dialogTitle
, 0, NULL
);
122 /* Clears out any values of fontOpen before we use it */
123 ZeroMemory(&fontOpen
, sizeof(fontOpen
));
125 /* Sets up the open dialog box */
126 fontOpen
.lStructSize
= sizeof(fontOpen
);
127 fontOpen
.hwndOwner
= NULL
;
128 fontOpen
.lpstrFilter
= L
"TrueType Font (*.ttf)\0*.ttf\0"
129 L
"All Files (*.*)\0*.*\0";
130 fontOpen
.lpstrFile
= szFileName
;
131 fontOpen
.lpstrTitle
= dialogTitle
;
132 fontOpen
.nMaxFile
= MAX_PATH
;
133 fontOpen
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
134 fontOpen
.lpstrDefExt
= L
"ttf";
136 /* Opens up the Open File dialog box in order to chose a font file. */
137 if(GetOpenFileNameW(&fontOpen
))
139 fileName
= fontOpen
.lpstrFile
;
140 g_fileName
= fileName
;
142 /* If the user decides to close out of the open dialog effectively
143 exiting the program altogether */
147 LocalFree(dialogTitle
);
151 /* Try to add the font resource from command line */
153 g_fileName
= fileName
;
156 if (!AddFontResourceW(fileName
))
158 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, fileName
);
162 /* Load the GetFontResourceInfo function from gdi32.dll */
163 hDLL
= LoadLibraryW(L
"GDI32.DLL");
164 GetFontResourceInfoW
= (PGFRI
)GetProcAddress(hDLL
, "GetFontResourceInfoW");
166 /* Get the font name */
167 dwSize
= sizeof(g_ExtLogFontW
.elfFullName
);
168 if (!GetFontResourceInfoW(fileName
, &dwSize
, g_ExtLogFontW
.elfFullName
, 1))
170 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, fileName
);
174 dwSize
= sizeof(LOGFONTW
);
175 if (!GetFontResourceInfoW(fileName
, &dwSize
, &g_ExtLogFontW
.elfLogFont
, 2))
177 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, fileName
);
181 if (!Display_InitClass(hThisInstance
))
183 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
187 /* The main window class */
188 wincl
.cbSize
= sizeof (WNDCLASSEXW
);
189 wincl
.style
= CS_DBLCLKS
;
190 wincl
.lpfnWndProc
= MainWndProc
;
191 wincl
.cbClsExtra
= 0;
192 wincl
.cbWndExtra
= 0;
193 wincl
.hInstance
= hThisInstance
;
194 wincl
.hIcon
= LoadIcon (NULL
, IDI_APPLICATION
);
195 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
196 wincl
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
197 wincl
.lpszMenuName
= NULL
;
198 wincl
.lpszClassName
= g_szFontViewClassName
;
199 wincl
.hIconSm
= LoadIcon (NULL
, IDI_APPLICATION
);
201 /* Register the window class, and if it fails quit the program */
202 if (!RegisterClassExW (&wincl
))
204 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOCLASS
);
208 /* The class is registered, let's create the main window */
209 hMainWnd
= CreateWindowExW(
210 0, /* Extended possibilites for variation */
211 g_szFontViewClassName
, /* Classname */
212 g_ExtLogFontW
.elfFullName
,/* Title Text */
213 WS_OVERLAPPEDWINDOW
, /* default window */
214 CW_USEDEFAULT
, /* Windows decides the position */
215 CW_USEDEFAULT
, /* where the window ends up on the screen */
216 544, /* The programs width */
217 375, /* and height in pixels */
218 HWND_DESKTOP
, /* The window is a child-window to desktop */
220 hThisInstance
, /* Program Instance handler */
221 NULL
/* No Window Creation data */
223 ShowWindow(hMainWnd
, nCmdShow
);
225 /* Main message loop */
226 while (GetMessage (&msg
, NULL
, 0, 0))
228 TranslateMessage(&msg
);
229 DispatchMessage(&msg
);
232 RemoveFontResourceW(argv
[1]);
234 return (int)msg
.wParam
;
238 MainWnd_OnCreate(HWND hwnd
)
240 WCHAR szQuit
[MAX_BUTTONNAME
];
241 WCHAR szPrint
[MAX_BUTTONNAME
];
242 WCHAR szString
[MAX_STRING
];
243 HWND hDisplay
, hButtonInstall
, hButtonPrint
;
245 /* create the display window */
246 hDisplay
= CreateWindowExW(
247 0, /* Extended style */
248 g_szFontDisplayClassName
, /* Classname */
249 L
"", /* Title text */
250 WS_CHILD
| WS_VSCROLL
, /* Window style */
252 HEADER_SIZE
, /* Y-Pos */
254 370-HEADER_SIZE
, /* Height */
256 (HMENU
)IDC_DISPLAY
, /* Identifier */
257 g_hInstance
, /* Program Instance handler */
258 NULL
/* Window Creation data */
261 LoadStringW(g_hInstance
, IDS_STRING
, szString
, MAX_STRING
);
262 SendMessage(hDisplay
, FVM_SETSTRING
, 0, (LPARAM
)szString
);
264 /* Init the display window with the font name */
265 SendMessage(hDisplay
, FVM_SETTYPEFACE
, 0, (LPARAM
)&g_ExtLogFontW
);
266 ShowWindow(hDisplay
, SW_SHOWNORMAL
);
268 /* Create the quit button */
269 LoadStringW(g_hInstance
, IDS_INSTALL
, szQuit
, MAX_BUTTONNAME
);
270 hButtonInstall
= CreateWindowExW(
271 0, /* Extended style */
272 L
"button", /* Classname */
273 szQuit
, /* Title text */
274 WS_CHILD
| WS_VISIBLE
, /* Window style */
275 BUTTON_POS_X
, /* X-pos */
276 BUTTON_POS_Y
, /* Y-Pos */
277 BUTTON_WIDTH
, /* Width */
278 BUTTON_HEIGHT
, /* Height */
280 (HMENU
)IDC_INSTALL
, /* Identifier */
281 g_hInstance
, /* Program Instance handler */
282 NULL
/* Window Creation data */
284 SendMessage(hButtonInstall
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
286 /* Create the print button */
287 LoadStringW(g_hInstance
, IDS_PRINT
, szPrint
, MAX_BUTTONNAME
);
288 hButtonPrint
= CreateWindowExW(
289 0, /* Extended style */
290 L
"button", /* Classname */
291 szPrint
, /* Title text */
292 WS_CHILD
| WS_VISIBLE
, /* Window style */
294 BUTTON_POS_Y
, /* Y-Pos */
295 BUTTON_WIDTH
, /* Width */
296 BUTTON_HEIGHT
, /* Height */
298 (HMENU
)IDC_PRINT
, /* Identifier */
299 g_hInstance
, /* Program Instance handler */
300 NULL
/* Window Creation data */
302 SendMessage(hButtonPrint
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
308 MainWnd_OnSize(HWND hwnd
)
312 GetClientRect(hwnd
, &rc
);
313 MoveWindow(GetDlgItem(hwnd
, IDC_PRINT
), rc
.right
- BUTTON_WIDTH
- BUTTON_POS_X
, BUTTON_POS_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
, TRUE
);
314 MoveWindow(GetDlgItem(hwnd
, IDC_DISPLAY
), 0, HEADER_SIZE
, rc
.right
, rc
.bottom
- HEADER_SIZE
, TRUE
);
320 MainWnd_OnPaint(HWND hwnd
)
326 hDC
= BeginPaint(hwnd
, &ps
);
327 GetClientRect(hwnd
, &rc
);
328 rc
.top
= HEADER_SIZE
- 2;
329 rc
.bottom
= HEADER_SIZE
;
330 FillRect(hDC
, &rc
, GetStockObject(GRAY_BRUSH
));
336 MainWnd_OnInstall(HWND hwnd
)
340 /* First, we have to find out if the font still exists. */
341 fontExists
= GetFileAttributes((LPCSTR
)g_fileName
);
342 if (fontExists
!= 0xFFFFFFFF) /* If the file does not exist */
344 ErrorMsgBox(0, IDS_ERROR
, IDS_ERROR_NOFONT
, g_fileName
);
348 //CopyFile(g_fileName, NULL, TRUE);
350 MessageBox(hwnd
, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK
);
356 MainWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
361 return MainWnd_OnCreate(hwnd
);
364 return MainWnd_OnPaint(hwnd
);
367 return MainWnd_OnSize(hwnd
);
370 switch(LOWORD(wParam
))
373 return MainWnd_OnInstall(hwnd
);
377 return Display_OnPrint(hwnd
);
383 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
386 default: /* for messages that we don't deal with */
387 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);