ReactOS 0.4.16-dev-334-g4d9f67c
MainWindow.cpp
Go to the documentation of this file.
1/*
2* PROJECT: ReactOS Character Map
3* LICENSE: GPL - See COPYING in the top level directory
4* FILE: base/applications/charmap/MainWindow.cpp
5* PURPOSE: Implements the main dialog window
6* COPYRIGHT: Copyright 2015 Ged Murphy <gedmurphy@reactos.org>
7*/
8
9
10#include "precomp.h"
11#include "MainWindow.h"
12
13
14/* DATA *****************************************************/
15
16#define ID_ABOUT 0x1
17
19
20
21/* PUBLIC METHODS **********************************************/
22
24 m_hMainWnd(NULL),
25 m_hStatusBar(NULL),
26 m_CmdShow(0),
27 m_hRichEd(NULL),
28 m_GridView(nullptr)
29{
30 m_GridView = new CGridView();
31}
32
34{
35}
36
37bool
39 _In_ int nCmdShow)
40{
43 int Ret = 1;
44
45 // Store the instance
47 m_CmdShow = nCmdShow;
48
49 // Initialize common controls
50 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
53
54 // Load the application name
55 if (szAppName.LoadStringW(g_hInstance, IDS_TITLE))
56 {
57 // Initialize the main window
58 if (Initialize(szAppName, nCmdShow))
59 {
60 // Run the application
61 Ret = Run();
62
63 // Uninitialize the main window
65 }
66 }
67
68 return (Ret == 0);
69}
70
71
72
73/* PRIVATE METHODS **********************************************/
74
75bool
77 _In_ int nCmdShow)
78{
79 // The dialog has a rich edit text box
80 m_hRichEd = LoadLibraryW(L"riched20.DLL");
81 if (m_hRichEd == NULL) return false;
82
85 NULL,
87 (LPARAM)this));
88}
89
90void
92{
93 if (m_hRichEd)
95}
96
97int
99{
100 MSG Msg;
101
102 // Pump the message queue
103 while (GetMessageW(&Msg, NULL, 0, 0) != 0)
104 {
107 }
108
109 return 0;
110}
111
112void
114{
116 SB_SIMPLE,
117 (WPARAM)InMenuLoop,
118 0);
119}
120
121bool
123{
124 int StatWidths[] = { 110, -1 }; // widths of status bar
125 bool bRet = FALSE;
126
127 // Create the status bar
130 NULL,
132 0, 0, 0, 0,
136 NULL);
137 if (m_hStatusBar)
138 {
139 // Create the sections
142 sizeof(StatWidths) / sizeof(int),
143 (LPARAM)StatWidths) != 0);
144
145 // Set the status bar for multiple parts output
147 }
148
149 return bRet;
150}
151
152bool
154 _In_ INT PartId,
156 _In_ UINT uID)
157{
158 CAtlStringW szMessage;
159 bool bRet = false;
160
161 // Load the string from the resource
162 if (szMessage.LoadStringW(hInstance, uID))
163 {
164 // Display it on the status bar
165 bRet = (SendMessageW(hStatusBar,
167 (WPARAM)PartId,
168 (LPARAM)szMessage.GetBuffer()) != 0);
169 }
170
171 return bRet;
172}
173
174BOOL
176{
177 m_hMainWnd = hDlg;
178
179 if (!CreateStatusBar())
180 return FALSE;
181
182 if (!m_GridView->Create(hDlg))
183 return FALSE;
184
185 // Load an 'about' option into the system menu
186 HMENU hSysMenu;
187 hSysMenu = GetSystemMenu(m_hMainWnd, FALSE);
188 if (hSysMenu != NULL)
189 {
190 CAtlStringW AboutText;
191 if (AboutText.LoadStringW(IDS_ABOUT))
192 {
193 AppendMenuW(hSysMenu, MF_SEPARATOR, 0, NULL);
194 AppendMenuW(hSysMenu, MF_STRING, ID_ABOUT, AboutText);
195 }
196 }
197
198 // Add all the fonts to the list
199 if (!CreateFontComboBox())
200 return FALSE;
201
203
204 // Configure Richedit control for sending notification changes.
205 DWORD evMask;
206 evMask = SendDlgItemMessage(hDlg, IDC_TEXTBOX, EM_GETEVENTMASK, 0, 0);
207 evMask |= ENM_CHANGE;
209
210 // Display the window according to the user request
212
213 return TRUE;
214}
215
216BOOL
219 )
220{
221 RECT rcClient, rcStatus;
222 INT lvHeight, iStatusHeight;
223
224 // Resize the status bar
226
227 // Get the statusbar rect and save the height
228 GetWindowRect(m_hStatusBar, &rcStatus);
229 iStatusHeight = rcStatus.bottom - rcStatus.top;
230
231 // Get the full client rect
232 GetClientRect(m_hMainWnd, &rcClient);
233
234 // Calculate the remaining height for the gridview
235 lvHeight = rcClient.bottom - iStatusHeight;
236
237 // Resize the grid view
239
240 return TRUE;
241}
242
243BOOL
245{
246 LPNMHDR NmHdr = (LPNMHDR)lParam;
247 LRESULT Ret = 0;
248
249 switch (NmHdr->code)
250 {
251 case NM_RCLICK:
252 {
253 break;
254 }
255
256 case NM_DBLCLK:
257 case NM_RETURN:
258 {
259 break;
260 }
261 }
262
263 return Ret;
264}
265
266BOOL
268{
269 return 0;// m_GridView->OnContextMenu(lParam);
270}
271
272BOOL
274 _In_ LPARAM /*lParam*/)
275{
276 LRESULT RetCode = 0;
277 WORD Msg;
278
279 // Get the message
280 Msg = LOWORD(wParam);
281
282 switch (Msg)
283 {
285 break;
286
287 case IDC_FONTCOMBO:
289 {
291 }
292 break;
293
294 default:
295 // We didn't handle it
296 RetCode = -1;
297 break;
298 }
299
300 return RetCode;
301}
302
303BOOL
305{
306 // Clear the user data pointer
308
309 // Break the message loop
311
312 return TRUE;
313}
314
317 _In_ HWND hwndDlg,
318 _In_ UINT Msg,
321 )
322{
324 LRESULT RetCode = 0;
325
326 // Get the object pointer from window context
328 if (This == NULL)
329 {
330 // Check that this isn't a create message
331 if (Msg != WM_INITDIALOG)
332 {
333 // Don't handle null info pointer
334 return FALSE;
335 }
336 }
337
338 switch (Msg)
339 {
340 case WM_INITDIALOG:
341 {
342 // Get the object pointer from the create param
344
345 // Store the pointer in the window's global user data
347
348 // Call the create handler
349 return This->OnCreate(hwndDlg);
350 }
351
352 case WM_SIZE:
353 {
354 return This->OnSize(wParam);
355 }
356
357 case WM_NOTIFY:
358 {
359 return This->OnNotify(lParam);
360 }
361
362 case WM_CONTEXTMENU:
363 {
364 return This->OnContext(lParam);
365 }
366
367 case WM_COMMAND:
368 {
369 return This->OnCommand(wParam, lParam);
370 }
371
372 case WM_SYSCOMMAND:
373 switch (wParam)
374 {
375 case ID_ABOUT:
376 MessageBoxW(This->m_hMainWnd,
377 L"ReactOS Character Map\nCopyright Ged Murphy 2015",
378 L"About",
380 break;
381 }
382 break;
383
384 case WM_ENTERMENULOOP:
385 {
386 This->UpdateStatusBar(true);
387 return TRUE;
388 }
389
390 case WM_EXITMENULOOP:
391 {
392 This->UpdateStatusBar(false);
393 return TRUE;
394 }
395
396 case WM_CLOSE:
397 {
398 // Destroy the main window
399 return DestroyWindow(hwndDlg);
400 }
401
402
403 case WM_DESTROY:
404 {
405 // Call the destroy handler
406 return This->OnDestroy();
407 }
408 }
409
410 return FALSE;
411}
412
414{
417};
418
419int
422 NEWTEXTMETRICEXW *lpntme,
423 DWORD FontType,
425{
427 LPWSTR pszName = lpelfe->elfLogFont.lfFaceName;
428
429 /* Skip rotated font */
430 if (pszName[0] == L'@') return 1;
431
432 /* make sure font doesn't already exist in our list */
433 if (SendMessageW(Params->hCombo,
435 0,
436 (LPARAM)pszName) == CB_ERR)
437 {
438 INT idx;
439 idx = (INT)SendMessageW(Params->hCombo,
441 0,
442 (LPARAM)pszName);
443
444 /* record the font's attributes (Fixedwidth and Truetype) */
445 BOOL fFixed = (lpelfe->elfLogFont.lfPitchAndFamily & FIXED_PITCH) ? TRUE : FALSE;
446 BOOL fTrueType = (lpelfe->elfLogFont.lfOutPrecision == OUT_STROKE_PRECIS) ? TRUE : FALSE;
447
448 /* store this information in the list-item's userdata area */
449 SendMessageW(Params->hCombo,
451 idx,
452 MAKEWPARAM(fFixed, fTrueType));
453 }
454
455 return 1;
456}
457
458
459bool
461{
462 HWND hCombo;
464
465 NONCLIENTMETRICSW NonClientMetrics;
466 NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
467 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
468 sizeof(NONCLIENTMETRICSW),
469 &NonClientMetrics,
470 0);
471
472 // Get a handle to the font
473 HFONT GuiFont;
474 GuiFont = CreateFontIndirectW(&NonClientMetrics.lfMessageFont);
475
476 // Set the font used in the combo box
477 SendMessageW(hCombo,
479 (WPARAM)GuiFont,
480 0);
481
482 // Set the fonts which we want to enumerate
483 LOGFONTW FontsToEnum;
484 ZeroMemory(&FontsToEnum, sizeof(LOGFONTW));
485 FontsToEnum.lfCharSet = DEFAULT_CHARSET;
486
487 // Set the params we want to pass to the callback
489 Params.This = this;
490 Params.hCombo = hCombo;
491
492 // Get a DC for combo box
493 HDC hdc;
494 hdc = GetDC(hCombo);
495
496 // Enumerate all the fonts
497 int ret;
499 &FontsToEnum,
501 (LPARAM)&Params,
502 0);
503
504 ReleaseDC(hCombo, hdc);
505 DeleteObject(GuiFont);
506
507 // Select the first item in the list
508 SendMessageW(hCombo,
510 0,
511 0);
512
513 return (ret == 1);
514}
515
516bool
518 )
519{
520 HWND hCombo;
522
523 INT Length;
525 if (!Length) return false;
526
527 CAtlStringW FontName;
528 FontName.Preallocate(Length);
529
530 SendMessageW(hCombo,
532 FontName.GetAllocLength(),
533 (LPARAM)FontName.GetBuffer());
534
535 return m_GridView->SetFont(FontName);
536}
HINSTANCE g_hInstance
Definition: MainWindow.cpp:18
#define IDS_TITLE
Definition: resource.h:30
#define IDC_FONTCOMBO
Definition: resource.h:12
#define IDC_TEXTBOX
Definition: resource.h:15
#define IDC_CHECK_ADVANCED
Definition: resource.h:26
#define IDS_ABOUT
Definition: resource.h:29
#define IDD_CHARMAP
Definition: resource.h:7
#define IDD_STATUSBAR
Definition: resource.h:9
HINSTANCE g_hInstance
Definition: MainWindow.cpp:18
HWND hStatusBar
Definition: main.c:23
HINSTANCE hInstance
Definition: charmap.c:19
#define ID_ABOUT
Definition: charmap.c:17
void Preallocate(_In_ int nLength)
Definition: atlsimpstr.h:376
int GetAllocLength() const noexcept
Definition: atlsimpstr.h:357
bool Initialize(_In_z_ LPCTSTR lpCaption, _In_ int nCmdShow)
Definition: MainWindow.cpp:76
~CCharMapWindow(void)
Definition: MainWindow.cpp:33
static INT_PTR CALLBACK DialogProc(_In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: MainWindow.cpp:316
HWND m_hStatusBar
Definition: MainWindow.h:7
BOOL OnCommand(_In_ WPARAM wParam, LPARAM lParam)
Definition: MainWindow.cpp:273
static int CALLBACK EnumDisplayFont(ENUMLOGFONTEXW *lpelfe, NEWTEXTMETRICEXW *lpntme, DWORD FontType, LPARAM lParam)
Definition: MainWindow.cpp:421
bool StatusBarLoadString(_In_ HWND hStatusBar, _In_ INT PartId, _In_ HINSTANCE hInstance, _In_ UINT uID)
Definition: MainWindow.cpp:153
BOOL OnSize(void)
Definition: MainWindow.cpp:217
HMODULE m_hRichEd
Definition: MainWindow.h:9
HWND m_hMainWnd
Definition: MainWindow.h:6
CGridView * m_GridView
Definition: MainWindow.h:11
bool CreateStatusBar(void)
Definition: MainWindow.cpp:122
BOOL OnCreate(_In_ HWND hwnd)
Definition: MainWindow.cpp:175
BOOL OnContext(_In_ LPARAM lParam)
Definition: MainWindow.cpp:267
CCharMapWindow(void)
Definition: MainWindow.cpp:23
BOOL OnDestroy(void)
Definition: MainWindow.cpp:304
void UpdateStatusBar(_In_ bool InMenuLoop)
Definition: MainWindow.cpp:113
bool CreateFontComboBox()
Definition: MainWindow.cpp:460
bool ChangeMapFont()
Definition: MainWindow.cpp:517
bool Create(_In_ HINSTANCE hInst, _In_ int nCmdShow)
Definition: MainWindow.cpp:38
void Uninitialize(void)
Definition: MainWindow.cpp:91
BOOL OnNotify(_In_ LPARAM lParam)
Definition: MainWindow.cpp:244
HWND GetHwnd()
Definition: GridView.h:49
bool SetFont(_In_ CAtlString &FontName)
Definition: GridView.cpp:67
bool Create(_In_ HWND hParent)
Definition: GridView.cpp:36
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
struct @1642 Msg[]
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:900
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
#define FreeLibrary(x)
Definition: compat.h:748
#define CALLBACK
Definition: compat.h:35
#define LoadLibraryW(x)
Definition: compat.h:747
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define _In_z_
Definition: no_sal2.h:164
#define _In_
Definition: no_sal2.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
#define INT
Definition: polytest.cpp:20
#define SB_SIMPLE
Definition: commctrl.h:1963
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
#define NM_DBLCLK
Definition: commctrl.h:131
#define NM_RETURN
Definition: commctrl.h:132
#define NM_RCLICK
Definition: commctrl.h:133
#define SB_SETTEXT
Definition: commctrl.h:1954
#define ICC_COOL_CLASSES
Definition: commctrl.h:69
#define SB_SETPARTS
Definition: commctrl.h:1959
#define SBARS_SIZEGRIP
Definition: commctrl.h:1928
#define ICC_BAR_CLASSES
Definition: commctrl.h:60
#define STATUSCLASSNAME
Definition: commctrl.h:1944
#define ENM_CHANGE
Definition: richedit.h:468
#define EM_GETEVENTMASK
Definition: richedit.h:92
#define EM_SETEVENTMASK
Definition: richedit.h:102
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define WM_NOTIFY
Definition: richedit.h:61
TCHAR szAppName[128]
Definition: solitaire.cpp:18
CCharMapWindow * This
Definition: MainWindow.cpp:415
BYTE lfCharSet
Definition: dimm.idl:67
LOGFONTW elfLogFont
Definition: wingdi.h:2702
BYTE lfOutPrecision
Definition: wingdi.h:1906
WCHAR lfFaceName[LF_FACESIZE]
Definition: wingdi.h:1910
BYTE lfPitchAndFamily
Definition: wingdi.h:1909
UINT code
Definition: winuser.h:3162
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
int ret
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
#define ZeroMemory
Definition: winbase.h:1737
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define FIXED_PITCH
Definition: wingdi.h:444
int WINAPI EnumFontFamiliesExW(_In_ HDC, _In_ PLOGFONTW, _In_ FONTENUMPROCW, _In_ LPARAM, _In_ DWORD)
FARPROC FONTENUMPROCW
Definition: wingdi.h:2897
#define OUT_STROKE_PRECIS
Definition: wingdi.h:418
#define DEFAULT_CHARSET
Definition: wingdi.h:384
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
HWND WINAPI CreateDialogParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CB_SETITEMDATA
Definition: winuser.h:1969
#define MAKEWPARAM(l, h)
Definition: winuser.h:4012
#define WM_CLOSE
Definition: winuser.h:1624
#define WM_SYSCOMMAND
Definition: winuser.h:1744
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1614
#define WM_COMMAND
Definition: winuser.h:1743
#define MF_STRING
Definition: winuser.h:138
#define CB_ERR
Definition: winuser.h:2438
#define CB_SETCURSEL
Definition: winuser.h:1964
#define WM_GETTEXT
Definition: winuser.h:1621
#define CB_FINDSTRINGEXACT
Definition: winuser.h:1943
#define WM_INITDIALOG
Definition: winuser.h:1742
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define CBN_SELCHANGE
Definition: winuser.h:1982
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WM_ENTERMENULOOP
Definition: winuser.h:1807
#define MF_SEPARATOR
Definition: winuser.h:137
#define WM_SETFONT
Definition: winuser.h:1653
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define CB_ADDSTRING
Definition: winuser.h:1939
struct tagNMHDR * LPNMHDR
#define SendMessage
Definition: winuser.h:5855
#define WM_EXITMENULOOP
Definition: winuser.h:1808
HDC WINAPI GetDC(_In_opt_ HWND)
int WINAPI GetWindowTextLengthW(_In_ HWND)
#define MB_OK
Definition: winuser.h:793
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define WM_DESTROY
Definition: winuser.h:1612
#define MB_APPLMODAL
Definition: winuser.h:795
#define SendDlgItemMessage
Definition: winuser.h:5854
BOOL WINAPI DestroyWindow(_In_ HWND)
#define MAKEINTRESOURCE
Definition: winuser.h:591
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
static void Initialize()
Definition: xlate.c:212
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const CHAR * LPCTSTR
Definition: xmlstorage.h:193