自定义绘制CProgressBarCtrl的win32(Custom draw CProgressB

2019-10-17 08:19发布

我希望有一个自定义的进度条控制中,例如示出了某些移动斜线或像这样或绘图进度条控制内部的图像。 我已经在网上搜索和列表视图为动态子类的自定义绘制的一些例子,但代码不会调用绘画方法:

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

Answer 1:

你报的代码有没有机会开始工作: NMLVCUSTOMDRAW属于列表视图控件,并且您继承控制试图使其自行绘制的? 不,它不会像这样工作。

进度条是一个简单的类,它不提供业主抽奖定制。 相反,你会离开你全权执行与视觉呈现完全定制的控制更好。

自定义进度栏窗口的骨架可以在这里抬头: http://tech.groups.yahoo.com/group/wtl/message/4814添加MSG_WM_PAINTOnPaint会有让你画你想要的方式。



文章来源: Custom draw CProgressBarCtrl win32
标签: winapi mfc atl wtl