Updating a Gauge and Detecting a User Interrupt (C++ Builder)
Take the following steps to update a gauge during processing and detect a user interrupt:
1. |
Start with the project that you created in Loading and Displaying an Image. |
|
2. |
Add 2 Button controls to your main form. Put them at the top of the form to keep them away from the image. Name them as follows: |
|
|
Name |
Caption |
|
btnMedian |
Do Median |
|
btnQuit |
Quit |
3. |
Add a TrackBar control to your main Form, and change the Max property of it to 100. |
|
4. |
On the Project pull-down menu, use the Import Type library… and install the LEAD Raster Process object library (14.5). Press OK. |
|
5. |
Select LEAD Raster Process from the ActiveX tab and add it to your form. |
|
6. |
Add the following variables to the Private section of “Unit1.h” file: |
bool fEscape; //Use to indicate the user interrupt
bool fInProc; //Use to avoid closing the form during processing
7. |
Code the btnMedian Click’s procedure as follows: |
void __fastcall TForm1::btnMedianClick(TObject *Sender)
{
//Enable the ProgressStatus event
LEADRasterProcess1->set_EnableProgressEvent ( true );
//Initialize the indicators
fEscape = false; //The user does not want to quit
fInProc = true; //Processing is taking place
//Perform a relatively slow median filter
LEADRasterProcess1->Median (LEADRasterView1->Raster, 4);
//Clean up
fInProc = False; //Processing is no longer taking place
LEADRasterView1->ForceRepaint ();
}
8. |
Handle the LEADRasterProcess1’s OnProgressStatus and code LEADRasterProcess1ProgressStatus as follows: |
void __fastcall TForm1::LEADRasterProcess1ProgressStatus(TObject *Sender,
short iPercent)
{
Application->ProcessMessages (); //Detect Windows events
if (!fEscape) // Look for the Click on the Quit button
{
TrackBar1->Position= iPercent;
}
else
LEADRasterProcess1->set_EnableProgressEvent ( false ); //Cancel the task
}
9. |
Code the btnQuit click’s procedure as follows: |
void __fastcall TForm1::btnQuitClick(TObject *Sender)
{
fEscape= True; //The user wants to quit
TrackBar1->Position= 0 ;
}
10. |
Handle the Form1 OnCloseQuery event, and code FormCloseQuery procedure as follows: |
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if (fInProc) //If processing is taking place
CanClose= false; //Do not let the user close the form
}
11. |
Run your program to test it. |