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.
32 HINSTANCE g_hInstance
;
33 EXTLOGFONTW g_ExtLogFontW
;
36 static const WCHAR g_szFontViewClassName
[] = L
"FontViewWClass";
38 /* GetFontResourceInfoW is undocumented */
39 BOOL WINAPI
GetFontResourceInfoW(LPCWSTR lpFileName
, DWORD
*pdwBufSize
, void* lpBuffer
, DWORD dwType
);
56 len
= LoadStringW(hInstance
, dwStringId
, (LPWSTR
)Buffer
, 1000);
60 dwFlags
|= FORMAT_MESSAGE_FROM_STRING
;
61 dwFlags
&= ~(FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_FROM_SYSTEM
);
62 dwRet
= FormatMessageW(dwFlags
, Buffer
, 0, dwLanguageId
, lpBuffer
, nSize
, Arguments
);
69 ErrorMsgBox(HWND hParent
, DWORD dwMessageId
, ...)
71 HLOCAL hMemCaption
= NULL
;
72 HLOCAL hMemText
= NULL
;
75 va_start(args
, dwMessageId
);
76 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
77 NULL
, dwMessageId
, 0, (LPWSTR
)&hMemText
, 0, &args
);
80 FormatString(FORMAT_MESSAGE_ALLOCATE_BUFFER
,
81 NULL
, IDS_ERROR
, 0, (LPWSTR
)&hMemCaption
, 0, NULL
);
83 MessageBoxW(hParent
, hMemText
, hMemCaption
, MB_ICONERROR
);
85 LocalFree(hMemCaption
);
90 WinMain (HINSTANCE hThisInstance
,
91 HINSTANCE hPrevInstance
,
97 WCHAR szFileName
[MAX_PATH
] = L
"";
104 switch (GetUserDefaultUILanguage())
106 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
107 SetProcessDefaultLayout(LAYOUT_RTL
);
114 g_hInstance
= hThisInstance
;
116 /* Get unicode command line */
117 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
120 OPENFILENAMEW fontOpen
;
121 WCHAR filter
[MAX_PATH
], dialogTitle
[MAX_PATH
];
123 LoadStringW(NULL
, IDS_OPEN
, dialogTitle
, MAX_PATH
);
124 LoadStringW(NULL
, IDS_FILTER_LIST
, filter
, MAX_PATH
);
126 /* Clears out any values of fontOpen before we use it */
127 ZeroMemory(&fontOpen
, sizeof(fontOpen
));
129 /* Sets up the open dialog box */
130 fontOpen
.lStructSize
= sizeof(fontOpen
);
131 fontOpen
.hwndOwner
= NULL
;
132 fontOpen
.lpstrFilter
= filter
;
133 fontOpen
.lpstrFile
= szFileName
;
134 fontOpen
.lpstrTitle
= dialogTitle
;
135 fontOpen
.nMaxFile
= MAX_PATH
;
136 fontOpen
.Flags
= OFN_EXPLORER
| OFN_FILEMUSTEXIST
| OFN_HIDEREADONLY
;
137 fontOpen
.lpstrDefExt
= L
"ttf";
139 /* Opens up the Open File dialog box in order to chose a font file. */
140 if(GetOpenFileNameW(&fontOpen
))
142 fileName
= fontOpen
.lpstrFile
;
143 g_fileName
= fileName
;
145 /* If the user decides to close out of the open dialog effectively
146 exiting the program altogether */
152 /* Try to add the font resource from command line */
154 g_fileName
= fileName
;
157 if (!AddFontResourceW(fileName
))
159 ErrorMsgBox(0, IDS_ERROR_NOFONT
, fileName
);
163 /* Get the font name */
164 dwSize
= sizeof(g_ExtLogFontW
.elfFullName
);
165 if (!GetFontResourceInfoW(fileName
, &dwSize
, g_ExtLogFontW
.elfFullName
, 1))
167 ErrorMsgBox(0, IDS_ERROR_NOFONT
, fileName
);
171 dwSize
= sizeof(LOGFONTW
);
172 if (!GetFontResourceInfoW(fileName
, &dwSize
, &g_ExtLogFontW
.elfLogFont
, 2))
174 ErrorMsgBox(0, IDS_ERROR_NOFONT
, fileName
);
178 if (!Display_InitClass(hThisInstance
))
180 ErrorMsgBox(0, IDS_ERROR_NOCLASS
);
184 /* The main window class */
185 wincl
.cbSize
= sizeof (WNDCLASSEXW
);
186 wincl
.style
= CS_DBLCLKS
;
187 wincl
.lpfnWndProc
= MainWndProc
;
188 wincl
.cbClsExtra
= 0;
189 wincl
.cbWndExtra
= 0;
190 wincl
.hInstance
= hThisInstance
;
191 wincl
.hIcon
= LoadIcon (GetModuleHandle(NULL
), MAKEINTRESOURCE(IDI_TT
));
192 wincl
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
193 wincl
.hbrBackground
= (HBRUSH
)COLOR_BACKGROUND
;
194 wincl
.lpszMenuName
= NULL
;
195 wincl
.lpszClassName
= g_szFontViewClassName
;
196 wincl
.hIconSm
= LoadIcon (GetModuleHandle(NULL
), MAKEINTRESOURCE(IDI_TT
));
198 /* Register the window class, and if it fails quit the program */
199 if (!RegisterClassExW (&wincl
))
201 ErrorMsgBox(0, IDS_ERROR_NOCLASS
);
205 /* The class is registered, let's create the main window */
206 hMainWnd
= CreateWindowExW(
207 0, /* Extended possibilites for variation */
208 g_szFontViewClassName
, /* Classname */
209 g_ExtLogFontW
.elfFullName
,/* Title Text */
210 WS_OVERLAPPEDWINDOW
, /* default window */
211 CW_USEDEFAULT
, /* Windows decides the position */
212 CW_USEDEFAULT
, /* where the window ends up on the screen */
213 544, /* The programs width */
214 375, /* and height in pixels */
215 HWND_DESKTOP
, /* The window is a child-window to desktop */
217 hThisInstance
, /* Program Instance handler */
218 NULL
/* No Window Creation data */
220 ShowWindow(hMainWnd
, nCmdShow
);
222 /* Main message loop */
223 while (GetMessage (&msg
, NULL
, 0, 0))
225 TranslateMessage(&msg
);
226 DispatchMessage(&msg
);
229 RemoveFontResourceW(argv
[1]);
231 return (int)msg
.wParam
;
235 MainWnd_OnCreate(HWND hwnd
)
237 WCHAR szQuit
[MAX_BUTTONNAME
];
238 WCHAR szPrint
[MAX_BUTTONNAME
];
239 WCHAR szString
[MAX_STRING
];
240 HWND hDisplay
, hButtonInstall
, hButtonPrint
;
242 /* create the display window */
243 hDisplay
= CreateWindowExW(
244 0, /* Extended style */
245 g_szFontDisplayClassName
, /* Classname */
246 L
"", /* Title text */
247 WS_CHILD
| WS_VSCROLL
, /* Window style */
249 HEADER_SIZE
, /* Y-Pos */
251 370-HEADER_SIZE
, /* Height */
253 (HMENU
)IDC_DISPLAY
, /* Identifier */
254 g_hInstance
, /* Program Instance handler */
255 NULL
/* Window Creation data */
258 LoadStringW(g_hInstance
, IDS_STRING
, szString
, MAX_STRING
);
259 SendMessage(hDisplay
, FVM_SETSTRING
, 0, (LPARAM
)szString
);
261 /* Init the display window with the font name */
262 SendMessage(hDisplay
, FVM_SETTYPEFACE
, 0, (LPARAM
)&g_ExtLogFontW
);
263 ShowWindow(hDisplay
, SW_SHOWNORMAL
);
265 /* Create the install button */
266 LoadStringW(g_hInstance
, IDS_INSTALL
, szQuit
, MAX_BUTTONNAME
);
267 hButtonInstall
= CreateWindowExW(
268 0, /* Extended style */
269 L
"button", /* Classname */
270 szQuit
, /* Title text */
271 WS_CHILD
| WS_VISIBLE
, /* Window style */
272 BUTTON_POS_X
, /* X-pos */
273 BUTTON_POS_Y
, /* Y-Pos */
274 BUTTON_WIDTH
, /* Width */
275 BUTTON_HEIGHT
, /* Height */
277 (HMENU
)IDC_INSTALL
, /* Identifier */
278 g_hInstance
, /* Program Instance handler */
279 NULL
/* Window Creation data */
281 SendMessage(hButtonInstall
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
283 /* Create the print button */
284 LoadStringW(g_hInstance
, IDS_PRINT
, szPrint
, MAX_BUTTONNAME
);
285 hButtonPrint
= CreateWindowExW(
286 0, /* Extended style */
287 L
"button", /* Classname */
288 szPrint
, /* Title text */
289 WS_CHILD
| WS_VISIBLE
, /* Window style */
291 BUTTON_POS_Y
, /* Y-Pos */
292 BUTTON_WIDTH
, /* Width */
293 BUTTON_HEIGHT
, /* Height */
295 (HMENU
)IDC_PRINT
, /* Identifier */
296 g_hInstance
, /* Program Instance handler */
297 NULL
/* Window Creation data */
299 SendMessage(hButtonPrint
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), (LPARAM
)TRUE
);
305 MainWnd_OnSize(HWND hwnd
)
309 GetClientRect(hwnd
, &rc
);
310 MoveWindow(GetDlgItem(hwnd
, IDC_PRINT
), rc
.right
- BUTTON_WIDTH
- BUTTON_POS_X
, BUTTON_POS_Y
, BUTTON_WIDTH
, BUTTON_HEIGHT
, TRUE
);
311 MoveWindow(GetDlgItem(hwnd
, IDC_DISPLAY
), 0, HEADER_SIZE
, rc
.right
, rc
.bottom
- HEADER_SIZE
, TRUE
);
317 MainWnd_OnPaint(HWND hwnd
)
323 hDC
= BeginPaint(hwnd
, &ps
);
324 GetClientRect(hwnd
, &rc
);
325 rc
.top
= HEADER_SIZE
- 2;
326 rc
.bottom
= HEADER_SIZE
;
327 FillRect(hDC
, &rc
, GetStockObject(GRAY_BRUSH
));
333 MainWnd_OnInstall(HWND hwnd
)
337 /* First, we have to find out if the font still exists. */
338 fontExists
= GetFileAttributes((LPCSTR
)g_fileName
);
339 if (fontExists
!= 0xFFFFFFFF) /* If the file does not exist */
341 ErrorMsgBox(0, IDS_ERROR_NOFONT
, g_fileName
);
345 //CopyFile(g_fileName, NULL, TRUE);
347 MessageBox(hwnd
, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK
);
353 MainWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
358 return MainWnd_OnCreate(hwnd
);
361 return MainWnd_OnPaint(hwnd
);
364 return MainWnd_OnSize(hwnd
);
367 switch(LOWORD(wParam
))
370 return MainWnd_OnInstall(hwnd
);
374 return Display_OnPrint(hwnd
);
380 PostQuitMessage (0); /* send a WM_QUIT to the message queue */
383 default: /* for messages that we don't deal with */
384 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);