简体   繁体   中英

Parent dialog receiving WM_CLOSE when child process exits

I have a situation where my C# application uses a mix of 32 bit and 64 bit DLLs when running on a 64 bit machine. My main UI has to be 64 bit and a child dialog has to be 32 bit. To address this problem I launch the 32 bit version of the app from the 64 bit version and wait for it to exit. I use Anonymous pipes to get the results of the child dialog back to the 64 bit process. I pass the parent window handle to child process so the child dialog from 32 bit process will be modal to the main dialog in parent process. This works very nicely but the problem is when the child process closes the parent dialog in the 64 bit process receives a WM_CLOSE message and the application exists. How can I prevent this while still making the child dialog in the 32 bit process modal to the parent dialog in the 64 bit process?

If I don't pass the parent dialog window handle the application does not close.

I found when I tried this sometimes the child window would hang. Other posts on here suggests you cannot set the parent of a dialog to a dialog from a different thread.

To solve the problem I did the following:

  1. Call EnableWindow(parent, false) before starting the child process
  2. Pass the main forms handle to the child process on command line.
  3. Call SetWindowLong(child, GWL_HWNDPARENT, parent) on the child dialog's handle in the child process
  4. Call EnableWindow(parent, true) when child process ends

All works nicely now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM