Display process status in the status bar

zhaozj2021-02-11  255

Display process status in the status bar, Ice is a large number of numerical operations in terms of using MFC writing applications, especially when numerical analysis and analog programs, such as displaying three-dimensional, two-dimensional graphic images, need data fitting , Splines, and interpolation, and in order to ensure accuracy, data points generally use floating and even double precision floating point numbers, such applications need to take up a lot of CPU time to complete the corresponding work, generally last for a few minutes, a few Ten minutes or even more time. If the application does not output some information, it will often be mistakenly considered whether the system has been caught. Therefore, the Windows system provides a function: loadcursor (uint nidResource) const; through this function, the shape of the mouse can be changed to the hourglass to indicate that the system is in a time consuming process. However, in general, this change is easy to neglect, and I don't know how much the current process is completed, and there is still the rest. The process string control CProgressCtrl class is provided in the MFC, which can easily display the completion of the process. For the usage and description of the process string control CPRESSCTRL class, see the online help of Visual C . Displays the completion of the current process, there are many ways to use the process string control CProgressCtrl class. For example, the multi-threaded programming method is used, and the thread communication can be displayed, and the process string control CPRESSCTRL class can be used in the same thread. The dialog is displayed. But these methods are more complicated and inconvenient, and need to take up certain system resources, and the status display response is not very fast. Windows applications typically have a small tangible state strip at the bottom there. The right side of the status bar is a number of status capable of dynamically increase or delete. The status bar control CSTATUSBAR class is provided in the MFC to complete the management of the status. So we can add a process strip status in the application's status bar to display the completion of the current process task. Obviously, relatively relatively long, this method is more convenient and easy to implement, does not occupy system resources, and the status display is very fast. The specific implementation method is explained below: 1. Creating a project file with AppWizard PBAR, single document application, or multi-document applications. Other options can be used by default. 2. In Visual Studio's workbench, select the "Resource Symbols" menu command under the "View" menu, pop up the dialog, click the "New" button to add a new symbol ID_ indeicator_progress_pane and use the default ID value assigned by the system. As shown in Figure 1. (Figure Zhuang-1) Figure 1 Add a symbol ID_indicator_progress_pane 3, indicating an array (immediately after the message mapping code segment) in the message mapping code segment indicates the array (after the message mapping code segment). Note that if the symbol ID_INDI-CATOR_PROGRESS_PANE is placed in the array, the process strip status will be on the rightmost right side of the status bar; if you put the symbol ID_indicator_progress _pane in front of the array, the process strip status will be in the status bar The leftmost; if the symbol ID_indicator_progress _pane is placed in the middle of the array, the process strip status will be in the middle of the status bar.

Referring specifically to the following code: static UINT indicators [] = {ID_SEPARATOR, // status line indicator ID_INDICATOR_PROGRESS_PANE, // means the progress pane in far left ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,.}; 4, open the resource editor, select string table , Click the right mouse button, select the "New String" command (or select the "New String" command through the "INSERT" menu of the Workbench, and pop up the string property editing dialog as shown in Figure 2. In the ID field of the String Prorties dialog, type symbol ID_INDICATOR_PROGRESS_ PANE, and type the space in the Caption Edit field. Note how many spaces will determine the length of the process status in the status bar. See Figure 2 in particular. (Figure Zhuang-2) Figure 2 Add a string of symbol ID_indicator_progress_pane 5, in the header file mainfrm.h, add two variables, set to the CPROGRESSCTRL control, set to m_progress; another logic Boolean variable, set to m_bcreated, This variable is used to mark the CPROGRESSCTRL control to be created successfully. 6. In the oncreate () function of the source file mainfrm.cpp, the m_bcreated is false, as shown below: m_bcreated = false; 7, an hourly process function oversomelongProcess () is to present the process status of the status bar. This is simply used to simulate a time consuming process. Function code See program 1.

void CMainFrame :: OnSomeLongProcess () {RECT MyRect;. // substitute 1 with the zero-based index of your status bar pane For example, if you put your // pane first in the indicators array, you put 0, second you put 1, etc. m_wndStatusBar.GetItemRect (1, & MyRect); if (m_bCreated == FALSE) {// Create the progress control m_Progress.Create (WS_VISIBLE | WS_CHILD, MyRect, & m_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'll Simulate A long process: for (int i = 0; i <100; i ) ) {SLEEP (20); m_progress.stepit ();}} 8, after the process status in the status bar is created, if the application main window size changes, the size of the process status does not automatically adapt to the main window. Various, therefore requires the ONSIZE () function of the main window. Add the WM_SIZE message mapping function in the main window via ClassWizard, as shown in Figure 3. (Figure Zhuang-3) Figure 3 Exploses the Source Code of the WM_SIZE message mapping function in CMAINFRAME with ClassWizard. Void CMAINFRAME :: OnSize (uint ntype, int cx, int CY) {cframeWnd :: Onsize (NTYPE, CX, CY); // Todo: add your message handler code here if (m_bcreated == true) {Rect rc; m_wndstatusbar .GETITEMRECT (1, & RC); // Reposition The Progress Control Correctly! M_Progress.SetWindowPos (& Wndtop, Rc.Left, Rc.top, Rc.right - rc.LEFT, RC.BOTTOM - RC.TOP, SWP_SHOWINDOW);} } 9, open the resource editor, add the "Test" menu command under the View menu, and the ID is set to ID_TEST. Then use ClassWizard to add a message mapping function onTest (), the code is as follows: void cmainframe :: ontest () {// Todo: add Your command handler code heren OnsomelongProcess (); After completing all of the above steps, compile and run the program. Select the Test menu command under the "View" menu will see the process display of the process status in the status bar, as shown in Figure 4.

转载请注明原文地址:https://www.9cbs.com/read-3994.html

New Post(0)