?
Solved

Enter key doesn't work

Posted on 1998-08-14
10
Medium Priority
?
250 Views
Last Modified: 2013-11-20
After adding a tab control to my dialog app, I find that if I tab to a button on one of the child windows, the Enter key doesn't send a command message to the main window.  The spacebar does.  If I press enter while the focus is on a control on the main window, the program dies.  Please help.
0
Comment
Question by:duncan2
  • 8
  • 2
10 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 400 total points
ID: 1320839
Answer coming...
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320840
The program dies because the enter key is interpreted as pressing the default button in the dialog box.  The spacebar is the key that sends commands to the currently selected item in the dialog box.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320841
There will always be a default button, even if the box that says "Default button" is unchecked.  The default button check box is useful for overriding the default.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320842
In fact, even if there are no buttons in the app, the enter key will still close it, just as if there were.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320843
To prevent the enter key from doing anything, delete the default OK button, and put in your own.

Then go into class wizard, and add a function to handle what happens when the button is pressed.  In the function put in whatever code you had in the okay button that was already there.

But don't call the CDialog::OnOK member function.

After this your code will look something like:
void CYourDlg::OnNewOk()
{ // Your code here.

  // CDialog::OnOK ();
}

Then set this new button as the default button.  The enter key will now push your new button, not terminate the app.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320844
Now, if there were never any buttons in your app to begin with, simply override the CDialog::OnOK member function.  This new function should do nothing, i.e. it should look like this:

void CYourDlg::OnOK()
{ // Nothing here.
}

When you press the enter key, it will do nothing.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320845
If you have any questions about how to implement any of the above, or any other questions about anything, please ask.

Thank you.
0
 

Author Comment

by:duncan2
ID: 1320846
I don't have any buttons on the main dialog.  There used to be some buttons, so I guess that's why the enter key worked before.  It always activated either the default button or the button with the input focus.  Now it doesn't have a button, so it's closing the program.

If I override CDialog::OnOK, that may fix the problem of killing the program, but I don't think it will fix my other problem.  I have moved the buttons that were on the main dialog to the tab control's child windows.  When I use the Tab key to put the input focus on one of these buttons, pressing Enter should activate that button.  I have handlers for these buttons in the child dialog's class.  These handlers get called if I press the space bar, but not if I press Enter.  In a normal dialog (not a child), if the focus is on a button, pressing Enter will activate that button.  If you can solve this problem, It would be worth another 100 points to me.  Thanks for your help.
0
 

Author Comment

by:duncan2
ID: 1320847
I found an answer to my problem.  It turns out that when Enter is pressed while a button on a child window has focus, a message is sent to the main window instead of the child window containing the button.  If the spacebar is pressed, a message is sent to the child window.  I had to leave the handlers in the child's class to handle the spacebar, and manually add ON_BN_CLICKED macros to the main window class message map with handlers there as well to take care of the Enter key.

Overriding the OnOK function like you suggested fixed the other problem.  Thanks a lot.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1320848
Glad I could help :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

839 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