I want to close a Modal Dialog when the thread ends. I know how to use PostMessage or SendMessage, but why can’t I directly call the EndDialog member function? If I do, it causes an App exception.
I want to close a Modal Dialog when the thread ends. I know how
Share
EndDialog needs to be called from the thread that created the modal dialog box, specifically the dialog box procedure. It sounds like you want to call it from another thread. To close the dialog from another thread, you will need to post a message as that is supported across threads. The dialog can then respond to the message and close itself. The calling thread needs to wait for the dialog box to close before destroying the thread.
If you’re wondering why this is, well most of the USER API functions have thread affinity. They were originally implemented in this way and were not designed to support use across threads.