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