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>
11 #include "MainWindow.h"
14 /* DATA *****************************************************/
18 HINSTANCE g_hInstance
= NULL
;
21 /* PUBLIC METHODS **********************************************/
23 CCharMapWindow::CCharMapWindow(void) :
30 m_GridView
= new CGridView();
33 CCharMapWindow::~CCharMapWindow(void)
38 CCharMapWindow::Create(_In_ HINSTANCE hInst
,
41 INITCOMMONCONTROLSEX icex
;
42 CAtlStringW szAppName
;
49 // Initialize common controls
50 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
51 icex
.dwICC
= ICC_BAR_CLASSES
| ICC_COOL_CLASSES
;
52 InitCommonControlsEx(&icex
);
54 // Load the application name
55 if (szAppName
.LoadStringW(g_hInstance
, IDS_TITLE
))
57 // Initialize the main window
58 if (Initialize(szAppName
, nCmdShow
))
60 // Run the application
63 // Uninitialize the main window
73 /* PRIVATE METHODS **********************************************/
76 CCharMapWindow::Initialize(_In_z_ LPCTSTR lpCaption
,
79 // The dialog has a rich edit text box
80 m_hRichEd
= LoadLibraryW(L
"riched20.DLL");
81 if (m_hRichEd
== NULL
) return false;
83 return !!(CreateDialogParamW(g_hInstance
,
84 MAKEINTRESOURCE(IDD_CHARMAP
),
91 CCharMapWindow::Uninitialize(void)
94 FreeLibrary(m_hRichEd
);
98 CCharMapWindow::Run(void)
102 // Pump the message queue
103 while (GetMessageW(&Msg
, NULL
, 0, 0) != 0)
105 TranslateMessage(&Msg
);
106 DispatchMessageW(&Msg
);
113 CCharMapWindow::UpdateStatusBar(_In_
bool InMenuLoop
)
115 SendMessageW(m_hStatusBar
,
122 CCharMapWindow::CreateStatusBar(void)
124 int StatWidths
[] = { 110, -1 }; // widths of status bar
127 // Create the status bar
128 m_hStatusBar
= CreateWindowExW(0,
131 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
134 (HMENU
)IDD_STATUSBAR
,
139 // Create the sections
140 bRet
= (SendMessageW(m_hStatusBar
,
142 sizeof(StatWidths
) / sizeof(int),
143 (LPARAM
)StatWidths
) != 0);
145 // Set the status bar for multiple parts output
146 SendMessage(m_hStatusBar
, SB_SIMPLE
, (WPARAM
)FALSE
, (LPARAM
)0);
153 CCharMapWindow::StatusBarLoadString(_In_ HWND hStatusBar
,
155 _In_ HINSTANCE hInstance
,
158 CAtlStringW szMessage
;
161 // Load the string from the resource
162 if (szMessage
.LoadStringW(hInstance
, uID
))
164 // Display it on the status bar
165 bRet
= (SendMessageW(hStatusBar
,
168 (LPARAM
)szMessage
.GetBuffer()) != 0);
175 CCharMapWindow::OnCreate(_In_ HWND hDlg
)
179 if (!CreateStatusBar())
182 if (!m_GridView
->Create(hDlg
))
185 // Load an 'about' option into the system menu
187 hSysMenu
= GetSystemMenu(m_hMainWnd
, FALSE
);
188 if (hSysMenu
!= NULL
)
190 CAtlStringW AboutText
;
191 if (AboutText
.LoadStringW(IDS_ABOUT
))
193 AppendMenuW(hSysMenu
, MF_SEPARATOR
, 0, NULL
);
194 AppendMenuW(hSysMenu
, MF_STRING
, ID_ABOUT
, AboutText
);
198 // Add all the fonts to the
199 if (!CreateFontComboBox())
202 // Configure Richedit control for sending notification changes.
204 evMask
= SendDlgItemMessage(hDlg
, IDC_TEXTBOX
, EM_GETEVENTMASK
, 0, 0);
205 evMask
|= ENM_CHANGE
;
206 SendDlgItemMessage(hDlg
, IDC_TEXTBOX
, EM_SETEVENTMASK
, 0, (LPARAM
)evMask
);
208 // Display the window according to the user request
209 ShowWindow(m_hMainWnd
, m_CmdShow
);
215 CCharMapWindow::OnSize(void)
217 RECT rcClient
, rcStatus
;
218 INT lvHeight
, iStatusHeight
;
220 // Resize the status bar
221 SendMessage(m_hStatusBar
, WM_SIZE
, 0, 0);
223 // Get the statusbar rect and save the height
224 GetWindowRect(m_hStatusBar
, &rcStatus
);
225 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
227 // Get the full client rect
228 GetClientRect(m_hMainWnd
, &rcClient
);
230 // Calculate the remaining height for the treeview
231 lvHeight
= rcClient
.bottom
- iStatusHeight
;
233 // Resize the device view
234 //m_GridView->OnSize(0,
243 CCharMapWindow::OnNotify(_In_ LPARAM lParam
)
245 LPNMHDR NmHdr
= (LPNMHDR
)lParam
;
266 CCharMapWindow::OnContext(_In_ LPARAM lParam
)
268 return 0;// m_GridView->OnContextMenu(lParam);
272 CCharMapWindow::OnCommand(_In_ WPARAM wParam
,
273 _In_ LPARAM
/*lParam*/)
279 Msg
= LOWORD(wParam
);
283 case IDC_CHECK_ADVANCED
:
287 // We didn't handle it
296 CCharMapWindow::OnDestroy(void)
298 // Clear the user data pointer
299 SetWindowLongPtr(m_hMainWnd
, GWLP_USERDATA
, 0);
301 // Break the message loop
308 CCharMapWindow::DialogProc(
315 CCharMapWindow
*This
;
318 // Get the object pointer from window context
319 This
= (CCharMapWindow
*)GetWindowLongPtr(hwndDlg
, GWLP_USERDATA
);
322 // Check that this isn't a create message
323 if (Msg
!= WM_INITDIALOG
)
325 // Don't handle null info pointer
334 // Get the object pointer from the create param
335 This
= (CCharMapWindow
*)lParam
;
337 // Store the pointer in the window's global user data
338 SetWindowLongPtr(hwndDlg
, GWLP_USERDATA
, (LONG_PTR
)This
);
340 // Call the create handler
341 return This
->OnCreate(hwndDlg
);
346 return This
->OnSize();
351 return This
->OnNotify(lParam
);
356 return This
->OnContext(lParam
);
361 return This
->OnCommand(wParam
, lParam
);
369 MessageBoxW(This
->m_hMainWnd
,
370 L
"ReactOS Character Map\r\nCopyright Ged Murphy 2015",
372 MB_OK
| MB_APPLMODAL
);
377 case WM_ENTERMENULOOP
:
379 This
->UpdateStatusBar(true);
383 case WM_EXITMENULOOP
:
385 This
->UpdateStatusBar(false);
391 // Destroy the main window
392 return DestroyWindow(hwndDlg
);
398 // Call the destroy handler
399 return This
->OnDestroy();
406 struct EnumFontParams
408 CCharMapWindow
*This
;
414 CCharMapWindow::EnumDisplayFont(ENUMLOGFONTEXW
*lpelfe
,
415 NEWTEXTMETRICEXW
*lpntme
,
419 EnumFontParams
*Params
= (EnumFontParams
*)lParam
;
420 LPWSTR pszName
= lpelfe
->elfLogFont
.lfFaceName
;
422 /* Skip rotated font */
423 if (pszName
[0] == L
'@') return 1;
425 /* make sure font doesn't already exist in our list */
426 if (SendMessageW(Params
->hCombo
,
429 (LPARAM
)pszName
) == CB_ERR
)
432 idx
= (INT
)SendMessageW(Params
->hCombo
,
437 /* record the font's attributes (Fixedwidth and Truetype) */
438 BOOL fFixed
= (lpelfe
->elfLogFont
.lfPitchAndFamily
& FIXED_PITCH
) ? TRUE
: FALSE
;
439 BOOL fTrueType
= (lpelfe
->elfLogFont
.lfOutPrecision
== OUT_STROKE_PRECIS
) ? TRUE
: FALSE
;
441 /* store this information in the list-item's userdata area */
442 SendMessageW(Params
->hCombo
,
445 MAKEWPARAM(fFixed
, fTrueType
));
453 CCharMapWindow::CreateFontComboBox()
456 hCombo
= GetDlgItem(m_hMainWnd
, IDC_FONTCOMBO
);
458 NONCLIENTMETRICSW NonClientMetrics
;
459 NonClientMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
460 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
461 sizeof(NONCLIENTMETRICSW
),
465 // Get a handle to the font
467 GuiFont
= CreateFontIndirectW(&NonClientMetrics
.lfMessageFont
);
469 // Set the font used in the combo box
475 // Set the fonts which we want to enumerate
476 LOGFONTW FontsToEnum
;
477 ZeroMemory(&FontsToEnum
, sizeof(LOGFONTW
));
478 FontsToEnum
.lfCharSet
= DEFAULT_CHARSET
;
480 // Set the params we want to pass to the callback
481 EnumFontParams Params
;
483 Params
.hCombo
= hCombo
;
485 // Get a DC for combo box
489 // Enumerate all the fonts
491 ret
= EnumFontFamiliesExW(hdc
,
493 (FONTENUMPROCW
)EnumDisplayFont
,
497 ReleaseDC(hCombo
, hdc
);
498 DeleteObject(GuiFont
);
500 // Select the first item in the list