winapi - Win32 ListView: Make colored progress bar for full row -


i want make colored progress bar full row in listview. take idea here:

custom draw

in above image, have colored progress bar, fo single cell. want make same think, full row.
here have done:

make progress bar

not expected :) tried draw @ cdds_item | cdds_postpaint case. code:

static lresult handlecustomdraw(nmlvcustomdraw* pcd) {     tchar buffer[16];     lvitem item;      switch (pcd->nmcd.dwdrawstage)     {         case cdds_prepaint:             /* tell control interested in per-item notifications.             * (we need tell control want per-subitem             * notifications.) */             return cdrf_dodefault | cdrf_notifyitemdraw;          case (cdds_item | cdds_prepaint) :             /* tell control interested in per-subitem notifications. */             return cdrf_dodefault | cdrf_notifypostpaint | cdrf_notifysubitemdraw;         case (cdds_item | cdds_postpaint) :         {             // test: assume progress value 50%             float percent = 0.5;             rect r = pcd->nmcd.rc;             r.right = r.left + percent * (r.right - r.left);             hbrush hprogressbrush = createsolidbrush(rgb(255, 255, 0));             fillrect(pcd->nmcd.hdc, &r, hprogressbrush);             return cdrf_skipdefault;         }     } } 

the expect result, example @ row item 8, percent = 0.5, filled rectange start of row, between third column, , rest of row other color.
how can achieve that? know have draw different color selected/focused/inative row, i'm ok it.

edit:
above image (the second one) above code.
demo want:

enter image description here

in wm_size handler of window retrieve , save list view's client rect (for example in global variable) getclientrect():

rect list_view_rc;  // global. getclientrect(list_view_hwnd, &list_view_rc); 

rect r = pcd->nmcd.rc; in handlecustomdraw() gives rectangle of drawn item inside list view's client area. have replace r.left , r.right obtained values list view's client rectangle:

r.left = list_view_rc.left; r.right = list_view_rc.right; 

this give rectangle whole row draw into. have on last item drawn if you're using cdds_postpaint. why need global variable list_view_column_count contains number of list view columns:

int list_view_column_count;   // global. list_view_column_count = header_getitemcount(listview_getheader(list_view_hwnd)); 

with cdds_postpaint have draw text inside items because destroyed rectangle, or try mix rectangle text changing foreground mix mode setrop2(). code need (without text drawing):

static lresult handlecustomdraw(nmlvcustomdraw* pcd) {     tchar buffer[16];     lvitem item;     // static variable works if you're calling     // handlecustomdraw() 1 specific list view.     static int current_item_count;      switch (pcd->nmcd.dwdrawstage)     {         case cdds_prepaint:             /* tell control interested in per-item notifications.             * (we need tell control want per-subitem             * notifications.) */             current_item_count=0;             return cdrf_dodefault | cdrf_notifyitemdraw;          case (cdds_item | cdds_prepaint) :             /* tell control interested in per-subitem notifications. */             return cdrf_dodefault | cdrf_notifypostpaint | cdrf_notifysubitemdraw;         case (cdds_item | cdds_postpaint) :         if (++current_item_count == list_view_column_count)         {             // test: assume progress value 50%             float percent = 0.5;             rect r = pcd->nmcd.rc;             r.left=list_view_rc.left;             r.right=list_view_rc.right;             r.right = r.left + percent * (r.right - r.left);             hbrush hprogressbrush = createsolidbrush(rgb(255, 255, 0));             fillrect(pcd->nmcd.hdc, &r, hprogressbrush);             return cdrf_skipdefault;         }     } } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -