Solved

Modeless dialog disappears in MFC, NOT caused by OnOK.

Posted on 2006-10-30
5
887 Views
Last Modified: 2013-11-20
I have a modeless dialog box derived from CDialog with OnOK and OnCancel both overridden as {}. However, if the dialog itself has focus (ie not a button, radiobox, etc) and the user presses SPACE, RETURN, or ENTER the box becomes invisible but is not destroyed. Any idea of what messages/commands I should be looking for that would cause this to happen?
0
Comment
Question by:rosenav
[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
  • 2
5 Comments
 
LVL 1

Expert Comment

by:mac-will01
ID: 17839524
This is strange behaviour.  I just quickly tried a dummy project and I found that I didn't get this behaviour.
Can you post some code maybe?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 17840326
Override PreTranslateMessage function:

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
    if( pMsg->message == WM_KEYDOWN )
    {
        if( pMsg->wParam == VK_RETURN ||  pMsg->wParam == VK_ESCAPE )  
        // AFAIK, Enter or Escape close the dialog. You can add other keys to ignore, for example, VK_SPACE
        {
            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE;
        }
    }
      
    return CDialog::PreTranslateMessage(pMsg);
}
0
 

Author Comment

by:rosenav
ID: 17843099
Great suggestion AlexFM. Didn't solve my problem but it did show that the dialog isn't recieving RETURN or ESC keys. In fact, nothing on the dialog has the little dotted-line focus highlight painted on it until I specifically click one of the controls. After that point it behaves as expected (doesn't disappear anymore). Is there a reliable way to force a control to have the focus?
0
 

Author Comment

by:rosenav
ID: 17843340
I still don't know why the dialog was disappearing but I was able to make it stop by forcing an arbitrary control in the dialog to have the focus.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 146
VBA "SendKeys" Syntax for Multiple Keystrokes 7 126
post4 challenge 28 113
Problem to event 3 114
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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