source: trunk/DirectShowSpy/AboutDialog.h @ 276

Last change on this file since 276 was 276, checked in by roman, 10 years ago

Updated header (on use, applicability, redistribution)

File size: 5.8 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2014
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 don’t 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 <atlctrls.h>
19#include <atlctrlx.h>
20#include "rocontrols.h"
21
22#pragma comment(lib, "version.lib")
23
24////////////////////////////////////////////////////////////
25// CAboutDialog
26
27class CAboutDialog : 
28        public CDialogImpl<CAboutDialog>
29{
30public:
31        enum { IDD = IDD_ABOUT };
32
33BEGIN_MSG_MAP_EX(CAboutDialog)
34        MSG_WM_INITDIALOG(OnInitDialog)
35        MSG_WM_DESTROY(OnDestroy)
36        COMMAND_ID_HANDLER_EX(IDOK, OnCommand)
37        COMMAND_ID_HANDLER_EX(IDCANCEL, OnCommand)
38END_MSG_MAP()
39
40protected:
41        CFont m_TitleFont;
42        CFont m_DisclaimerFont;
43        CRoHyperStatic m_WebsiteHyperStatic;
44        CRoHyperStatic m_EmailHyperStatic;
45
46public:
47// CAboutDialog
48        static CFontHandle CreateTitleFont() throw()
49        {
50                CLogFont LogFont;
51                LogFont.lfHeight = -MulDiv(12, GetDeviceCaps(CClientDC(GetDesktopWindow()), LOGPIXELSY), 72);
52                LogFont.lfWeight = FW_BOLD;
53                LogFont.lfItalic = TRUE;
54                _tcsncpy_s(LogFont.lfFaceName, _countof(LogFont.lfFaceName), _T("Arial"), _TRUNCATE);
55                CFont Font;
56                _W(Font.CreateFontIndirect(&LogFont));
57                return Font.Detach();
58        }
59        static CFontHandle CreateDisclaimerFont() throw()
60        {
61                CLogFont LogFont;
62                LogFont.lfHeight = -MulDiv(7, GetDeviceCaps(CClientDC(GetDesktopWindow()), LOGPIXELSY), 72);
63                LogFont.lfWeight = FW_NORMAL;
64                _tcsncpy_s(LogFont.lfFaceName, _countof(LogFont.lfFaceName), _T("Lucida Console"), _TRUNCATE);
65                CFont Font;
66                _W(Font.CreateFontIndirect(&LogFont));
67                return Font.Detach();
68        }
69        CAboutDialog() throw()
70        {
71                _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this);
72        }
73        ~CAboutDialog() throw()
74        {
75                _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this);
76        }
77
78// Window message handlers
79        LRESULT OnInitDialog(HWND, LPARAM)
80        {
81                CStatic(GetDlgItem(IDC_ABOUT_ICON)).SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, 48, 48));
82                #pragma region Title Font
83                m_TitleFont = CreateTitleFont();
84                CStatic(GetDlgItem(IDC_ABOUT_TITLE)).SetFont(m_TitleFont);
85                #pragma endregion
86                #pragma region Disclaimer Font
87                {
88                        m_DisclaimerFont = CreateDisclaimerFont();
89                        CStatic CopyrightWarningText = GetDlgItem(IDC_ABOUT_COPYRIGHTWARNING);
90                        CopyrightWarningText.SetFont(m_DisclaimerFont);
91                        {
92                                CString sText = AtlLoadString(IDC_ABOUT_COPYRIGHTWARNING);
93                                CopyrightWarningText.SetWindowText(sText);
94                                CRect CurrentPosition;
95                                _W(CopyrightWarningText.GetWindowRect(CurrentPosition));
96                                CRect Position = CurrentPosition;
97                                {
98                                        CClientDC Dc(CopyrightWarningText);
99                                        CGdiSelector FontSelector(Dc, m_DisclaimerFont);
100                                        _W(Dc.DrawText(sText, -1, Position, DT_TOP | DT_LEFT | DT_WORDBREAK | DT_CALCRECT));
101                                }
102                                Position.right = CurrentPosition.right;
103                                CRect WindowPosition;
104                                _W(GetWindowRect(WindowPosition));
105                                _W(SetWindowPos(NULL, 0, 0, WindowPosition.Width(), WindowPosition.Height() + (Position.Height() - CurrentPosition.Height()), SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER));
106                                static const LONG g_nSafetyHeight = 4;
107                                _W(CopyrightWarningText.SetWindowPos(NULL, 0, 0, Position.Width(), Position.Height() + g_nSafetyHeight, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER));
108                        }
109                }
110                #pragma endregion
111                #pragma region Version Text
112                CStatic ProductVersionStatic = GetDlgItem(IDC_ABOUT_PRODUCTVERSION), FileVersionStatic = GetDlgItem(IDC_ABOUT_FILEVERSION);
113                CString sProductVersionFormat, sFileVersionFormat;
114                ProductVersionStatic.GetWindowText(sProductVersionFormat);
115                FileVersionStatic.GetWindowText(sFileVersionFormat);
116                CPath sModulePath = _VersionInfoHelper::GetModulePath();
117                ProductVersionStatic.SetWindowText(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetProductVersion(sModulePath), sProductVersionFormat));
118                FileVersionStatic.SetWindowText(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetFileVersion(sModulePath), sFileVersionFormat));
119                #pragma endregion
120                #pragma region Hyperlinks
121                _W(m_WebsiteHyperStatic.SubclassWindow(GetDlgItem(IDC_ABOUT_WEBSITE)));
122                _W(m_EmailHyperStatic.SubclassWindow(GetDlgItem(IDC_ABOUT_EMAIL)));
123                #pragma endregion
124                #pragma region Caption
125                {
126                        #if _TRACE || defined(_WIN64)
127                                CString sCaption;
128                                _W(GetWindowText(sCaption));
129                                sCaption.Append(_T(" // "));
130                                #if _DEVELOPMENT
131                                        sCaption.Append(_T("Dev "));
132                                #endif // _DEVELOPMENT
133                                sCaption.Append(_VersionInfoHelper::GetVersionString(_VersionInfoHelper::GetFileVersion(_VersionInfoHelper::GetModulePath())));
134                                #if defined(_WIN64)
135                                        sCaption.Append(_T(" (x64)"));
136                                #endif // defined(_WIN64)
137                                _W(SetWindowText(sCaption));
138                        #endif // _TRACE || defined(_WIN64)
139                }
140                #pragma endregion
141                #pragma region Window Position and Focus
142                _W(CenterWindow(GetParent()));
143                GetDlgItem(IDOK).SetFocus();
144                #pragma endregion
145                return FALSE;
146        }
147        LRESULT OnDestroy() throw()
148        {
149                _W(m_TitleFont.DeleteObject());
150                _W(m_DisclaimerFont.DeleteObject());
151                return 0;
152        }
153        LRESULT OnCommand(UINT, INT nIdentifier, HWND) throw()
154        {
155                _W(EndDialog(nIdentifier));
156                return 0;
157        }
158};
Note: See TracBrowser for help on using the repository browser.