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

Question on ENTER key

Hi there,
         I've got a problem whenever I run my visual c++ program, the main window popped up but whenever I pressed the ENTER key, it'll destroy itself. Is there any way to capture the ENTER key and stop the window from destroying itself when the ENTER key is pressed? For ur info. I'm using MSVC 5.0 and my program is dialog-based and I'm working on a win98 platform.

Any help offered will be very much appreciated!
0
justinng
Asked:
justinng
  • 5
  • 5
1 Solution
 
naveenkohliCommented:
Capture your OnOK button message. And don't call the base class's OnOK function. This is the one which is making your app to close down
e.g. for dialog box

CMyDialog::OnOK ()
{
   CDialog::OnOK ();
}

The above code will make the app to close. Instead you wanna to have

CMyDialog::OnOK ()
{
}
0
 
justinngAuthor Commented:
sorry but i didn't see any CDialog::OnOK (); hehee

0
 
justinngAuthor Commented:
sorry but i didn't see any CDialog::OnOK (); hehee

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
justinngAuthor Commented:
If i don't call the OnOK(); function... if there's a mouse click on the "Done" button... the window will not destroy itself... is there another other ways?
0
 
naveenkohliCommented:
You won't see OnOK () function call. You will have to override this call. And this will be the simplest solution to your problem.
0
 
justinngAuthor Commented:
Erm.. hehe... can u please tell me how to go about overwriting it? thanks!
0
 
justinngAuthor Commented:
I think I've overwritten it because the window won't destroy itself after I pressed the ENTER key but however.. when I clicked on the "Done" button... the program still cannot terminate... Is there any ways to terminate it when "Done" button is clicked?

0
 
naveenkohliCommented:
Simple solution..
At the end of Done () function ..put
CDialog::OnOK ()....

This will do the job for you.
0
 
naveenkohliCommented:
Sorry about the last solution...
This won't work...

0
 
naveenkohliCommented:
Alrite! Finally...

Call
 ::PostQuitMessage (int code) API function at the end of your Done () function. And code can be any integer you like. It simply represent the exit code.

I hope this will solve your problem.
0
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: 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.

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