PDA

Click to See Complete Forum and Search --> : Same Question Again, and Again...


Vlatko
Oct 1st, 2000, 12:58 PM
I had posted this before but got no answers so i hope that somebody learnt something new. I am using MFC to be more precise my app is a dialog.Now the problem is that the app(dialog) terminates when the user presses Enter or Escape.
How can i disable this.

parksie
Oct 1st, 2000, 02:03 PM
Look in the InitInstance member function of the application object (the one derived from CWinApp). The comments there should give you enough information for the specifics of your project. Incidentally, why do you want it to keep running even though the dialogue has closed?

Vlatko
Oct 1st, 2000, 03:33 PM
I removed the IDOK and IDCANCEL handlers in the InitInstance
but the app still terminates when the user presses Enter or Esc.I think that when you show a window using DoModal() it terminates by default when Esc or Enter is pressed.Can this be changed.

BOOL CCdApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size of your final executable, you should remove from the following the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

CCdDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

// Since the dialog has been closed, return FALSE so that we exit the application, rather than start the application's message pump.
return FALSE;
}

parksie
Oct 2nd, 2000, 12:20 PM
Try overloading the event handlers in your dialogue (I think it's OnOK and OnCancel that need to be made - look under ClassWizard).

Alternatively, if you change the dialogue IDs away from IDOK and IDCANCEL to something more descriptive like IDC_BTN_OK, then you'll have more readable code and no more random escapes in one go.

Vlatko
Oct 2nd, 2000, 12:56 PM
I just read in a book that OnOk() and OnCancel() functions are member functions of the CDialog class ,from which my class derives.When someone presses Esc Or Enter it automatically calls one of this functions.I will try to solve this.But help is also needed.

hitcgar
Oct 4th, 2000, 03:41 PM
Parksie's right (again!) - if you really need to inherit from CDialog then you'll have to override the event handlers.

This means that you'll either have to intercept these events and treat them in a WM_COMMAND message handler (like without MFC) or override the OnCancel (OnOk doesn't work with ESC) method with your own CDialog-derived class' code.

Something like this:

// in .h file inside class def in protected section
afx_msg void OnCancel();
// in .cpp
void CMfcTestDlg::OnCancel()
{
// do nothing
}


Pressing ESC will no longer cause a close.
;)