简体   繁体   English

子进程退出时,父对话框收到WM_CLOSE

[英]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. 我遇到的情况是,我的C#应用​​程序在64位计算机上运行时会同时使用32位和64位DLL。 My main UI has to be 64 bit and a child dialog has to be 32 bit. 我的主用户界面必须为64位,子对话框必须为32位。 To address this problem I launch the 32 bit version of the app from the 64 bit version and wait for it to exit. 为了解决此问题,我从64位版本启动了32位版本的应用程序,并等待其退出。 I use Anonymous pipes to get the results of the child dialog back to the 64 bit process. 我使用匿名管道将子对话框的结果返回到64位进程。 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. 我将父窗口句柄传递给子进程,因此32位进程的子对话框将对父进程中的主对话框模态化。 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. 这可以很好地工作,但是问题是当子进程关闭64位进程中的父对话框时,会收到WM_CLOSE消息,并且该应用程序存在。 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? 在仍将32位进程中的子对话框设置为64位进程中的父对话框的模态的同时,如何防止这种情况呢?

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 在启动子进程之前调用EnableWindow(parent,false)
  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 在子进程中的子对话框的句柄上调用SetWindowLong(child,GWL_HWNDPARENT,parent)
  4. Call EnableWindow(parent, true) when child process ends 子进程结束时调用EnableWindow(parent,true)

All works nicely now. 现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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