📄 taboutdlg.cpp
字号:
/*****************************************************************************/
/* TAboutDlg.cpp */
/*---------------------------------------------------------------------------*/
/* Implementation file for the about dialog */
/*****************************************************************************/
#include "stdafx.h"
#include "resource.h"
#include "TAboutDlg.h"
#include "WideStrHelp.h"
#pragma comment(lib, "Version.lib")
//-----------------------------------------------------------------------------
// Message map for TAboutDlg
BEGIN_MESSAGE_MAP(TAboutDlg, CDialog)
//{{AFX_MSG_MAP(TAboutDlg)
ON_WM_DRAWITEM()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
// Functions working with URL buttons
static WNDPROC OldWindowProc;
static HCURSOR hCursor = NULL;
static LRESULT CALLBACK SetCursorProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(msg == WM_SETCURSOR)
{
SetCursor(hCursor);
return 0;
}
return CallWindowProc(OldWindowProc, hwnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// TAboutDlg functions
TAboutDlg::TAboutDlg() : CDialog(TAboutDlg::IDD)
{}
void TAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TAboutDlg)
//}}AFX_DATA_MAP
}
// Draw hypertext button. It is drawn with the blue color,
// when normal and with the red color when clicked.
int TAboutDlg::DrawURLButton(LPDRAWITEMSTRUCT dis)
{
TCHAR szText[240];
UINT length = 0;
if(dis == NULL)
return ERROR_INVALID_PARAMETER;
if(dis->CtlType == ODT_BUTTON)
{
// Retrieve text from button
length = GetDlgItemText(dis->CtlID, szText, _tsize(szText));
// Select color and draw it.
if(dis->itemState & ODS_SELECTED)
SetTextColor(dis->hDC, RGB(0xFF, 0x00, 0x00));
else
SetTextColor(dis->hDC, RGB(0x00, 0x00, 0xFF));
TextOut(dis->hDC, 0, 0, szText, length);
}
return ERROR_SUCCESS;
}
// This function sets the font for the URL buttons. They must be a button class,
// with owner-draw style set.
int TAboutDlg::InitURLButtons()
{
CWnd * pWnd = GetWindow(GW_CHILD);
LOGFONT logFont;
HFONT hFont = NULL;
// Retrieve the settings of the dialog font.
// The buttons should have the same font like the dialog font.
GetFont()->GetLogFont(&logFont);
logFont.lfUnderline = TRUE;
hFont = CreateFontIndirect(&logFont);
if(hFont == NULL)
return GetLastError();
// Load URL-Point cursor for this buttons
hCursor = AfxGetApp()->LoadCursor(MAKEINTRESOURCE(IDC_URLPOINT));
if(hCursor == NULL)
return GetLastError();
while(pWnd != NULL)
{
if(IsURLButton(pWnd->m_hWnd))
{
// Set the new window font and procedure
pWnd->SendMessage(WM_SETFONT, (LPARAM)hFont, 0);
OldWindowProc = (WNDPROC)SetWindowLong(pWnd->m_hWnd, GWL_WNDPROC, (DWORD)SetCursorProc);
}
// Get the next window
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
return ERROR_SUCCESS;
}
BOOL TAboutDlg::IsURLButton(HWND hWnd)
{
TCHAR szClassName[0x20];
DWORD dwStyle;
szClassName[0] = 0;
::GetClassName(hWnd, szClassName, _tsize(szClassName)-1);
dwStyle = ::GetWindowLong(hWnd, GWL_STYLE);
// Must be a button
if(stricmp(szClassName, "Button"))
return FALSE;
// Must not be a groupbox
if((dwStyle & BS_GROUPBOX) == BS_GROUPBOX)
return FALSE;
// If ownerdrawn, the OK.
return ((dwStyle & BS_OWNERDRAW) == BS_OWNERDRAW) ? TRUE : FALSE;
}
// This callback handles the mouse click on an URL button (WWW, mail, http).
// It invokes the default web browser/mail client for the button
// (Recognized from button text)
void TAboutDlg::ClickURLButton(HWND hURL)
{
HCURSOR hWaitCursor = ::LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_URLWAIT));
TCHAR szUrl[128] = _T("");
TCHAR szText[128];
// Retrieve button text
::GetWindowText(hURL, szText, _tsize(szText));
// Test E-mail addresses. They must have "mailto:" at the begin
if(_tcschr(szText, _T('@')) != NULL)
{
_tcscpy(szUrl, _T("mailto:"));
_tcscat(szUrl, szText);
}
// Test "http://"
if(!_tcsnicmp(szText, _T("http://"), 7))
_tcscpy(szUrl, szText);
// If only "www." at the begin, we have to add "http://"
if(!_tcsnicmp(szText, _T("www."), 4))
{
_tcscpy(szUrl, _T("http://"));
_tcscat(szUrl, szText);
}
// If any valid URL address, invoke the default application
if(szUrl[0] != 0)
{
// Set waiting cursor and launch default browser
::SetCursor(hWaitCursor);
ShellExecute(NULL, _T("open"), szUrl, NULL, NULL, SW_SHOWNORMAL);
::SetCursor(hCursor);
}
}
//-----------------------------------------------------------------------------
// Message handlers
BOOL TAboutDlg::OnInitDialog()
{
VS_FIXEDFILEINFO * vs = NULL;
LPVOID pVerInfo = NULL;
CWnd * pStatic = NULL;
TCHAR szExeName[MAX_PATH];
TCHAR szOldText[128];
TCHAR szNewText[128];
DWORD dwHandle = 0;
DWORD dwSize = 0;
UINT uiSize;
int nVerNum[4] = {1, 0, 0, 1};
CDialog::OnInitDialog();
// Set the dialog icon
HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
SetIcon(hIcon, TRUE); // Set big icon
SetIcon(hIcon, FALSE); // Set small icon
// Retrieve the version number from resources
GetModuleFileName(AfxGetResourceHandle(), szExeName, _tsize(szExeName)-1);
dwSize = GetFileVersionInfoSize(szExeName, &dwHandle);
if(dwSize != 0)
{
pVerInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
if(GetFileVersionInfo(szExeName, dwHandle, dwSize, pVerInfo))
{
VerQueryValue(pVerInfo, _T("\\"), (LPVOID *)&vs, &uiSize);
nVerNum[0] = HIWORD(vs->dwFileVersionMS);
nVerNum[1] = LOWORD(vs->dwFileVersionMS);
nVerNum[2] = HIWORD(vs->dwFileVersionLS);
nVerNum[3] = LOWORD(vs->dwFileVersionLS);
}
if(pVerInfo != NULL)
HeapFree(GetProcessHeap(), 0, pVerInfo);
}
// Set the information about build number
if((pStatic = GetDlgItem(IDC_BUILDNUM)) != NULL)
{
pStatic->GetWindowText(szOldText, _tsize(szOldText));
_stprintf(szNewText, szOldText, nVerNum[0], nVerNum[1], nVerNum[2], nVerNum[3]);
pStatic->SetWindowText(szNewText);
pStatic->ShowWindow(SW_SHOW);
}
// Initialize buttons for e-mails and WWW pages
InitURLButtons();
return TRUE;
}
BOOL TAboutDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// If no lParam, retrieve child handle from wParam
if(HIWORD(wParam) == BN_CLICKED)
{
HWND hChild = (HWND)lParam;
if(hChild == NULL)
hChild = ::GetDlgItem(m_hWnd, LOWORD(wParam));
if(IsURLButton(hChild))
{
ClickURLButton(hChild);
return TRUE;
}
}
return CDialog::OnCommand(wParam, lParam);
}
void TAboutDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CWnd * pWnd = GetDlgItem(nIDCtl);
char szClassName[0x20];
DWORD dwStyle;
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
// Draw the URL buttons. They must be owner-drawn.
if(pWnd != NULL)
{
::GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)-1);
dwStyle = ::GetWindowLong(pWnd->m_hWnd, GWL_STYLE);
if(IsURLButton(pWnd->m_hWnd))
DrawURLButton(lpDrawItemStruct);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -