1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2011 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | |
---|
5 | #pragma once |
---|
6 | |
---|
7 | #include <atlctrls.h> |
---|
8 | #include <atlctrlx.h> |
---|
9 | #include "rocontrols.h" |
---|
10 | |
---|
11 | #pragma comment(lib, "version.lib") |
---|
12 | |
---|
13 | //////////////////////////////////////////////////////////// |
---|
14 | // CAboutDialog |
---|
15 | |
---|
16 | class CAboutDialog : |
---|
17 | public CDialogImpl<CAboutDialog> |
---|
18 | { |
---|
19 | public: |
---|
20 | |
---|
21 | enum { IDD = IDD_ABOUT }; |
---|
22 | |
---|
23 | BEGIN_MSG_MAP_EX(CAboutDialog) |
---|
24 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
25 | MSG_WM_DESTROY(OnDestroy) |
---|
26 | COMMAND_ID_HANDLER_EX(IDOK, OnCommand) |
---|
27 | COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand) |
---|
28 | END_MSG_MAP() |
---|
29 | |
---|
30 | protected: |
---|
31 | CFont m_TitleFont; |
---|
32 | CFont m_DisclaimerFont; |
---|
33 | CRoHyperStatic m_WebsiteHyperStatic; |
---|
34 | CRoHyperStatic m_EmailHyperStatic; |
---|
35 | |
---|
36 | public: |
---|
37 | // CAboutDialog |
---|
38 | CAboutDialog() throw() |
---|
39 | { |
---|
40 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
41 | } |
---|
42 | ~CAboutDialog() throw() |
---|
43 | { |
---|
44 | _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); |
---|
45 | } |
---|
46 | |
---|
47 | // Window message handlers |
---|
48 | LRESULT OnInitDialog(HWND, LPARAM) |
---|
49 | { |
---|
50 | CStatic(GetDlgItem(IDC_ABOUT_ICON)).SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, 48, 48)); |
---|
51 | #pragma region Create and apply title font |
---|
52 | { |
---|
53 | CLogFont LogFont; |
---|
54 | LogFont.lfHeight = -MulDiv(12, GetDeviceCaps(CClientDC(m_hWnd), LOGPIXELSY), 72); |
---|
55 | LogFont.lfWeight = FW_BOLD; |
---|
56 | LogFont.lfItalic = TRUE; |
---|
57 | _tcsncpy_s(LogFont.lfFaceName, _countof(LogFont.lfFaceName), _T("Arial"), _TRUNCATE); |
---|
58 | _W(m_TitleFont.CreateFontIndirect(&LogFont)); |
---|
59 | CStatic(GetDlgItem(IDC_ABOUT_TITLE)).SetFont(m_TitleFont); |
---|
60 | } |
---|
61 | #pragma endregion |
---|
62 | #pragma region Create and apply disclaimer font |
---|
63 | { |
---|
64 | CLogFont LogFont; |
---|
65 | LogFont.lfHeight = -MulDiv(7, GetDeviceCaps(CClientDC(m_hWnd), LOGPIXELSY), 72); |
---|
66 | LogFont.lfWeight = FW_NORMAL; |
---|
67 | _tcsncpy_s(LogFont.lfFaceName, _countof(LogFont.lfFaceName), _T("Lucida Console"), _TRUNCATE); |
---|
68 | _W(m_DisclaimerFont.CreateFontIndirect(&LogFont)); |
---|
69 | CStatic CopyrightWarningText = GetDlgItem(IDC_ABOUT_COPYRIGHTWARNING); |
---|
70 | CopyrightWarningText.SetFont(m_DisclaimerFont); |
---|
71 | { |
---|
72 | CString sText = AtlLoadString(IDC_ABOUT_COPYRIGHTWARNING); |
---|
73 | CopyrightWarningText.SetWindowText(sText); |
---|
74 | CRect CurrentPosition; |
---|
75 | _W(CopyrightWarningText.GetWindowRect(CurrentPosition)); |
---|
76 | CRect Position = CurrentPosition; |
---|
77 | { |
---|
78 | CClientDC Dc(CopyrightWarningText); |
---|
79 | CGdiSelector FontSelector(Dc, m_DisclaimerFont); |
---|
80 | _W(Dc.DrawText(sText, -1, Position, DT_TOP | DT_LEFT | DT_WORDBREAK | DT_CALCRECT)); |
---|
81 | } |
---|
82 | Position.right = CurrentPosition.right; |
---|
83 | CRect WindowPosition; |
---|
84 | _W(GetWindowRect(WindowPosition)); |
---|
85 | _W(SetWindowPos(NULL, 0, 0, WindowPosition.Width(), WindowPosition.Height() + (Position.Height() - CurrentPosition.Height()), SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER)); |
---|
86 | static const LONG g_nSafetyHeight = 4; |
---|
87 | _W(CopyrightWarningText.SetWindowPos(NULL, 0, 0, Position.Width(), Position.Height() + g_nSafetyHeight, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER)); |
---|
88 | } |
---|
89 | } |
---|
90 | #pragma endregion |
---|
91 | #pragma region Update version text |
---|
92 | CStatic ProductVersionStatic = GetDlgItem(IDC_ABOUT_PRODUCTVERSION), FileVersionStatic = GetDlgItem(IDC_ABOUT_FILEVERSION); |
---|
93 | CString sProductVersionFormat, sFileVersionFormat; |
---|
94 | ProductVersionStatic.GetWindowText(sProductVersionFormat); |
---|
95 | FileVersionStatic.GetWindowText(sFileVersionFormat); |
---|
96 | CPath sModulePath = _VersionInfoHelper::GetModulePath(); |
---|
97 | ProductVersionStatic.SetWindowText(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetProductVersion(sModulePath), sProductVersionFormat)); |
---|
98 | FileVersionStatic.SetWindowText(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetFileVersion(sModulePath), sFileVersionFormat)); |
---|
99 | #pragma endregion |
---|
100 | #pragma region Update hyperlinks |
---|
101 | _W(m_WebsiteHyperStatic.SubclassWindow(GetDlgItem(IDC_ABOUT_WEBSITE))); |
---|
102 | _W(m_EmailHyperStatic.SubclassWindow(GetDlgItem(IDC_ABOUT_EMAIL))); |
---|
103 | #pragma endregion |
---|
104 | #pragma region Update caption |
---|
105 | { |
---|
106 | #if _TRACE |
---|
107 | CString sCaption; |
---|
108 | _W(GetWindowText(sCaption)); |
---|
109 | sCaption.Append(_T(" // ")); |
---|
110 | #if _DEVELOPMENT |
---|
111 | sCaption.Append(_T("Dev ")); |
---|
112 | #endif // _DEVELOPMENT |
---|
113 | sCaption.Append(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetFileVersion(_VersionInfoHelper::GetModulePath()))); |
---|
114 | _W(SetWindowText(sCaption)); |
---|
115 | #endif // _TRACE |
---|
116 | } |
---|
117 | #pragma endregion |
---|
118 | #pragma region Update window position and focus |
---|
119 | _W(CenterWindow(GetParent())); |
---|
120 | GetDlgItem(IDOK).SetFocus(); |
---|
121 | #pragma endregion |
---|
122 | return FALSE; |
---|
123 | } |
---|
124 | LRESULT OnDestroy() throw() |
---|
125 | { |
---|
126 | _W(m_TitleFont.DeleteObject()); |
---|
127 | _W(m_DisclaimerFont.DeleteObject()); |
---|
128 | return 0; |
---|
129 | } |
---|
130 | LRESULT OnCommand(UINT, INT nIdentifier, HWND) throw() |
---|
131 | { |
---|
132 | _W(EndDialog(nIdentifier)); |
---|
133 | return 0; |
---|
134 | } |
---|
135 | }; |
---|