CPROGRESS

xiaoxiao2021-03-06  43

CPROGRESS

(1) Main functions of progress bar

Progress Control is mainly used to perform operational progress prompts when operating data read and write, file copy, and disk formats, such as installation programs, etc., with progressive progress, the rectangular area of ​​the progress bar is used from left to right. The color of the current active window title bar is constantly filling.

The progress bar is controlled in the encapsulation class in the MFC class library as CProgressCtrl, which is usually only controlled as an output class, so its operation is mainly to set the range and the current position of the progress bar, and constantly update the current position. The scope of the progress bar is used to represent the length of time of the entire operating process, and the current position represents the current time of the completion. SetRange () function is used to set the range, the initial range is 0-100, and the setpos () function is used to set the current location, the initial value is 0, the setstep () function is used to set the step size, the initial step length is 10, step () The function is used to update the location according to the current step size, and the offsetpos () function is used to move the current location from a distance. If the range or position changes, the progress bar will automatically redraw the progress area to promptly reflect the progress of the current work.

Aggregate object structure

Progress strip control establishment method

CPROGRESSCTRL & ProgressCtrl Establishing progress bar control target structure

CREATE establishes progress bar to control objects and bind objects

The progress bar control class CPROGRESSCTRL :: CREATE is as follows:

Bool Create (DWORD DWSTYLE, CONST RECT & RECT, CWND * PPARENTWND, UINT NID);

The parameter DWSTYLE is used to determine the control style of the progress bar control; the parameter RECT is used to determine the size and position of the progress bar control; the parameter pParentWnd is used to determine the progress strip parent window pointer; the parameter NID is used to determine the control ID value of the progress bar control. .

2, progress bar control class properties

The class attribute of the progress bar control includes setting the maximum smallest control range setRange, setting the progress bar Current location setpos, setting the progress bar current position offset value OFFSETPOS and setting the progress bar control the incremental setstep.

3, progress bar control operation method

The operation method of progress bar control is mainly to control the progress bar and redraw the STEPIT function of the progress bar.

Application skills for progress bar control

1. Use the application wizard AppWizard to generate an object box-based application CProgDLG;

2. Set the progress bar and static text control in the dialog, and its ID is IDC_PROG and IDCPERCENT;

Add control range and location in the initial code of the dialog:

Set two data members in progdlg.h, used to indicate the maximum and steps of the progress bar:

//Progdlg.h

Class Cprogdlg: Public CDialog

{. . . . . . // Other code

PUBLIC:

INT M_NMAX, M_NSTEP;

. . . . . . // Other code

}

(2) Set the initial state in progdlg.cpp

Bool cprogdlg :: oninitdialog ()

{CDialog :: oninitdialog ();

. . . . . . // Other code

// Todo: Add Extra Initialization Here

CPROGRESSCTRL * PPROGCTRL = (CProgressCtrl *) getdlgitem (IDC_PROG);

PProgCtrl-> setRange (0,200); // Set the progress bar range

. . . . . . // Other code m_nmax = 200;

M_NSTEP = 10;

SetTimer (1,1000, null); // Set the progress bar update clock

Return True;

}

(3) Improve the WM_TIMER message processing, so that the progress bar will be updated according to the current step size, and the percentage of the progress bar is completed:

Void CProgdlg :: ONTIMER (Uint Nidevent)

{// Todo: add your message handler?

CPROGRESSCTRL * PPROGCTRL = (CProgressCtrl *) getdlgitem (IDC_PROG);

INT nprepos = pprogctrl-> step (); // get the update position

CHAR TEST [10];

INT NPERCENT = (INT) (((NPREPOS M_NSTEP) /M_NMAX*100 0.5);

WSPRINTF (TEST,?% D %% ?, npercent);

Getdlgitem (IDC_PERCENT) -> SetWindowText (Text);

CDIALOG :: ONTIMER (Nidevent);

}

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

New Post(0)