|
-
Oct 1st, 2000, 12:58 PM
#1
Thread Starter
Frenzied Member
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.
-
Oct 1st, 2000, 02:03 PM
#2
Monday Morning Lunatic
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?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 1st, 2000, 03:33 PM
#3
Thread Starter
Frenzied Member
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.
Code:
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;
}
-
Oct 2nd, 2000, 12:20 PM
#4
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 2nd, 2000, 12:56 PM
#5
Thread Starter
Frenzied Member
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.
-
Oct 4th, 2000, 03:41 PM
#6
Lively Member
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:
Code:
// 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.
C/C++,Delphi, VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
I love deadlines. I like the whooshing sound they make as they fly by.
—Douglas Adams
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
|