改變窗體背景色的幾種方法

2021-04-18 16:12:45 字數 802 閱讀 4832

第一種方法是:攔截檢視類的wm_erasebkgnd訊息,

加入以下**,

crect rect;

pdc->getclipbox(&rect);

cbrush brush(m_crbackcolor);

cbrush* poldbrush=pdc->selectobject(&brush);

pdc->patblt( rect.left,rect.top,rect.width(),rect.height(),patcopy);

pdc->selectobject(poldbrush);

第二種方法是:過載其precreatewindow()函式,

加入以下**:

cs.lpszclass=afxregisterwndclass(cs_hredraw|cs_vredraw,loadcursor(null,idc_help),(hbrush)getstockobject(dkgray_brush),0);

利用此函式還可以改變圖示和游標.

第三種方法是在oncreate函式中利用api函式getclasslong()和setclasslong(),

具體**如下:

hbrush hbrush = (hbrush)getclasslong(m_hwnd,gcl_hbrbackground);

m_hbrush = createsolidbrush(m_color);

::setclasslong(m_hwnd,gcl_hbrbackground,(long)m_hbrush);

deleteobject(hbrush);

改變Push Button背景色

聞怡洋 01 9 12 下午 03 14 36 在windows中edit,staticbox的背景色都可以通過處理wm ctlcolor訊息來改變,但push button卻不行。唯一的方法是使用ownerdraw風格的按鈕。本文講述的方法是使用cbutton的派生類。class ccbutton...

ios改變tablecell背景色

最有效的解決方式是 使用 void tableview uitableview tableview willdisplaycell uitableviewcell cell forrowatindexpath nsindexpath indexpath 託管函式中定義cell的背景顏色值。注意 ce...

改變TreeView控制項的背景色

private declare function sendmessage lib user32 alias sendmessagea byval hwnd as long,byval wmsg as long,byval wparam as long,lparam as long as long p...