source: trunk/Utilities/RotView/AboutDialog.h @ 937

Last change on this file since 937 was 494, checked in by roman, 9 years ago

VS2013 upgrade and Windows 8 fix

File size: 5.5 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2006-2015
3// Created by Roman Ryltsov roman@alax.info
4//
5// A permission to use the source code is granted as long as reference to
6// source website http://alax.info is retained.
7
8#pragma once
9
10#include <atlsecurity.h>
11#include <atlctrls.h>
12#include <atlctrlx.h>
13#include "rocontrols.h"
14
15#pragma comment(lib, "version.lib")
16
17////////////////////////////////////////////////////////////
18// CAboutDialog
19
20class CAboutDialog : 
21        public CDialogImpl<CAboutDialog>
22{
23public:
24        enum { IDD = IDD_ABOUT };
25
26BEGIN_MSG_MAP_EX(CAboutDialog)
27        MSG_WM_INITDIALOG(OnInitDialog)
28        MSG_WM_DESTROY(OnDestroy)
29        COMMAND_ID_HANDLER_EX(IDOK, OnCommand)
30        COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand)
31END_MSG_MAP()
32
33protected:
34        CFont m_TitleFont;
35        CFont m_DisclaimerFont;
36        CRoHyperStatic m_WebsiteHyperStatic;
37        CRoHyperStatic m_EmailHyperStatic;
38
39public:
40// CAboutDialog
41        static CFontHandle CreateTitleFont()
42        {
43                CLogFont LogFont;
44                LogFont.lfHeight = -MulDiv(12, GetDeviceCaps(CClientDC(GetDesktopWindow()), LOGPIXELSY), 72);
45                LogFont.lfWeight = FW_BOLD;
46                LogFont.lfItalic = TRUE;
47                _tcsncpy_s(LogFont.lfFaceName, _T("Arial"), _TRUNCATE);
48                CFont Font;
49                _W(Font.CreateFontIndirect(&LogFont));
50                return Font.Detach();
51        }
52        static CFontHandle CreateDisclaimerFont()
53        {
54                CLogFont LogFont;
55                LogFont.lfHeight = -MulDiv(7, GetDeviceCaps(CClientDC(GetDesktopWindow()), LOGPIXELSY), 72);
56                LogFont.lfWeight = FW_NORMAL;
57                _tcsncpy_s(LogFont.lfFaceName, _T("Lucida Console"), _TRUNCATE);
58                CFont Font;
59                _W(Font.CreateFontIndirect(&LogFont));
60                return Font.Detach();
61        }
62        CAboutDialog()
63        {
64                _Z4_THIS();
65        }
66        ~CAboutDialog()
67        {
68                _Z4_THIS();
69        }
70        static BOOL IsAdministrator()
71        {
72                bool bIsMember = FALSE;
73                return CAccessToken().CheckTokenMembership(Sids::Admins(), &bIsMember) && bIsMember;
74        }
75        static VOID UpdateCaption(CWindow Window)
76        {
77                CString sCaption;
78                _W(Window.GetWindowText(sCaption));
79                CRoArrayT<CString> SpecifierArray;
80                #if defined(_WIN64)
81                        SpecifierArray.Add(_T("64-bit"));
82                #else
83                        if(SafeIsWow64Process())
84                                SpecifierArray.Add(_T("32-bit"));
85                #endif // defined(_WIN64)
86                if(IsWindowsVistaOrGreater() && IsAdministrator())
87                        SpecifierArray.Add(_T("Administrator"));
88                if(!SpecifierArray.IsEmpty())
89                        sCaption = AtlFormatString(_T("%s (%s)"), sCaption, _StringHelper::Join(SpecifierArray, _T(", ")));
90                #if _TRACE
91                        sCaption.Append(_T(" // "));
92                        #if _DEVELOPMENT
93                                sCaption.Append(_T("Dev "));
94                        #endif // _DEVELOPMENT
95                        sCaption.Append(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetFileVersion(_VersionInfoHelper::GetModulePath())));
96                #endif // _TRACE
97                Window.SetWindowText(sCaption);
98        }
99
100// Window message handlers
101        LRESULT OnInitDialog(HWND, LPARAM)
102        {
103                CStatic(GetDlgItem(IDC_ABOUT_ICON)).SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, 48, 48));
104                #pragma region Title Font
105                m_TitleFont = CreateTitleFont();
106                CStatic(GetDlgItem(IDC_ABOUT_TITLE)).SetFont(m_TitleFont);
107                #pragma endregion
108                #pragma region Disclaimer Font
109                {
110                        m_DisclaimerFont = CreateDisclaimerFont();
111                        CStatic CopyrightWarningText = GetDlgItem(IDC_ABOUT_COPYRIGHTWARNING);
112                        CopyrightWarningText.SetFont(m_DisclaimerFont);
113                        {
114                                CString sText = AtlLoadString(IDC_ABOUT_COPYRIGHTWARNING);
115                                CopyrightWarningText.SetWindowText(sText);
116                                CRect CurrentPosition;
117                                _W(CopyrightWarningText.GetWindowRect(CurrentPosition));
118                                CRect Position = CurrentPosition;
119                                {
120                                        CClientDC Dc(CopyrightWarningText);
121                                        CGdiSelector FontSelector(Dc, m_DisclaimerFont);
122                                        _W(Dc.DrawText(sText, -1, Position, DT_TOP | DT_LEFT | DT_WORDBREAK | DT_CALCRECT));
123                                }
124                                Position.right = CurrentPosition.right;
125                                CRect WindowPosition;
126                                _W(GetWindowRect(WindowPosition));
127                                _W(SetWindowPos(NULL, 0, 0, WindowPosition.Width(), WindowPosition.Height() + (Position.Height() - CurrentPosition.Height()), SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER));
128                                static const LONG g_nSafetyHeight = 4;
129                                _W(CopyrightWarningText.SetWindowPos(NULL, 0, 0, Position.Width(), Position.Height() + g_nSafetyHeight, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER));
130                        }
131                }
132                #pragma endregion
133                #pragma region Version Text
134                CStatic ProductVersionStatic = GetDlgItem(IDC_ABOUT_PRODUCTVERSION), FileVersionStatic = GetDlgItem(IDC_ABOUT_FILEVERSION);
135                CString sProductVersionFormat, sFileVersionFormat;
136                ProductVersionStatic.GetWindowText(sProductVersionFormat);
137                FileVersionStatic.GetWindowText(sFileVersionFormat);
138                CPath sModulePath = _VersionInfoHelper::GetModulePath();
139                ProductVersionStatic.SetWindowText(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetProductVersion(sModulePath), sProductVersionFormat));
140                FileVersionStatic.SetWindowText(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetFileVersion(sModulePath), sFileVersionFormat));
141                #pragma endregion
142                #pragma region Hyperlinks
143                _W(m_WebsiteHyperStatic.SubclassWindow(GetDlgItem(IDC_ABOUT_WEBSITE)));
144                _W(m_EmailHyperStatic.SubclassWindow(GetDlgItem(IDC_ABOUT_EMAIL)));
145                #pragma endregion
146                UpdateCaption(*this);
147                #pragma region Window Position and Focus
148                _W(CenterWindow(GetParent()));
149                GetDlgItem(IDOK).SetFocus();
150                #pragma endregion
151                return FALSE;
152        }
153        LRESULT OnDestroy()
154        {
155                _W(m_TitleFont.DeleteObject());
156                _W(m_DisclaimerFont.DeleteObject());
157                return 0;
158        }
159        LRESULT OnCommand(UINT, INT nIdentifier, HWND)
160        {
161                _W(EndDialog(nIdentifier));
162                return 0;
163        }
164};
Note: See TracBrowser for help on using the repository browser.