Embed a program UI into another one with modal dialogs in two separate Win32 processes
delphi
Solution
Modal forms work as follows:
- When the modal form is shown, it disables its owner window.
- This has the effect of making interaction with the owner impossible.
- When the modal window closes, it re-enables the owner.
But in your scenario modal windows in the secondary application won't be disabling the windows in the primary app. So to solve your problem you need to make sure that your secondary app reaches out to the primary app and disables the appropriate windows whilst the modal form is shown.
Modality is a somewhat tricky area. It's easy to get it wrong with all sorts of bad consequences. It took at least 10 releases of the VCL to get the handling of modality and window owner anywhere close to correct! Raymond Chen wrote a great serious of articles on modality and I'm sure you'll find them useful:
- Modality, part 1: UI-modality vs code-modality
- Modality, part 2: Code-modality vs UI-modality
- Modality, part 3: The WM_QUIT message
- Modality, part 4: The importance of setting the correct owner for modal UI
- Modality, part 5: Setting the correct owner for modal UI
- Modality, part 6: Interacting with a program that has gone modal
- Modality, part 7: A timed MessageBox, the cheap version
- Modality, part 8: A timed MessageBox, the better version
- Modality, part 9: Setting the correct owner for modal UI, practical exam
Problem
I have the need to embed the user interface (UI) of a secondary application into a primary application. I can easily host the secondary application main form into the primary application using SetParent. i'm using a named pipe to communicate between the two application. I can even resolve tabbing issues using AttachThreadInput API in the secondary application with the help of a dummy TEdit in the primary application. So far so good. I cannot solve the following: Any modal form in the secondary application is not seen as modal for the primary application and this cause major trouble. btw: Don't tell me to use a DLL, OCX nor ActiveX. I have two plain exe files. Any help / hint appreciated.