Solved

Progress Bar

Posted on 2003-12-03
4
681 Views
Last Modified: 2013-11-20
I need to add a Progress Bar in a List Control Box.
i.e In Report View as an element in a specific column
Can anyone suggest me the procedure to do the same
0
Comment
Question by:VS_Learner
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
0
 

Author Comment

by:VS_Learner
Comment Utility
I have a Class inheriting CPropertyPage ...
and I have designed a list control in that dialog
I have a problem in integrating the code given in above examples with my LIST CONTROL DIALOG ..
i.e how and where to define those classes and variables
0
 
LVL 3

Accepted Solution

by:
komar earned 20 total points
Comment Utility
You may create the progress control dynamically (when needed), user it and then destroy it when you are done with it.

The code below is just a simple way to just that:

NOTE: You may need to copy the code below and paste it into notepad (or the VC editor) to be able to see long lines!

1. Add a method called "CProgressCtrl *CreateProgressCtrlInListCtrlItem(CListCtrl &ctrlList, int nItem, int nSubItem)" to you CPropertyPage derived class. The code for this method is shown below:

CProgressCtrl *CDerivedPropPage::CreateProgressCtrlInListCtrlItem(CListCtrl &ctrlList, int nItem, int nSubItem)
{
      ASSERT(IsWindow(ctrlList.GetSafeHwnd()));
      if(!IsWindow(ctrlList.GetSafeHwnd()))
            return NULL;

      //Get rectangle for the specified sub-item
      CRect rectSubItem;
      ctrlList.GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rectSubItem);

      //Special case handling if nSubItem is 0
      //(GetSubItemRect() returns the whole list width if nSubItem equals 0)
      if(nSubItem == 0)
      {
            rectSubItem.right = rectSubItem.left + ctrlList.GetColumnWidth(nSubItem);
      }

      CProgressCtrl *pCtrl = new CProgressCtrl;
      if(pCtrl)
      {
            BOOL bCreated = pCtrl->Create(WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
                                                 rectSubItem,
                                       &ctrlList,
                                       (UINT)-1);

            if(bCreated)
            {
                  pCtrl->ShowWindow(SW_SHOW);
                  pCtrl->UpdateWindow();
            }
      }

      return pCtrl;
}

2. To use this method, you can do something like this:
      ...
      ...
      CProgressCtrl *pCtrl = CreateProgressCtrlInListCtrlItem(m_list, 0, 0);

      if(pCtrl->GetSafeHwnd()) //Make sure creation of progress succeed
      {
            int nMin = 0;
            int nMax = 100;
            int nStep = 5;

            pCtrl->SetRange32(nMin, nMax);
            pCtrl->SetPos(nMin);
            pCtrl->SetStep(nStep);
            
            while(nMax > pCtrl->GetPos())
            {
                  pCtrl->StepIt();
                  Sleep(100); //Delay 100 milli seconds
            }

            pCtrl->DestroyWindow();
            delete pCtrl;
            pCtrl = NULL;
      }
      ...
      ...

Thanks,
Khalid Omar.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now