[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

changing button state enabled to disabled!

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
Rahulsaxena
Asked:
Rahulsaxena
1 Solution
 
freewellCommented:
If it is in a dialogbox.
GetDlgItem(ID_EXIT)->EnableWindow(FALSE);

0
 
AndyAinscowCommented:
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
 
martynjpearsonCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now