Solved

changing button state enabled to disabled!

Posted on 2003-11-13
3
279 Views
Last Modified: 2013-11-20
hi!
During the course of the program, I want to change the state of the button from enabled to disabled, the button property is set to Enabled at the start of the program, when the window is displayed, Once I start the process of importing a file, I want to disable the Exit button provided so that the user is not able to stop the program.
Any ideas..
please help
thanks
rahul
0
Comment
Question by:Rahulsaxena
3 Comments
 
LVL 3

Accepted Solution

by:
freewell earned 50 total points
ID: 9745313
If it is in a dialogbox.
GetDlgItem(ID_EXIT)->EnableWindow(FALSE);

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9745796
I want to disable the Exit button provided so that the user is not able to stop the program.

the code from freewells above will cope with a button.  If it is on the toolbar use the OnUpdateCommandUI functionality.

HOWEVER if you do not provide some sort of message pumping the user can click as many times as he likes on the button and nothing should happen.  Also see what happens if the user switches to another app and back to yours re redrawing the screen.
If the progress takes a long time you may want to display a progress bar.
0
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9745933
If you also need to stop users from closing the app by clicking the cross in the top right hand corner, the best bet is to override OnCancel if it is a dialog, and to not call the base class OnCancel() if you are still processing, thus:

void CMyDialog::OnCancel()
{
    if (m_bProcessing) // Some flag that indicates processing is taking place
      AfxMessageBox("Cannot close application during processing");
   else
      OnCancel();
}

All the best
Martyn
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 55
Turn a spreadsheet into a vba executable. 2 78
List out all word 7 255
noX challenge 17 91
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now