Display progress bar in status line

Source: Internet
Author: User

 

 

This code can create a progress bar anywhere in the status line.

 

1. Select Resource Symbols from the View menu and add a new ID (in this example, assume that

 ID_INDICATOR_PROGRESS_PANE), it may be better to assign a value to the ID by the computer.

 

2. Search for the indicators array in MainFrm. cpp, and add the newly added ID to the array,

 Put it behind other IDs, which will make the progress bar appear at the far right of the Status line. If you

Do not want the progress bar to appear on the rightmost side, You can also place the ID in other places you want to appear.

 

3. Open the string table in the resource file and Insert a new string. You can use the Insert Menu

 To add a new External table, or right-click the string table.

 

4. The character of this string is the new ID. For the message to be followed, add appropriate spaces. (add spaces.

 At least it must be larger than the created progress bar)

 

Now we have created an empty rectangleNext, we will place a progress bar here.

 

1. Declare a public variable in MainFrm. h. The type is CProgressCtrl (assuming m_progress)

 

2. Declare a protection variable in MainFrm. h. The type is BOOL (assuming m_bCreated)

 

3. In the OnCreate () function of MainFrm. cpp, initialize m_bCreated to FALSE:

 

M_bCreated = FALSE;

 

4. Now, when we need to use a progress bar, we should first check whether the progress bar has been created. If not,

Then we need to create:

 

CMainFrame: OnSomeLongProcess ()

{

RECT MyRect;

// Substitute 4 with the zero-based index of your status bar pane.

// For example, if you put your pane first in the indicators array,

// You must put 0, second you must put 1, etc.

M_wndStatusBar.GetItemRect (4, & MyRect );

 

If (m_bCreated = FALSE)

{

// Create the progress control

M_Progress.Create (WS_VISIBLE | WS_CHILD, MyRect, & wndStatusBar, 1 );

 

M_Progress.SetRange (0,100); // Set the range to between 0 and 100

M_Progress.SetStep (1); // Set the step amount

M_bCreated = TRUE;

}

 

// Now we want l simulate a long process:

For (int I = 0; I <100; I ++) {Sleep (20); m_Progress.StepIt ();}}

If the window is created after the progress bar, Changed the size, so the progress bar will not be adjusted again

We mustAdd your own code to the WM_SIZE event to adjust the position of the progress bar:

 

Void CMainFrame: OnSize (UINT nType, int cx, int cy)

{

CMDIFrameWnd: OnSize (nType, cx, cy );

RECT rc;

M_wndStatusBar.GetItemRect (4, & rc );

 

// Reposition the progress control correctly!

M_Progress.SetWindowPos (& wndTop, rc. left, rc. top, rc. right-rc. left,

Rc. bottom-rc. top, 0 );

}

 

This is how to implement the progress bar in the status line.It looks very long, but in fact it is very simple.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.