summaryrefslogtreecommitdiff
path: root/win/aboutdlg.cpp
blob: 1c261ea2a14379e0f1e3ffd187b95dc26581e5d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// AboutDlg.cpp : implementation file
//

#include "stdafx.h"
#include "leocad.h"
#include "AboutDlg.h"
#include "config.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

CAboutDlg::~CAboutDlg()
{
	m_Font.DeleteObject();
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(IDC_ABTDLG_HOMEPAGE, OnHomepage)
	ON_WM_CTLCOLOR()
	ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg message handlers

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// Initialize the OpenGL information box.
	CString info, tmp;
	PIXELFORMATDESCRIPTOR pfd;
	OpenGLDescribePixelFormat(m_hViewDC, OpenGLGetPixelFormat(m_hViewDC), sizeof(PIXELFORMATDESCRIPTOR), &pfd);

	info = ("Pixel Format: ");
	if (pfd.iPixelType == PFD_TYPE_RGBA)
		info += "RGBA, ";
	else
		info += "Color Index, ";

	if (pfd.dwFlags & PFD_DOUBLEBUFFER)
		info += "Double Buffer ";
	else
		info += "Single Buffer ";

	if ((pfd.dwFlags & (PFD_GENERIC_ACCELERATED|PFD_GENERIC_FORMAT)) == 0)
		info += "(Installable Client Driver)\r\n";
	else if ((pfd.dwFlags & (PFD_GENERIC_ACCELERATED|PFD_GENERIC_FORMAT)) == (PFD_GENERIC_ACCELERATED|PFD_GENERIC_FORMAT))
		info += "(Mini-Client Driver)\r\n";
	else if ((pfd.dwFlags & (PFD_GENERIC_ACCELERATED|PFD_GENERIC_FORMAT)) == PFD_GENERIC_FORMAT)
		info += "(Generic Software Driver)\r\n";
	else if ((pfd.dwFlags & (PFD_GENERIC_ACCELERATED|PFD_GENERIC_FORMAT)) == PFD_GENERIC_ACCELERATED)
		info += "(Unknown Driver Type)\r\n";

	tmp.Format("Color bits: %d, Depth Buffer: %d bits\r\nOpenGL Version ", pfd.cColorBits, pfd.cDepthBits);
	info += tmp;
	info += (const char*)glGetString(GL_VERSION);
	info += " (";
	info += (const char*)glGetString(GL_RENDERER);
	info += " - ";
	info += (const char*)glGetString(GL_VENDOR);
	info += ")";

	SetDlgItemText(IDC_ABTDLG_INFO, info);

	// Underline the homepage link.
	LOGFONT lf;
	CFont* pFont = GetDlgItem(IDC_ABTDLG_HOMEPAGE)->GetFont();
	if (pFont != NULL)
	{
		pFont->GetLogFont(&lf);
		lf.lfUnderline = TRUE;
		m_Font.DeleteObject();
		m_Font.CreateFontIndirect(&lf);
		GetDlgItem(IDC_ABTDLG_HOMEPAGE)->SetFont(&m_Font);
	}	

	// The following function appeared in Paul DiLascia's Jan 1998 MSJ articles.
	// It loads a "hand" cursor from "winhlp32.exe" resources

	// Get the windows directory
	CString strWndDir;
	GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH);
	strWndDir.ReleaseBuffer();
	strWndDir += _T("\\winhlp32.exe");

	// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer
	HMODULE hModule = LoadLibrary(strWndDir);
	if (hModule)
	{
		HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
		m_hLinkCursor = CopyCursor(hHandCursor);
		FreeLibrary(hModule);
	}

	AdjustHomepageWindow();

	// Fix the version number.
	SetDlgItemText(IDC_ABTDLG_VERSION, "LeoCAD Version " LC_VERSION_TEXT LC_VERSION_TAG);

	return TRUE;
}

// Move and resize the window so that its client area has the same size as the hyperlink text.
// This prevents the hyperlink cursor being active when it is not over the text.
void CAboutDlg::AdjustHomepageWindow()
{	
	CWnd *pWnd = GetDlgItem(IDC_ABTDLG_HOMEPAGE);
	ASSERT(::IsWindow(pWnd->GetSafeHwnd()));

	// Get the current window rect
	CRect rcWnd;
	pWnd->GetWindowRect(rcWnd);

	// For a child CWnd object, window rect is relative to the 
	// upper-left corner of the parent window�s client area. 
	ScreenToClient(rcWnd);

	// Get the current client rect
	CRect rcClient;
	pWnd->GetClientRect(rcClient);

	// Calc border size based on window and client rects
	int borderWidth = rcWnd.Width() - rcClient.Width();
	int borderHeight = rcWnd.Height() - rcClient.Height();

	// Get the extent of window text 
	CString strWndText;
	pWnd->GetWindowText(strWndText);
	
	CDC* pDC = pWnd->GetDC();	
	CFont* pOldFont = pDC->SelectObject(&m_Font);
	CSize Extent = pDC->GetTextExtent(strWndText);
	pDC->SelectObject(pOldFont);
	ReleaseDC(pDC);

	// Get the text justification style
	DWORD dwStyle = pWnd->GetStyle();

	// Recalc window size and position based on text justification
	if (dwStyle & SS_CENTERIMAGE)
		rcWnd.DeflateRect(0, (rcWnd.Height() - Extent.cy) / 2);
	else
		rcWnd.bottom = rcWnd.top + Extent.cy;

	if (dwStyle & SS_CENTER)
		rcWnd.DeflateRect((rcWnd.Width() - Extent.cx) / 2, 0);
	else if (dwStyle & SS_RIGHT)
		rcWnd.left  = rcWnd.right - Extent.cx;
	else // SS_LEFT
		rcWnd.right = rcWnd.left + Extent.cx;

	// Move and resize the window
	pWnd->MoveWindow(rcWnd.left, rcWnd.top, rcWnd.Width() + borderWidth, rcWnd.Height() + borderHeight);
}

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if (pWnd->GetDlgCtrlID() == IDC_ABTDLG_HOMEPAGE)
		pDC->SetTextColor(RGB(0, 0, 255));

	return hbr;
}

BOOL CAboutDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	if (pWnd->GetDlgCtrlID() == IDC_ABTDLG_HOMEPAGE)
	{
		if (m_hLinkCursor)
			::SetCursor(m_hLinkCursor);

		return TRUE;
	}

	return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

void CAboutDlg::OnHomepage() 
{
	ShellExecute(::GetDesktopWindow(), _T("open"), _T("http://www.leocad.org"), NULL, NULL, SW_NORMAL); 
}