MFC application and modal dialogue without MFC

I am writing a Win32 plug-in DLL for a third-party MFC application. The DLL should display a modal dialog. When I do this using DialogBox() or another simple Win32 API (for example, I tried to write my own modal loop), the main application window does not redraw all the elements: it redraws the standard elements, but not the client area. Modeless dialogs display very well.

Screen shot

I suspect this is happening because MFC does not really have modal dialogs in the sense of Win32. It can have only one message loop, and a separate loop in DialogBox() disrupts its delicate mechanism. Here's a CodeProject article that explains this. But this CodeProject article is 9 years old, so perhaps the situation has changed since then. Can anyone shed some light on this? The application uses MFC 8 (i.e. mfc80.dll ).

Update . Here is a link to the original question ; It may contain some additional information.

Update 2 . Thanks to all; I really appreciate all the advice, it certainly helps me get a general picture of how everything fits together. The first way I'm going to learn is to use my own MFC-modal dialogs. (Since I am doing all this from Python, I will use Python bindings for MFC, pywin32 ). It will take some time; when it is ready, I update the message with the results.

+7
source share
1 answer

Each thread can have a message outline. Put your modal dialog box in a separate thread and emulate standard Windows behavior by disabling the parent window.

Edit: after some discussion (see below), it seems that the parent code is behaving incorrectly.

However, I think workarounds are possible. One of them may be a parent window (in a modal dialog box, but with a child window in relation to the one that is currently behaving incorrectly), which overlaps the erroneous contents of the window, but redraws it from DC to memory to simulate the correct behavior. Of course, the parent window should still be disabled. Another solution might be to subclass the parent window to fix the behavior. Since the plugin will work within the same process, the implementation should be simple.

+4
source

All Articles