用VC++6.0为对话框添加最小化按钮(3)
2015-06-17 01:45
导读:void CMinButtonDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) { CDialog::OnActivate(nState, pWndOther, bMinimized); DrawButton(); //绘制最小化按钮 } //对应消息WM_NCMOUSEMOVE的
void CMinButtonDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
DrawButton(); //绘制最小化按钮
}
//对应消息WM_NCMOUSEMOVE的消息处理函数
void CMinButtonDlg::OnNcMouseMove(UINT nHitTest, CPoint point)
{
DrawButton(); //绘制最小化按
CDialog::OnNcMouseMove(nHitTest, point);
}
⑶ 绘制最小化按钮的函数
void CMinButtonDlg::DrawButton()
{
CDC* pDC = GetWindowDC();
CDC* pMemDC=new CDC;
CBitmap *pBitmap1=new CBitmap;
CBitmap *pBitmap2=new CBitmap;
CBitmap *pOldBitmap;
CRect rtWnd, rtButtons, rtTitle;
//创建一个内存设备环境
pMemDC->CreateCompatibleDC(pDC);
if(!pDC) return;
GetWindowRect(&rtWnd);
//取得标题栏的矩形
rtTitle.left = GetSystemMetrics(SM_CXFRAME);
rtTitle.top = GetSystemMetrics(SM_CYFRAME);
rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME);
rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
//最小化按钮的位置,位图大小为15X15
rtButtons.top=rtTitle.top+1;
rtButtons.bottom=rtButtons.top+15;
rtButtons.right = rtTitle.right-20;
rtButtons.left = rtButtons.right-15; m_rtButtMin = rtButtons;
(转载自http://zw.NSEAC.com科教作文网)
pBitmap1->LoadBitmap(IDB_BITMAP1); //调入正常状态按钮的位图
pBitmap2->LoadBitmap(IDB_BITMAP2); //调入按钮按下状态的位图
m_rtButtMin.OffsetRect(rtWnd.TopLeft());//记录最小化按钮的位置
//将按钮位图调入内存设备环境中,m_BMPPressed为TRUE
//调入正常状态按钮的位图
pOldBitmap=pMemDC->SelectObject(m_BMPPressed ? pBitmap1: pBitmap2);
//将按钮位图复制到实际的内存设备环境中
pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(),
rtButtons.Height(), pMemDC, 0, 0, SRCCOPY);
pMemDC->SelectObject(pOldBitmap);//恢复原来的内存设备环境
//释放资源