如何使子进程窗口在我的进程中显示为模态? [英] How can I make a child process window to appear modal in my process?

查看:30
本文介绍了如何使子进程窗口在我的进程中显示为模态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它调用其他一些实用程序来为特定设备设置一些设置.使用 ShellExecuteEx 调用该实用程序应用程序.

I have an application that calls some other utility application to set some settings for a particular device. That utility application is called using ShellExecuteEx.

为了不混淆用户,最好将实用程序应用程序的窗口设为我的主窗口.这是怎么做到的?

So as not to confuse the user, it would be better to made the window of the utility application modal to my main window. How does one do this?

我尝试过的事情:

  1. 在 ShellExecuteEx 之后的进程上 WaitForSingleObjectEx,无限超时 - 窗口是模态的,但主应用程序不会重绘(因为它正在等待单个对象!)
  2. WaitForSingleObjectEx 在 ShellExecuteEx 之后的进程上等待,一些小的超时,然后调用 Peekmessage 和 DispatchMessage - 重绘现在可以工作,但实用程序应用程序不再是模态".主应用程序响应鼠标点击、按钮点击等
  3. EnableWindow(FALSE),然后执行方法 #2,然后 EnableWindow(TRUE) - 有效!!!,但在此之后,我的应用程序的 z 顺序发生了变化.(它现在位于其他窗口下方).为什么?!

推荐答案

您需要模拟两件事:所有权和模态.

You have two things to simulate: ownership and modality.

模拟所有权:您需要将新子进程窗口的所有者设置为您的窗口.这应该可以缓解任何 z 排序问题.虽然我不知道这是否适用于另一个过程.如果没有,那么您可能必须附加您的线程输入队列,然后调用它.或者使用其他一些代码注入技术.

To simulate ownership: You need to set the owner of your new child process window to your window. This should alleviate any z ordering issues. Though I don't know if this works from another process. If not then you might have to attach your thread input queues and then call it. Or use some other code injection technique.

SetWindowLong <target window handle>, GWL_HWNDPARENT, <new owner handle>

为了模拟模态,我认为您使用 EnableWindow 和 WaitForSingleObjectEx 是正确的.

To simulate modality, I think you are on the right track with EnableWindow and the WaitForSingleObjectEx.

这篇关于如何使子进程窗口在我的进程中显示为模态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆