Solved

Modeless dialog disappears in MFC, NOT caused by OnOK.

Posted on 2006-10-30
5
883 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
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Macro to save highlighted rows as a separate file 5 45
conditional code and condition difference 9 84
FizzBuzz challenge 9 82
sumHeights2  challenge 7 114
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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