📄 wzddlg.cpp
字号:
// WzdDlg.cpp : implementation file
//
#include "stdafx.h"
#include "wzd.h"
#include "WzdDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWzdDialog dialog
CWzdDialog::CWzdDialog(CWnd* pParent /*=NULL*/)
: CDialog(CWzdDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CWzdDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bPressed=FALSE;
m_bitmapPressed.LoadBitmapEx(IDB_PRESSED_BITMAP,TRUE);
m_bitmapUnpressed.LoadBitmapEx(IDB_UNPRESSED_BITMAP,TRUE);
}
void CWzdDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWzdDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWzdDialog, CDialog)
//{{AFX_MSG_MAP(CWzdDialog)
ON_WM_NCPAINT()
ON_WM_NCLBUTTONDOWN()
ON_WM_ACTIVATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWzdDialog message handlers
void CWzdDialog::OnNcPaint()
{
// draw caption first
CDialog::OnNcPaint();
// then draw button on top
DrawButton();
}
// caption is also redrawn with WM_ACTIVATE message for color change
void CWzdDialog::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
DrawButton();
}
void CWzdDialog::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
if (nHitTest == HTCAPTION)
{
// see if in area we reserved for button
CRect rect;
GetButtonRect(rect);
if (rect.PtInRect(point))
{
m_bPressed = !m_bPressed;
DrawButton();
}
}
CDialog::OnNcLButtonDown(nHitTest, point);
}
void CWzdDialog::GetButtonRect(CRect& rect)
{
GetWindowRect(&rect);
rect.top += GetSystemMetrics(SM_CYFRAME)+1; // for small caption use SM_CYDLGFRAME
rect.bottom = rect.top + GetSystemMetrics(SM_CYSIZE)-4; // for small caption use SM_CYSMSIZE
rect.left = rect.right - GetSystemMetrics(SM_CXFRAME) - // for small caption use SM_CXDLGFRAME
( 2 * // set to number of buttons already in caption + 1
GetSystemMetrics(SM_CXSIZE))-1; // for small caption use SM_CXSMSIZE
rect.right = rect.left + GetSystemMetrics(SM_CXSIZE)-3; // for small caption use SM_CXSMSIZE
}
void CWzdDialog::DrawButton()
{
// if window isn't visible or is minimized, skip
if (!IsWindowVisible() || IsIconic())
return;
// get appropriate bitmap
CDC memDC;
CDC* pDC = GetWindowDC();
memDC.CreateCompatibleDC(pDC);
memDC.SelectObject(m_bPressed ? &m_bitmapPressed : &m_bitmapUnpressed);
// get button rect and convert into non-client area coordinates
CRect rect, rectWnd;
GetButtonRect(rect);
GetWindowRect(rectWnd);
rect.OffsetRect(-rectWnd.left, -rectWnd.top);
// draw it
pDC->StretchBlt( rect.left, rect.top, rect.Width(), rect.Height(),
&memDC, 0, 0, m_bitmapPressed.m_Width, m_bitmapPressed.m_Height, SRCCOPY );
memDC.DeleteDC();
ReleaseDC(pDC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -