The progress bar is embedded in the ListCtrl in the VC, and the screenshots are as follows:
In fact, it is very easy. The following is the code of the self-painted listCtrl, first inherited ClistCtrl, then add functions: void cprocessList :: OnCustomDraw (nmhdr * pnmhdr, lresult * presult) {// Draw Each Item.set Txt Color, BKColor. ... NMLVCUSTOMDRAW * pLVCD = reinterpret_cast
COLORREF crText = :: GetSysColor (COLOR_WINDOWFRAME); COLORREF crBkgnd = :: GetSysColor (COLOR_WINDOW); CDC * pDC = CDC :: FromHandle (pLVCD-> nmcd.hdc); CRect rect; GetSubItemRect (nItem, nSubItem, LVIR_BOUNDS, rect) ; if (GetItemState (nItem, LVIS_SELECTED)) DrawText (nItem, nSubItem, pDC, :: GetSysColor (COLOR_HIGHLIGHT), :: GetSysColor (COLOR_HIGHLIGHT), rect); else DrawText (nItem, nSubItem, pDC, crText, crBkgnd, rect) ; * presult = cdrf_skipdefault; // we've painted everything.}
Then add message mapping for this function: ON_NOTIFY_REFLECT (NM_CUSTOMDRAW, ONCUSTOMDRAW) Finally, we work hard for the drawing of the model, and the progress exists in ItemData. void CProcessList :: DrawText (int nItem, int nSubItem, CDC * pDC, COLORREF crText, COLORREF crBkgnd, CRect & rect) {ASSERT (pDC); pDC-> FillSolidRect (& rect, crBkgnd); int nProcess = GetItemData (nItem); CRect PROCRECT = Rect; PDC-> Rectangle (ProCRect);
ProcRect.Eft = 1; procRect.bottom - = 1; procRect.top = 1; procRect.right = procRect.Lect Rect.width () * nprocess / 100; CBRUSH Brush (RGB (255, 0, 0) PDC-> FillRect (& ProcRect, & brush); CString Str; str.format ("% D %%", nprocess); if (! Str.isempty ()) {uint nformat = dt_vcenter | dt_singeline | dt_center; PDC- > Setbkmode (transparent); PDC-> setTextColor (CRText); PDC-> setBkcolor (CRBKGND); PDC-> DrawText (Str, & Rect, nformat);}}
how about it? Very simple, actually using the VC development interface is very fast, although it is still that the MFC package has a Java interface library package so good ...