Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Enter key doesn't work

Posted on 1998-08-14
10
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

715 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