下面是網上收集來的**,實現炫彩自繪視窗非客戶區,貼出來大家參考共享...
效果如下圖所示:
關鍵**如下:
在框架類中新增:
public:
afx_msg void onnclbuttondown(uint nhittest, cpoint point);
afx_msg void onncmousemove(uint nhittest, cpoint point);
afx_msg bool onerasebkgnd(cdc* pdc);
virtual bool pretranslatemessage(msg* pmsg);
virtual lresult defwindowproc(uint message, wparam wparam, lparam lparam);
public:
crect m_rticon; //程式圖示位置
crect m_rtbuttmax; //最大化按鈕位置
crect m_rtbuttmin; //最小化按鈕位置
crect m_rtbuttexit; //關閉按鈕位置
實現:
在oncreate訊息裡新增:
crect rtwnd;
getwindowrect(&rtwnd);
crgn rgn;
rgn.createroundrectrgn(0,0,rtwnd.width(),rtwnd.height(),5,5);
setwindowrgn((hrgn)rgn,true);
下面是訊息部分:
void cmainframe::onnclbuttondown(uint nhittest, cpoint point)
else
}else if (!iszoomed())
default();
//cframewndex::onnclbuttondown(nhittest, point);}
void cmainframe::onncmousemove(uint nhittest, cpoint point)
else
rtbutton = m_rtbuttmax;
rtbutton.offsetrect(-rtwnd.left, -rtwnd.top);
poldbitmap=(cbitmap*)pdisplaymemdc->selectobject(pbitmap);
pdc->bitblt(rtbutton.left, rtbutton.top, rtbutton.width(), rtbutton.height(), pdisplaymemdc, 0, 0, srccopy);
pdisplaymemdc->selectobject(poldbitmap);
pbitmap->deleteobject();
//最小化button
if (m_rtbuttmin.ptinrect(point))
pbitmap->loadbitmap(idb_bitmap7);
else
pbitmap->loadbitmap(idb_bitmap8);
rtbutton = m_rtbuttmin;
rtbutton.offsetrect(-rtwnd.left, -rtwnd.top);
poldbitmap=(cbitmap*)pdisplaymemdc->selectobject(pbitmap);
pdc->bitblt(rtbutton.left, rtbutton.top, rtbutton.width(), rtbutton.height(), pdisplaymemdc, 0, 0, srccopy);
pdisplaymemdc->selectobject(poldbitmap);
pbitmap->deleteobject(); }
pdisplaymemdc->deletedc();
delete pdisplaymemdc;
delete pbitmap;
//cdialog::onncmousemove(nhittest, point);
cframewndex::onncmousemove(nhittest, point);}
bool cmainframe::onerasebkgnd(cdc* pdc)
bool cmainframe::pretranslatemessage(msg* pmsg)
}return cframewndex::pretranslatemessage(pmsg);}
lresult cmainframe::defwindowproc(uint message, wparam wparam, lparam lparam)
catch( cexception* e )
}return lrst;
//return cframewndex::defwindowproc(message, wparam, lparam);
}void cmainframe::drawtitlebar(cdc *pdc)}
NcPaint重繪非客戶區
1.需要響應wm nccalcsize訊息 2.需要響應ncpaint訊息 3.還需要響應wm size void 類名 onsize uint ntype,int cx,int cy 4.響應active 用於繪製不同情況下的標題。void 類名 onactivate uint nstate,cw...
MFC重繪非客戶區
1.去除視窗邊框和標題欄 oninitdialog函式,去除視窗邊框和標題欄 dword dwstyle getstyle dwnewstyle dwstyle setwindowlong m hwnd,gwl style,dwnewstyle dword dwexstyle getexstyle ...
VC 實現 自繪 窗體 標題欄 非客戶區
vc 實現 自繪 窗體 標題欄 非客戶區 1.準備工作。1 得到資料夾中的點陣圖控制代碼 首先要準備相應。hbitmap bitmap bitmap hbitmap loadimage afxgetinstancehandle skin test.bmp image bitmap,0,0,lr de...