在MFC标准控件里有一些空间就是不规则的(方方正正的)这个时候自绘的时候背景就不好控制了。
比如我现在自绘了一个slidebar 如下图:
1是背景 2是自绘时没考虑到背景所带来的问题 3是控件本身,我现在想控件的背景透明,在不加任何资源的情况下,怎么实现。我只前继承自CSlideBar时挖去控件所在位置的父窗口的图片作为背景,能实现“透明效果”,现在这个控件继承自CWnd  再取父窗口背景就取不到了,一片漆黑啊。各位大神有无解决方案?滑动条自绘滑动条自绘控件背景

解决方案 »

  1.   

    WS_EX_TRANSPARENT   Specifies that a window created with this style is to be transparent. That is, any windows that are beneath the window are not obscured by the window. A window created with this style receives WM_PAINT messages only after all sibling windows beneath it have been updated.
      

  2.   

    由于主窗口的背景是纯色,实现透明还是比较容易的。
    重载CSlideBar,添加一个数据成员 COLORREF m_clrParentBg;
    创建滑动条控件时,将m_clrParentBg设置为主窗口的背景色,然后将控件的背景色设置为m_clrParentBg的颜色。
      

  3.   

    参考一下:
    http://bbs.csdn.net/topics/390401008
      

  4.   

    重载OnEraseBkgnd,直接返回TRUE不让它绘制背景:
    BOOL CBar::OnEraseBkgnd(CDC* pDC) 
    {
    // TODO: Add your message handler code here and/or call default
    return TRUE;
    //return CScrollBar::OnEraseBkgnd(pDC);
    }