Disappearing Dialog

Posted on 2001-07-28
Medium Priority
Last Modified: 2013-11-20
I have dialog-based application in which a dialog box is displayed once the user presses a button on the initial screen.  The problem is if the user presses the "ENTER" key in one of the edit boxes of the dialog box, the dialog box closes and the focus shifts back to the initial screen.  How can I make it so that the dialog box does not close (or disappear) until the user presses the "OK" button?
Question by:cneaton
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
LVL 32

Accepted Solution

jhance earned 150 total points
ID: 6330177
Add a handler for OnOK using the Class Wizard and be sure to do something other than call the CDialog::OnOK() handler which will close the dialog.

Expert Comment

ID: 6330462
Your "OK" button is set as default button. As a result, Pressing the "ENTER" button will amount to clicking on the "OK" button. Change the style of the "OK" button by unchecking the "Default" style.


Expert Comment

ID: 6330636
I meant changing the properties of the "OK" button by unchecking the "Default button" style.
Independent Software Vendors: 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 42

Expert Comment

ID: 6330822
do u have an OK button on your dialog?
if u do, change its ID to ID_OK and handle its click:

Expert Comment

ID: 6331625
Since he still wants to allow the user clicking OK to close the dialog box, he does not need to do anything with his OnOK() handler. Simply changing the property of the OK button will do the job.

Expert Comment

ID: 6335788
hi cneaton,

how are you getting along with your problem? were you able to get it work or you still need more clarification?


Expert Comment

ID: 6336858
The comments given previously will exactly predict ur problem and u can solve them easily. I will give it some more clear (It will be useful if u are a biginner).

Please know some some thing about the property Default of a push button.

When u log into windows or some other application u might have found that after typing ur password just pressing enter will (accepts ur password) close the login dialog and logs u in (Keep in mind that u haven't pressed the OK button). This happens because of the Default property of the OK Button.

If u press Esc key on the same dialog u might have found the dialog closes ignoring ur password and other changes this is due to the Cancel property of the Cancel Button in the doalog.

As in the previous comments remove the Default property of the OK button. To do that right-click on the OK button select properties. in the properties dialog go to styles Tab there uncheck the Default Button check box.

Expert Comment

ID: 6336859
If ur dialog still closes due to Esc/Enter Keys I will give u the code to remove that (if u want it) !!

Expert Comment

ID: 6336973
 Open the EditBox properties window and check mark the  style "Want Return", this will solve the problem.
-- PK

Author Comment

ID: 6340192
Hello everyone, and thanks for the comments.  My dialog didn't have an "OK" button on it, so I just overrode the OnOK function since the dialog equated pressing the "ENTER" key to hitting the OK button.  Thanks again for all of your help!

Featured Post

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

Question has a verified solution.

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

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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