我设置背景色和前景色(前景色是文本)以后,又设置背景色透明,结果是背景色和前景色设置正确,但是前景文本背后有个小方框的颜色是背景色的初始默认颜色而不是新改的背景色~~~我是做的activex控件~~,代码,图片如下
void CClock2Ctrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
// pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
// pdc->Ellipse(rcBounds);
CBrush brush(TranslateColor(GetBackColor()));
pdc->FillRect(rcBounds,&brush);
//pdc->SetBkColor(TRANSPARENT);
pdc->SetTextColor(TranslateColor(GetForeColor()));
CTime time=CTime::GetCurrentTime();
if(0==time.GetSecond())
{
FireNewMinute();
}
CString str=time.Format("%H:%M:%S");
pdc->TextOut(0,0,str);
}

解决方案 »

  1.   

    可以先创建一个基于CButton的类。。以为要是修改按钮控件要用到虚函数DrawItem。 然后在改类中加入虚函数DrawItem。 再把你要改变按钮的ID绑定到改类。。 然后在按钮的属性中--->样式--->选择owner draw 。。  具体你要的按钮透明可以再DrawItem中设置。 设计部分可以看MSDN中DRAWITEMSTRUCT的结构体介绍。     要是是文本背景透明可以用 SetBkMode 或是SetbKColor
      

  2.   

    setbkmode和setbkcolcor在具体使用时的差别是什么,我把那个pdc->SetBkColor(TRANSPARENT); 
    改为pdc->SetBkMode(TRANSPARENT);就没问题了,文字的小方框背景色就成了background的颜色了。不会像用 pdc->SetBkColor(TRANSPARENT); 时文字的小方框背景色是黑的了
      

  3.   

    看不到图.....
    SetBKMode!
    不会像用 pdc->SetBkColor(TRANSPARENT);这个设置背景颜色啊,能直接把TRANSPARENT当参数?当然编译是没错的.....
    用RGB()宏!
      

  4.   


    CBrush brush(TranslateColor(GetBackColor())); 
    pdc->FillRect(rcBounds,&brush); 
    //pdc->SetBkColor(TRANSPARENT);  // TRANSPARENT不是颜色来的,#define TRANSPARENT 1
                                     // 这样会变成RGB为1的颜色了// 改为pdc->SetBkMode(TRANSPARENT);  这样才是透明的
    // 或者改为pdc->SetBkColor(TranslateColor(GetBackColor()));  将文字背景改为你的刷子的颜色也可以setbkmode和setbkcolcor在具体使用时的差别是什么,很明显看名称都不一样吧The SetBkMode function sets the background mix mode of the specified device context. The background mix mode is used with text, hatched brushes, and pen styles that are not solid lines.The SetBkColor function sets the current background color to the specified color value, or to the nearest physical color if the device cannot represent the specified color value. 
      

  5.   

    同9L的 MSDN中SetBkcolor()的参数是COLORREF