?? proppageframe.cpp
字號(hào):
// PropPageFrame.cpp : implementation file
//
#include "stdafx.h"
#include "PropPageFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// class CPropPageFrame
BEGIN_MESSAGE_MAP(CPropPageFrame, CWnd)
//{{AFX_MSG_MAP(CPropPageFrame)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CPropPageFrame::CPropPageFrame()
: m_bShowCaption(FALSE),
m_nCaptionHeight(0),
m_hCaptionIcon(NULL),
m_dwMsgFormat(DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE)
{
}
CPropPageFrame::~CPropPageFrame()
{
if (m_Images.GetSafeHandle())
m_Images.DeleteImageList();
}
/////////////////////////////////////////////////////////////////////
// Operations
BOOL CPropPageFrame::Create(DWORD dwWindowStyle, const RECT &rect, CWnd *pwndParent, UINT nID)
{
return CWnd::Create(
AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW, AfxGetApp()->LoadStandardCursor(IDC_ARROW), GetSysColorBrush(COLOR_3DFACE)),
_T("屬性頁(yè)框架"),
dwWindowStyle, rect, pwndParent, nID);
}
void CPropPageFrame::ShowCaption(BOOL bEnable)
{
m_bShowCaption = bEnable;
SafeUpdateWindow(CalcCaptionArea());
}
BOOL CPropPageFrame::GetShowCaption() const
{
return m_bShowCaption;
}
void CPropPageFrame::SetCaption(LPCTSTR lpszCaption, HICON hIcon /*= NULL*/)
{
m_strCaption = lpszCaption;
m_hCaptionIcon = hIcon;
SafeUpdateWindow(CalcCaptionArea());
//創(chuàng)建圖像列表
if (m_Images.GetSafeHandle())
m_Images.DeleteImageList();
if (hIcon)
{
ICONINFO ii;
if (!GetIconInfo(hIcon, &ii))
return;
CBitmap bmMask;
bmMask.Attach(ii.hbmMask);
if (ii.hbmColor) DeleteObject(ii.hbmColor);
BITMAP bm;
bmMask.GetBitmap(&bm);
if (!m_Images.Create(bm.bmWidth, bm.bmHeight, ILC_COLOR32|ILC_MASK, 0, 1))
return;
if (m_Images.Add(hIcon) == -1)
m_Images.DeleteImageList();
}
}
CString CPropPageFrame::GetCaption(HICON *pIcon /* = NULL */) const
{
if (pIcon)
*pIcon = m_hCaptionIcon;
return m_strCaption;
}
void CPropPageFrame::SetCaptionHeight(int nCaptionHeight)
{
m_nCaptionHeight = nCaptionHeight;
SafeUpdateWindow(CalcCaptionArea());
}
int CPropPageFrame::GetCaptionHeight() const
{
return m_nCaptionHeight;
}
void CPropPageFrame::SetMsgText(LPCTSTR lpszMsg)
{
m_strMsg = lpszMsg;
SafeUpdateWindow(CalcMsgArea());
}
CString CPropPageFrame::GetMsgText() const
{
return m_strMsg;
}
void CPropPageFrame::SetMsgFormat(DWORD dwFormat)
{
m_dwMsgFormat = dwFormat;
SafeUpdateWindow(CalcMsgArea());
}
DWORD CPropPageFrame::GetMsgFormat() const
{
return m_dwMsgFormat;
}
/////////////////////////////////////////////////////////////////////
// Overridable implementation helpers
void CPropPageFrame::Draw(CDC *pDc)
{
if (GetShowCaption())
DrawCaption(pDc, CalcCaptionArea(), m_strCaption, m_hCaptionIcon);
DrawMsg(pDc, CalcMsgArea(), m_strMsg, m_dwMsgFormat);
}
CRect CPropPageFrame::CalcMsgArea()
{
ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
CRect rectMsg;
GetWnd()->GetClientRect(rectMsg);
if (GetShowCaption())
rectMsg.top+= GetCaptionHeight();
return rectMsg;
}
void CPropPageFrame::DrawMsg(CDC *pDc, CRect rect, LPCTSTR lpszMsg, DWORD dwFormat)
{
CFont *pPrevFont = dynamic_cast<CFont*>(pDc->SelectStockObject(DEFAULT_GUI_FONT));
int nPrevBkMode = pDc->SetBkMode(TRANSPARENT);
pDc->DrawText(GetMsgText(), rect, GetMsgFormat());
pDc->SetBkMode(nPrevBkMode);
pDc->SelectObject(pPrevFont);
}
CRect CPropPageFrame::CalcCaptionArea()
{
ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
CRect rectCaption;
GetWnd()->GetClientRect(rectCaption);
if (!GetShowCaption())
rectCaption.bottom = rectCaption.top;
else
rectCaption.bottom = rectCaption.top+GetCaptionHeight();
return rectCaption;
}
void CPropPageFrame::DrawCaption(CDC *pDc, CRect rect, LPCTSTR lpszCaption, HICON hIcon)
{
COLORREF clrLeft = GetSysColor(COLOR_INACTIVECAPTION);
COLORREF clrRight = pDc->GetPixel(rect.right-1, rect.top);
FillGradientRectH(pDc, rect, clrLeft, clrRight);
//繪制圖標(biāo)
if (hIcon && m_Images.GetSafeHandle() && m_Images.GetImageCount() == 1)
{
IMAGEINFO ii;
m_Images.GetImageInfo(0, &ii);
CPoint pt(3, rect.CenterPoint().y - (ii.rcImage.bottom-ii.rcImage.top)/2);
m_Images.Draw(pDc, 0, pt, ILD_TRANSPARENT);
rect.left+= (ii.rcImage.right-ii.rcImage.left) + 3;
}
//繪制文本
rect.left+= 2;
COLORREF clrPrev = pDc->SetTextColor(GetSysColor(COLOR_CAPTIONTEXT));
int nBkStyle = pDc->SetBkMode(TRANSPARENT);
CFont *pFont = (CFont*)pDc->SelectStockObject(SYSTEM_FONT);
pDc->DrawText(lpszCaption, rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
pDc->SetTextColor(clrPrev);
pDc->SetBkMode(nBkStyle);
pDc->SelectObject(pFont);
}
/////////////////////////////////////////////////////////////////////
// Implementation helpers
void CPropPageFrame::SafeUpdateWindow(LPCRECT lpRect /* = NULL */)
{
if (!IsWindow(GetWnd()->GetSafeHwnd()))
return;
GetWnd()->InvalidateRect(lpRect, TRUE);
}
CWnd* CPropPageFrame::GetWnd()
{
return static_cast<CWnd*>(this);
}
void CPropPageFrame::FillGradientRectH(CDC *pDc, const RECT &rect, COLORREF clrLeft, COLORREF clrRight)
{
//預(yù)計(jì)算
int nSteps = rect.right-rect.left;
int nRRange = GetRValue(clrRight)-GetRValue(clrLeft);
int nGRange = GetGValue(clrRight)-GetGValue(clrLeft);
int nBRange = GetBValue(clrRight)-GetBValue(clrLeft);
double dRStep = (double)nRRange/(double)nSteps;
double dGStep = (double)nGRange/(double)nSteps;
double dBStep = (double)nBRange/(double)nSteps;
double dR = (double)GetRValue(clrLeft);
double dG = (double)GetGValue(clrLeft);
double dB = (double)GetBValue(clrLeft);
CPen *pPrevPen = NULL;
for (int x = rect.left; x <= rect.right; ++x)
{
CPen Pen(PS_SOLID, 1, RGB((BYTE)dR, (BYTE)dG, (BYTE)dB));
pPrevPen = pDc->SelectObject(&Pen);
pDc->MoveTo(x, rect.top);
pDc->LineTo(x, rect.bottom);
pDc->SelectObject(pPrevPen);
dR+= dRStep;
dG+= dGStep;
dB+= dBStep;
}
}
void CPropPageFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
Draw(&dc);
// Do not call CWnd::OnPaint() for painting messages
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -