• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Application terminates when i hit enter ???


My application terminates when i hit enter ???

  • 4
  • 3
  • 2
  • +3
1 Solution
If it's a dialog based application, then Enter = OK, closing the dialog.

Remove the OK button (or change it from IDOK to some other value in the resources)

If it's not this, you need to give us a bit more information
Override the OnOK() function, and comment out the
kashif063098Author Commented:
This is not my problem because i don't have this kind of code "CDialog:OnOk"
thank you anyway
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Answer coming...
Open your main window's header file (called something like MyDlg.h).  Add this text:

void OnOK ();

right below the first "public:" (consider going to Edit-Find and searching for it if you are not sure.  Place the code immediately after the first instance of the text you find.  Of course, do not type the quotation marks "").

Next, go to your main windows implementation file (called something like MyDlg.cpp, notice the extension).  Add this text to the very bottom of it:

void CWhateverTheClassNameForYourDialogIs::OnOK ()

Recompile the project by hitting F7 or something like that, and then run it.  That should do it!

If you have any questions regarding this, please ask!  Thanks!
>> This is not my problem because i don't have this kind of code "CDialog:OnOk"

If you don't override OnOK in a dialog app, the default implementation gets called when the user presses a button with IDOK.  The default implementation closes the dialog and therefore the app.  Remove the call to the base class (by overriding OnOK as thresheer suggests) or change the id of the button.

If your app isn't dialog based, you need to give us more information to go on.  Try describing your app (Dialog, SDI, MDI based, anything else you might think relevant, etc.)
There is something here that I do not understand. Why do you have to override the OnOK when you just have to remove the OK button or change the id associated with it (as Answers2000 proposed)? In this way you simply generate some overhead.....
bobbym - You don't need to override OnOK if you change the id.

If you don't change the id, you need to change how OnOK is processed.

Which is better kinda depends

1. If you change the id, OK won't respond to Enter keystroke

2. If you override OnOK, enter will still trigger the OK button.  Maybe Q'ster want an OK button which won't close the app.

kashif063098Author Commented:
your solution did not help ...
the problem is my application is dialog based(MFC wizard) MFC by its put the code like

CDemo_6Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
so when ever i press enter DoModal() returns and that terminates my application.

thank you  !!!

Yes, I know that, you see, you want to implement my solution in a file named something like:

The last part of the file will always have "Dlg.cpp" on it.  That is where you want to implement my solution.

You do NOT want to do any of my suggestion in the file that is just "your_application_name_goes_here.cpp"
It looks like in your case the file you want to make my changes to is called "Demo_6Dlg.cpp" and "Demo_6Dlg.h"
Dear brother,

1. Ok and Enter both calls OnOk().
2. Even though you don't have OnOk function,
    override the OnOk() funciton.
3. That solves your problem
4. You can close your dialog by using
    EndDialog() function.

Any doubts please mail me
directly to Bhavani_73@hotmail.com.

with love,
Bhavani P Polimetla

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now