自定义绘制CProgressBarCtrl win32 [英] Custom draw CProgressBarCtrl win32

查看:243
本文介绍了自定义绘制CProgressBarCtrl win32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个自定义进度条控件,例如显示一些移动的斜线或类似

I want to have a custom progress bar control, for example showing some moving oblique lines or like this or drawing an image inside the progress bar control. I 've searched the web and some examples of custom drawing for listviews and dynamic subclassing but the code doesn't call the painting methods:

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;
    }

推荐答案

您引用的代码没有机会开始工作:NMLVCUSTOMDRAW属于列表视图控件,并且您将该控件子类化以使其成为所有者绘制?不,它不能像这样工作.

The code you quoted has no chances to start working: NMLVCUSTOMDRAW belongs to list view control, and you are subclassing the control trying to make it owner-drawn? No, it does not work like this.

进度栏是一个简单的类,它不提供所有者绘图自定义.取而代之的是,您可以全权酌情采用可视化呈现来实现完全自定义控件,效果更好.

Progress bar is a simple class and it does not offer owner draw customization. Instead you would be better off implementing fully custom control with visual presentation at your full discretion.

可以在此处查找自定义进度栏窗口的框架: http://tech.groups.yahoo.com/group/wtl/message/4814 添加MSG_WM_PAINTOnPaint可以让您按照自己的方式绘画.

A skeleton of custom progress bar window can be looked up here: http://tech.groups.yahoo.com/group/wtl/message/4814 Adding MSG_WM_PAINT and OnPaint there will get you painting the way you want it.

这篇关于自定义绘制CProgressBarCtrl win32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆