|
-
June 23rd, 2005, 02:25 AM
#1
Toggle buttons
Hi all,
I am making a small tool, which scans a specific file on the whole hard drive. I am making this application via a small Dialog based application. My dialog window will have three buttons "Scan", "Exit" and "About". I have a doubt
1) When user clicks the "Scan" button, the "Exit" button should change to "Stop" so the user can click this "Stop" button to stop the scan, while my tool is scanning the hard drive. Basically this "Exit" should act like TOGGLE style.
How to do this ?
-
June 23rd, 2005, 02:27 AM
#2
Re: Toggle buttons
Code:
this->GetDlgItem(IDC_STOP)->SetWindowText( "Exit");
this is what you mean?
Cheers
-
June 23rd, 2005, 02:55 AM
#3
Re: Toggle buttons
Presumably, what you mean is that you don't want a user to exit while a scan is in progress.... I'd be tempted to use a slightly different logic. I think that once a scan was started, I'd change the "Scan" button to read "Stop" and I'd simply disable the "Exit" button while the app was scanning. That's only my personal preference though.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
June 23rd, 2005, 03:45 AM
#4
Re: Toggle buttons
hi john, thats a nice idea.. But i would like to know, how to do this ?
-
June 23rd, 2005, 04:02 AM
#5
Re: Toggle buttons
Pretty much as Golanshahar indicated...
Code:
GetDlgItem(IDC_SCAN)->SetWindowText( "STOP" );
GetDlgItem(IDC_EXIT)->EnableWindow( FALSE );
Of course, IDC_SCAN and IDC_EXIT would need to match your actual control ID's...!
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
June 23rd, 2005, 04:26 AM
#6
Re: Toggle buttons
thank you john. Now my other doubt is how to stop the scanning when the user presses the new Toggle button ("Stop") ?
-
June 23rd, 2005, 05:01 AM
#7
Re: Toggle buttons
Well that may depend upon the way your scan function has been implemented. I think Already we have made a lot of guess work here.....
Regards
Ashwin
-
June 23rd, 2005, 06:59 AM
#8
Re: Toggle buttons
Why don't you use radio buttons with "Push-like" style??
Regards
Robert Thompson
-
June 23rd, 2005, 07:11 AM
#9
Re: Toggle buttons
If I understand you correct, this is what you need :
Code:
bScanning = FALSE ;
void OnPressedScanButton
{
if (!bScanning)
{
GetDlgItem(IDC_SCAN)->SetWindowText( "STOP" );
GetDlgItem(IDC_EXIT)->EnableWindow( FALSE );
bScanning = true ;
}
else
{
GetDlgItem(IDC_SCAN)->SetWindowText( "SCAN" );
GetDlgItem(IDC_EXIT)->EnableWindow( TRUE );
bScanning = false ;
}
}
-
June 25th, 2005, 12:22 PM
#10
Re: Toggle buttons
Hi all,
I am having a problem in Toggle buttons. I have a Toggle button "Scan" & "Stop". When I click "Scan" button, my app will scan the hard drive and button will change to "Stop". But, after i press "Stop" button I want to stop scanning. How to do this ? I tried using the flags. But it's not happening . How to solve this ?
-
June 25th, 2005, 12:44 PM
#11
Re: Toggle buttons
You've tried using the flags?
In your Scan code, is there a while(...) or for(...) operation going on ?
If so, when the user hits "Stop", set a BOOL variable. Each time it loops through the while() operation, for example, have it check the value of that BOOL variable. If it's set, then break out of the operation.
before the operation:
BOOL bStop = FALSE;
User hits the "Stop" button, so:
bStop = TRUE;
while (...)
{
if (bStop)
break;
...
...
...
}
-
June 25th, 2005, 12:58 PM
#12
Re: Toggle buttons
hi RCFOx,
I tried already as U said. but that too not happening. See my sample below:
bool Scanning = FALSE;
OnScan()
{
if(Scanning == FALSE)
{ Scanning = TRUE; }
else if(Scanning == TRUE)
{ Scanning = FALSE; }
while(EndOfDrive || Scanning != FALSE)
{
if(Scanning == FALSE){ break };
ScandDir();
}
}
void ScanDir()
{
do
{
if(Scanning == FALSE){ break };
}While(EndOfFile || Scanning != FALSE);
}
But, when I press "Stop" it's not going to OnScan().. what to do ?
-
June 26th, 2005, 05:24 AM
#13
Re: Toggle buttons
But, when I press "Stop" it's not going to OnScan().. what to do ?
[/QUOTE]
I think your troubles are here:
Code:
bool Scanning = FALSE;
OnScan()
{
if(Scanning == FALSE)
{ Scanning = TRUE; }
else if(Scanning == TRUE)
{ Scanning = FALSE; }
while(EndOfDrive || Scanning != FALSE) //<-------
{
if(Scanning == FALSE){ break }; <--- This only needed in ScanDir() itself
ScandDir();
}
}
OnScan() is still executed because of the while statement. The while statement needed for the scanning has to be in your ScanDir() function so you dont need it twice. And dont run the ScanDir() in the OnScan() Send a Userdefined message to start Scandir() if ( Scanning ==TRUE) and dont send it when it is false. because the if(Scanning == FALSE){ break };
Code:
#define WM_EXECUTESCAN (WM_USER+1)
// This is a class member
bool Scanning = FALSE;
OnScan()
{
if(Scanning == FALSE)
{
Scanning = TRUE;
SendMessage(WM_EXECUTESCAN);
} else
Scanning = FALSE;
}
And then create a Handler with the wizzard ( So you can be sure he is also in the Message Map
Code:
OnExecuteScan()
{
ScanDir();
}
Jonny Poet
Last edited by JonnyPoet; June 26th, 2005 at 05:51 AM.
Reason: expanding information
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
June 26th, 2005, 05:44 AM
#14
Re: Toggle buttons
 Originally Posted by Extreme_Coder
But, when I press "Stop" it's not going to OnScan().. what to do ?
That's because your scanning task is executed in a loop within your main (UI) thread - and that prevents the thread from processing messages, making your UI unresponsive. The usual approach to this kind of problem is to do the scanning in a worker thread.
-
June 26th, 2005, 06:01 AM
#15
Re: Toggle buttons
 Originally Posted by gstercken
The usual approach to this kind of problem is to do the scanning in a worker thread.
Sorry I didn't look at that, but thats clear Your ScanDir() has to start a new thread, which has to be stopped when Scanning changes to false.
In VB you would have set a DoEvent() statement into the loop of ScanDir() and then it would have got the message. I never have heard about a similar solution in VC++ I'm frightened there in no such an 'more easy' approach also possible in VC++ ?? If needed tell me. I'll try to do a Working thread solution for you. ( It just fits to my study to train that )
Jonny Poet
Last edited by JonnyPoet; June 26th, 2005 at 06:55 AM.
Reason: Adding Information
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|