Showing progress bar in a status bar pane
来源:互联网 发布:windows linux 拷 编辑:程序博客网 时间:2024/05/31 18:39
This code creates a progress bar anywhere in the status window and the control is created only once.
1. From the View menu, choose Resource Symbols. Press the New button and assign the symbol a name. (In this example we’ll be using ID_INDICATOR_PROGRESS_PANE) It’s probably best if you let the computer assign a value for it.
2. In MainFrm.cpp, find the indicators array (located under the message map section) and type the ID of the resource (ID_INDICATOR_PROGRESS_PANE) in the section. Put it under all the rest of the ID’s, unless you don’t want the bar in the far right corner. (placing the ID at the beginning of the array puts the pane in the far left where the program messages usually go)
3. Open the string table in the resource editor, and from the Insert menu, choose New String.
4. Double click the string and select the ID. For the message, just type a bunch of spaces. (the more spaces the larger the progress bar)
Now that we’ve created the pane, it’s time to put a progress bar in it.
1. Declare a public variable in MainFrm.h of type CProgressCtrl. (In this example we’ll call it m_Progress)
2. Declare a protected variable in MainFrm.h of type BOOL. (In this example we’ll call it m_bCreated)
3. In the OnCreate() function in MainFrm.cpp, initialize m_bCreated to FALSE:
m_bCreated = FALSE;
4. Now, when we need to use the progress bar, we check to see if it’s created, and if it isn’t, we make a new one:
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’d put 0, second you’d put 1, etc.m_wndStatusBar.GetItemRect(4, &MyRect); if (m_bCreated == FALSE){//Create the progress controlm_Progress.Create(WS_VISIBLE|WS_CHILD, MyRect, &wndStatusBar, 1); m_Progress.SetRange(0,100); //Set the range to between 0 and 100m_Progress.SetStep(1); // Set the step amountm_bCreated = TRUE;}// Now we’ll simulate a long process:for (int I = 0; I < 100; I++){Sleep(20);m_Progress.StepIt();}}
If the window is resized while the progress bar is created, the progress control doesn’t reposition correctly, so we have to override the WM_SIZE event of class CMainFrame:
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); }
That’s the way to implement a progress control into a status bar pane! Although the process is long, it is relatively simple.
- Showing progress bar in a status bar pane
- Showing progress bar in a status bar pane
- Showing Windows Progress Bar
- Showing a Message in the Browser's Status Bar:在浏览器的状态栏中显示信息
- Custom Progress Bar In Android
- Progress bar in VBA Excel
- progress bar
- Creating a Status Bar Application
- Creating a Status Bar Application
- Status bar
- Create a Progress Bar with Win32 project
- A progress bar (gauge box) -- dialog Linux
- Customizing Navigation Bar and Status Bar in iOS 7
- Customizing Navigation Bar and Status Bar in iOS 7
- Customizing Navigation Bar and Status Bar in iOS 7
- Customizing Navigation Bar and Status Bar in iOS 7 .
- Customizing Navigation Bar and Status Bar in iOS 7
- How Creeate status Bar in MFC
- 在tomcat中部署appfusework1.8.2
- 求13的13次方的最后三位数
- 在tomcat中部署appfusework1.8.2
- PHP中使用XML-RPC构造Web Service简单入门
- gcc 4.3 configure脚本学习(1):前言
- Showing progress bar in a status bar pane
- CSDN BLOG的改版
- fleXive——JavaEE框架
- Vlan知识之五:IEEE802.1Q与ISL
- 根据声音判断电脑故障(BIOS 提示音汇总) [转帖]
- UI-界面制作体会
- jsp+java分页出现错误
- C# 2.0 操作注册表
- 怎样不用临时变量而交换两个变量的值?——看一中文编程语言中的“完美”一例