Symbian progress bar processbar

Source: Internet
Author: User

The progress bar control is used to display a relatively long operation progress, such as the mail acceptance progress and file download progress. The progressbar sample program in this section displays a simple progress bar. As the progress increases with the event, the running interface of the progressbar sample program is as follows:





The base class of the ceikprogressinfo class

The progress bar class is the ceikprogressinfo defined in the header file eikprogi. h. This class is derived from the ceiborderedcontrol class.

1: Define the progress bar in the resource file

The Resource Type of the progress bar is defined in the Eikon. RH file:

Struct progressinfo

{

Word
Text_type = 0;


Word splits_in_block = 0;


Long finalval;

Long
Length = 120;

Long
Height = 10;

}

 
Text_type is the text display setting on the progress bar, And splits_in_block is the number of cells displayed in each step of the progress. The two values are s60.
The SDK of version 2. x is no longer supported.

Finalval sets the total number of steps in the progress bar, which is a value that must be defined in the progress bar resource file. The width value sets the width of the progress bar, and the height value sets the height of the progress bar, both of which are measured in pixels.

In the progressbar sample program, the resource definition of the progress bar is as follows:

Resource progressinfo r_progress_bar

{

Text_type
= 0;

Splits_in_block = 0;

Finalval = 20;

Width =
120;

Height = 20;

}

2: Construct a progress bar Control

First, in the header file of the master control cprogressbarcontainer of the progressbar sample program, define the progress bar control:

Class ceikprogressinfo;

Class
Cprogressbarcontainer: Public ccoecontrol, mcoecontrolobserver

{


PRIVATE:

Ceikprogressinfo *
Ipbar;

}

 
The process of constructing the progress bar control is similar to that of the slider. It is constructed from the resource definition in the constructl () function of the main control. The reference code is as follows:

# Include
<Eikprogi. h> // use ceikprogressinfo

# Include
<Progressbar. RSG> // use the r_progress_bar resource.

# Include
<Coemain. h> // use icoeenv

# Include
<Barsread. h> // use tresourcereader

 

Void cprogressbarcontainer: constructl (const
Trect & arect)

{


Tresourcereader reader;


Icoeenv-> createresourceresderlc (reader,
R_progress_bar );

Ipbar =
New (eleave) ceikprogressinfo ();

Ipbar =
New (eleave) ceikprogressinfo ();


Cleanupstack: popanddestroy ();


Ipbar-> setposition (tpoint (10, 40 ));

Ipbar-> setcontainer1_wl (* This );

}

3: Adjust the progress of the progress bar


The ceikprogressinfo class provides multiple progress setting functions. The incrementanddraw () and setanddraw () functions are commonly used. Their definitions are as follows:

Void
Incrementanddraw (tint ainc );

Void
Setanddraw (tint avalue );

The incrementanddraw () function adds the ainc step to the progress bar and refreshes the progress bar. Ainc can be a negative number. The progress of the progress bar will jump back.
When the value of the gdang progress bar reaches or exceeds the value defined by finalval, the progress bar displays the maximum progress. The setanddraw () function sets the current progress as a parameter.
Avalue represents an absolute value.

 
The progressbar example program uses the periodic timer cperiodic to control the progress of the progress bar. cperiodic can generate periodic timer events. The example program adds the progress bar when the timer event starts.

 
First, define the timer object and related processing functions in the cprogressbarcontainer class. The reference code is as follows:

Class
Cprogressbarcontainer: Public ccoecontrol,
Mcoecontrolobserver

{

PRIVATE:


Static tint period (Tany * aptr );


Void dostep ();


Cperiodic * iperiodic
Timer;

}

 
Iperiodictimer is a periodic timer cperiodic object, and the period () function must be a static function, which serves as a callback function when a timer event is triggered.
Number, dostep () function is the function that actually increases the progress. These two functions are implemented in the cprogressbarcontainer. cpp file. The Code is as follows:

Void cprogressbarcontainer: dostep ()

{

Ipbar-> incrementanddraw ();

}

Tint cprogressbarcontainer: Period (Tany * aptr)

{

 
(Cprogressbarcontainer *) aptr)-> dostep ();

Return true;

}


The timer object is constructed before the timer is started, and then the START () function is used to start the timer. In the parameters of the START () function, in addition to the specified periodic scheduled event, the timer event is also specified.
The callback function that needs to be called during triggering. Here is the static function period () of the cprogressbarcontainer class. The reference code is as follows:

Iperiodictimer =
Cperiodic: newl (cactive: eprioritystandard );

Iperiodictimer-> Start (500000,200000, tcallback (cprogressbarcontainer: period, this ));

In the cprogressbarcontainer destructor, you must delete the timer object in addition to the progress bar control. The reference code is as follows:


Cprogressbarcontainer ::~ Cprogressbarcontaier ()

{

Delete
Ipbar;

If (iperiodictimer
! = NULL)

{

Iperiodictimer-> cancel ();

}

Delete
Iperiodictimer;

}

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.