设置透明属性可通过重载OnCtrlColor函数实现 LOGBRUSH brush; brush.lbStyle =BS_SOLID; brush.lbColor =RGB(0,0,0); //black color hbr= CreateBrushIndirect (&brush); switch(nCtlColor) { case CTLCOLOR_LISTBOX: //其他控件类似 SetBkMode (*pDC, TRANSPARENT); //就是这句起的作用 break; } // TODO: Return a different brush if the default is not desired return hbr;
OnCtrrlColor什么时候响应?
写错了,应该是OnCtlColor“你们说的是使背景透过。 而我要做的是使整个控件区域透过!”,我还没看明白:)不知道你想要什么时候响应,这里说的很清楚啊 The framework calls this member function when a child control is about to be drawn. Most controls send this message to their parent (usually a dialog box) to prepare the pDC for drawing the control using the correct colors。OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window.
楼上的净说废话 还一个 星呢,真差劲!xintiaf(日月紫光) 请把那个讲清楚点好么?
在OnEraseBkgnd中加入如下代码: CRect clientRect; GetClientRect(&clientRect); int cx=clientRect.Width (); int cy=clientRect.Height (); // Store our orignal DC. CBitmap bitmap; memDC.CreateCompatibleDC (pDC); bitmap.CreateCompatibleBitmap (pDC,cx,cy); memDC.SelectObject (&bitmap); memDC.BitBlt (0,0,cx,cy,pDC,0,0,SRCCOPY);用memDC保存透过的背景 然后在需要透过的地方使用 pdc->BitBlt (CRect,&memDC,0,0,SRCCOPY);
大哥们,如果这么简单我早就弄出来了!
你们说的是使背景透过。
而我要做的是使整个控件区域透过!
就像STATIC的透过效果一样!
我曾试过使用一个虚拟设备,然后选中放整个控件位置的背景!
但是好像效果并不理想还有上面的第2个问题有经验的请帮忙回答!
LOGBRUSH brush;
brush.lbStyle =BS_SOLID;
brush.lbColor =RGB(0,0,0); //black color
hbr= CreateBrushIndirect (&brush);
switch(nCtlColor)
{
case CTLCOLOR_LISTBOX: //其他控件类似
SetBkMode (*pDC, TRANSPARENT); //就是这句起的作用
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
而我要做的是使整个控件区域透过!”,我还没看明白:)不知道你想要什么时候响应,这里说的很清楚啊
The framework calls this member function when a child control is about to be drawn. Most controls send this message to their parent (usually a dialog box) to prepare the pDC for drawing the control using the correct colors。OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window.
还一个 星呢,真差劲!xintiaf(日月紫光)
请把那个讲清楚点好么?
CRect clientRect;
GetClientRect(&clientRect);
int cx=clientRect.Width ();
int cy=clientRect.Height ();
// Store our orignal DC.
CBitmap bitmap;
memDC.CreateCompatibleDC (pDC);
bitmap.CreateCompatibleBitmap (pDC,cx,cy);
memDC.SelectObject (&bitmap);
memDC.BitBlt (0,0,cx,cy,pDC,0,0,SRCCOPY);用memDC保存透过的背景
然后在需要透过的地方使用
pdc->BitBlt (CRect,&memDC,0,0,SRCCOPY);