简体   繁体   English

等待另一个应用程序窗口

[英]Waiting for another application window

What is the best way (with a view to optimization and using system resources) to make waiting in my application when window of another app will be shown? 当显示另一个应用程序的窗口时,在我的应用程序中等待的最佳方法是什么(以优化和使用系统资源为目的)?

For example: 例如:

  1. My application starts. 我的应用程序启动。
  2. Waiting while, for example, Notepad will be started so i can get handle of its window. 等待一会儿,例如, 记事本将启动,以便我可以获取其窗口的句柄。
  3. Using handle im doing something with it and then closing my app. 使用handle im对其进行处理,然后关闭我的应用程序。

How to accomplish item 2? 如何完成第2项? I know only one possible way: just check if handle exists in loop using FindWindow . 我只知道一种可能的方法:只使用FindWindow检查句柄是否存在于循环中。 But I hope there is a more smart solution exists. 但我希望存在更智能的解决方案。

If you launched the process (with CreateProcess ) use WaitForInputIdle and then start the FindWindow loop. 如果启动了该过程(使用CreateProcess ),请使用WaitForInputIdle ,然后启动FindWindow循环。 Adding a Sleep(20) or something to the loop will ensure your resource usage is minimal. 在循环中添加Sleep(20)或其他内容将确保您的资源使用最少。

I dont think the same... I think the best way is windows hooking process... USING HOOKS 我不这么认为...我认为最好的方法是Windows挂钩过程... 使用钩子

... Please see: WH_CBT and you have to be watching the event: HCBT_CREATEWND ...请参阅: WH_CBT ,您必须观看事件: HCBT_CREATEWND

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

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