Custom draw CProgressBarCtrl win32

旧时模样 提交于 2019-12-11 11:14:47

问题


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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/12971062/custom-draw-cprogressbarctrl-win32

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!