【问题标题】:Custom draw CProgressBarCtrl win32自定义绘制 CProgressBarCtrl win32
【发布时间】:2012-10-09 21:07:04
【问题描述】:

我想要一个自定义进度条控件,例如显示一些移动的斜线或类似this 或在进度条控件内绘制图像。我已经在网上搜索了一些关于列表视图和动态子类的自定义绘图示例,但代码没有调用绘图方法:

public:
     BOOL SubclassWindow(HWND hWnd)
      {
          ATLASSERT(m_hWnd==NULL);
          ATLASSERT(::IsWindow(hWnd));
          BOOL bRet = CWindowImpl<CMyProgressControl, CProgressBarCtrl>::SubclassWindow(hWnd);
          return bRet;
       }

    BEGIN_MSG_MAP(CMyProgressControl)
      CHAIN_MSG_MAP(CCustomDraw<CMyProgressControl>)
   END_MSG_MAP()

   DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
    {        
        return  CDRF_NOTIFYITEMDRAW;
    }
     DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW lpNMCustomDraw)
    {
        NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( lpNMCustomDraw );

        // This is the prepaint stage for an item. Here's where we set the
        // item's text color. Our return value will tell Windows to draw the
        // item itself, but it will use the new color we set here for the background

        COLORREF crText;


            crText = RGB(200,200,255);

        // Store the color back in the NMLVCUSTOMDRAW struct.
        pLVCD->clrTextBk = crText;


        // Tell Windows to paint the control itself.
        return CDRF_DODEFAULT;
    }

【问题讨论】:

    标签: winapi mfc atl wtl


    【解决方案1】:

    您引用的代码没有机会开始工作:NMLVCUSTOMDRAW 属于列表视图控件,并且您正在对控件进行子类化以使其成为所有者绘制的?不,它不是这样工作的。

    进度条是一个简单的类,它不提供所有者绘制自定义。相反,您最好完全自行决定通过视觉呈现来实现完全自定义的控制。

    可以在此处查找自定义进度条窗口的骨架:http://tech.groups.yahoo.com/group/wtl/message/4814 添加MSG_WM_PAINTOnPaint 将让您以您想要的方式进行绘画。

    【讨论】:

      猜你喜欢
      • 2010-12-29
      • 1970-01-01
      • 2014-04-01
      • 2011-01-01
      • 2012-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多