Solved

Application terminates when i hit enter ???

Posted on 1998-09-22
12
341 Views
Last Modified: 2013-11-19
hi,

My application terminates when i hit enter ???

thanks
0
Comment
Question by:kashif063098
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1322436
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
0
 

Expert Comment

by:jubjub
ID: 1322437
Override the OnOK() function, and comment out the
//CDialog:OnOK();
0
 

Author Comment

by:kashif063098
ID: 1322438
This is not my problem because i don't have this kind of code "CDialog:OnOk"
thank you anyway
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1322439
Answer coming...
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1322440
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!
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1322441
>> 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.)
0
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.

 

Expert Comment

by:bobbym
ID: 1322442
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.....
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1322443
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.

0
 

Author Comment

by:kashif063098
ID: 1322444
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  !!!

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1322445
Yes, I know that, you see, you want to implement my solution in a file named something like:
myDlg.cpp

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"
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1322446
It looks like in your case the file you want to make my changes to is called "Demo_6Dlg.cpp" and "Demo_6Dlg.h"
0
 
LVL 1

Accepted Solution

by:
polimetla earned 50 total points
ID: 1322447
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
Bhavani_73@hotmail.com


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
Perl Awk Need Help 3 109
wordmultiple challenge 12 121
Sed question 2 69
Capture logon name 13 42
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

895 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

18 Experts available now in Live!

Get 1:1 Help Now