Solved

Progress Bar

Posted on 2003-12-03
4
718 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
ID: 9865487
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9865504
0
 

Author Comment

by:VS_Learner
ID: 9866508
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
ID: 9866992
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

821 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