Debug assertion after closing a modal dialog

Posted on 2011-04-25
Last Modified: 2013-11-20
I have a dialog where I'm overriding the WM_LBUTTONDBLCLK event. When the event happens, I go to a function that launches a modal dialog box. After I close the dialog box, I get a debug assertion when the program exits the PreTranslateMessage function.

If I call the LaunchEditWindow function from a button click, there is no assertion.

BOOL CDlgPinOverview::PreTranslateMessage( LPMSG pMsg )
    if(::TranslateAccelerator(m_hWnd, m_hAccel, pMsg))

  if (pMsg->message ==WM_LBUTTONDBLCLK )

 return CDialog::PreTranslateMessage(pMsg);

void CDlgPinOverview::LaunchEditWindow(void)
	CEditDlg pPinEdit;



Open in new window

Question by:apostrophe27
    LVL 43

    Expert Comment

    I'm not certain exactly why this is happening but I guess it is because the button double click doesn't get processed properly before a new message loop (DoModal) is implemented.

    What you could do is use PostMessage to post a custom message to your dialog and in response to that you run your LaunchEditWindow function.

    The following article shows you how to create and respond to custom messages:
    LVL 16

    Accepted Solution

    After the call from LaunchEditWindow() returns inside of PreTranslateMessage, should you be returning a value of (TRUE) to indicate the message has been processed (like TranslateAccelerator() does) rather than dropping into the statement "return CDialog::PreTranslateMessage(pMsg);"?  Or do you really want the message to be processed again by the CDialog basecode?
    LVL 43

    Expert Comment

    I've just been having a look at this and actually both comments aren't correct.  Both just provide a workaround.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
    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 …
    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.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now