Is there a safe way to end a modal dialog from another thread?

Posted on 2009-12-16
Last Modified: 2013-11-25

Is there a safe and simple way to end a modal dialog from another thread in MFC/Win32?  I want to be able to force a modal dialog to close from elsewhere but just calling EndDialog() on it sometimes results in an Access Exception.

Question by:chrispauljarram
    LVL 33

    Accepted Solution

    Yes. Send WM_CLOSE to this dialog. For example:
    PostMessage(hDlg, WM_CLOSE, 0, 0);
    where hDlg is the dialog window handle.
    I hope this thread knows how to find the dialog.

    Author Closing Comment

    Cheers, that's fine :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    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 …
    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    737 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

    17 Experts available now in Live!

    Get 1:1 Help Now