x = bitinfo.bmiHeader.biWidth; y = bitinfo.bmiHeader.biHeight;
pWindowDC->StretchBlt(m_CloseRect.left,m_CloseRect.top,m_CloseRect.right,m_CloseRect.bottom,&memDC,0,0,x,y,SRCCOPY); LeftLine.DeleteObject(); m_IsDrawForm = TRUE;
/*****************************绘制关闭按钮***************************************/ ReleaseDC(&memDC); DrawFormCaption();
//*************************************************************************************** 五. 处理窗体的WM_NCMOUSEMOVE消息,确定标题栏按钮的状态,代码如下:
CDialog::OnNcMouseMove(nHitTest, point);
CRect tempIni,tempMin,tempMax,tempClose,ClientRect;
CDC* pWindowDC = GetWindowDC(); CDC memDC;
memDC.CreateCompatibleDC(pWindowDC); BITMAPINFO bInfo; CBitmap LeftLine; int x,y;
GetWindowRect(ClientRect); //GetClientRect();
tempIni.CopyRect(CRect(m_IniRect.left+
ClientRect.left,ClientRect.top+m_IniRect.top,m_IniRect.right+m_IniRect.left+ ClientRect.left,m_IniRect.bottom+m_IniRect.top+ClientRect.top)); tempMin.CopyRect(CRect(m_MinRect.left+
ClientRect.left,ClientRect.top+m_MinRect.top,m_MinRect.right+m_MinRect.left+ ClientRect.left,m_MinRect.bottom+m_MinRect.top+ClientRect.top)); tempMax.CopyRect(CRect(m_MaxRect.left+
ClientRect.left,ClientRect.top+m_MaxRect.top,m_MaxRect.right+m_MaxRect.left+ ClientRect.left,m_MaxRect.bottom+m_MaxRect.top+ClientRect.top)); tempClose.CopyRect(CRect(m_CloseRect.left+
ClientRect.left,ClientRect.top+m_CloseRect.top,m_CloseRect.right+m_CloseRect.left+
ClientRect.left,m_CloseRect.bottom+m_CloseRect.top+ClientRect.top));
if (tempIni.PtInRect(point)) //鼠标在初始化按钮上移动时,更改按钮显示的位图 {
LeftLine.LoadBitmap(IDB_BITMAP7); LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth; y = bInfo.bmiHeader.biHeight; memDC.SelectObject(&LeftLine);
pWindowDC->StretchBlt(m_IniRect.left,m_IniRect.top,m_IniRect.right,m_IniRect.bottom,&memDC,0,0,x,y,SRCCOPY); m_IsDrawForm = FALSE; m_ButtonState = bsIni; LeftLine.DeleteObject(); }
else if(tempMin.PtInRect(point))//鼠标在最小化按钮上移动时,更改按钮显示的位图 {
LeftLine.LoadBitmap(IDB_BITMAP7); LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth; y = bInfo.bmiHeader.biHeight; memDC.SelectObject(&LeftLine);
pWindowDC->StretchBlt(m_MinRect.left,m_MinRect.top,m_MinRect.right,m_MinRect.bottom,&memDC,0,0,x,y,SRCCOPY); m_IsDrawForm = FALSE; m_ButtonState = bsMin; LeftLine.DeleteObject(); }
else if (tempMax.PtInRect(point)) {
LeftLine.LoadBitmap(IDB_BITMAP7); LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth; y = bInfo.bmiHeader.biHeight; memDC.SelectObject(&LeftLine);
pWindowDC->StretchBlt(m_MaxRect.left,m_MaxRect.top,m_MaxRect.right,m_MaxRect.bottom,&memDC,0,0,x,y,SRCCOPY); m_IsDrawForm = FALSE; if (m_IsMax) {
m_ButtonState = bsMax; }
else {
m_ButtonState = bsRes; }
LeftLine.DeleteObject(); }
else if (tempClose.PtInRect(point)) {
LeftLine.LoadBitmap(IDB_BITMAP7); LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth; y = bInfo.bmiHeader.biHeight; memDC.SelectObject(&LeftLine);
pWindowDC->StretchBlt(m_CloseRect.left,m_CloseRect.top,m_CloseRect.right,m_CloseRect.bottom,&memDC,0,0,x,y,SRCCOPY); m_IsDrawForm = FALSE; m_ButtonState = bsClose; LeftLine.DeleteObject(); } else {
m_ButtonState = bsNone; if (m_IsDrawForm==FALSE) DrawForm();
// m_IsDrawForm = TRUE; }
ReleaseDC(&memDC);
//---------------------------------------------------------------------------------
六.处理窗体的WM_NCLBUTTONDOWN消息,当用户在非客户区域单击时,根据按钮的状态执行相应的操作,代码如下: CDialog::OnNcLButtonDown(nHitTest, point); switch (m_ButtonState) {
case bsClose: //关闭窗口 {
DestroyWindow(); }
break;
case bsIni: //还原窗口到初始大小和位置 {
m_IsMax = TRUE;
MoveWindow(m_OrigonRect.left,m_OrigonRect.top,m_OrigonRect.Width(),m_OrigonRect.Height()); }
break;
case bsMin: // {
CWnd* pDesk = GetDesktopWindow(); CRect rect;
pDesk->GetClientRect(rect);
SetWindowPos(0 ,(rect.Width()-m_OrigonRect.Width())/2,2,m_OrigonRect.Width(),0,SWP_SHOWWINDOW); }
break;
case bsMax: {
m_ButtonState = bsMax;
ShowWindow(SW_SHOWMAXIMIZED); m_IsMax = FALSE; }
break;
case bsRes: {
ShowWindow(SW_RESTORE); m_IsMax = TRUE; }
break; }
//------------------------------------------------------------------------------

