Debug assertion after closing a modal dialog

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(m_hAccel)
 {
    if(::TranslateAccelerator(m_hWnd, m_hAccel, pMsg))
        return(TRUE);
 }


  if (pMsg->message ==WM_LBUTTONDBLCLK )
    {
         LaunchEditWindow();   
	}


 return CDialog::PreTranslateMessage(pMsg);
}




void CDlgPinOverview::LaunchEditWindow(void)
{
	CEditDlg pPinEdit;

	pPinEdit.DoModal();

}

Open in new window

apostrophe27Asked:
Who is Participating?
 
HooKooDooKuCommented:
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?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
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:
http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/A_3827-Sudoku-a-complete-MFC-application-Part-7.html
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
I've just been having a look at this and actually both comments aren't correct.  Both just provide a workaround.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.