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