VC自绘窗体

2026/4/24 11:24:39

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; }

//------------------------------------------------------------------------------


VC自绘窗体.doc 将本文的Word文档下载到电脑
搜索更多关于: VC自绘窗体 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219