简体   繁体   English

使用Win32 API挂钩获取新创建的窗口

[英]Get newly created window using Win32 API hooks

This may be a long short or not even possible but no harm in asking. 这可能是一个很长的空缺,甚至是不可能的,但是问问没有任何伤害。

What I am trying to do is monitor an application for any new windows it creates in its MDI control. 我想做的是监视应用程序在其MDI控件中创建的任何新窗口。 I have implemented hooking in C# and can capture the MDICREATE window message but because I need to get information about the window after is has been created the MDICREATE message isn't much help because at that stage the window hasn't been created in the other application yet. 我已经在C#中实现了钩子,并且可以捕获MDICREATE窗口消息,但是由于创建后需要获取有关窗口的信息,因此MDICREATE消息并没有太大帮助,因为在那个阶段尚未在其他窗口中创建窗口申请呢。

Without going into to much detail I just need to be able to see when a new window has been created. 无需赘述,我只需要能够看到何时创建了新窗口。

Is this possible? 这可能吗?

Thanks 谢谢

I'm not aware of another message that gets the info that you are looking for off hand. 我不知道有另一条消息可以获取您正在寻找的信息。 But if that message works for you, you could hook that message and then do another scan of the windows to find the one you are missing. 但是,如果该消息对您有用,则可以挂接该消息,然后对窗口进行另一次扫描以查找丢失的窗口。 You can enumerate the child windows of the parent window. 您可以枚举父窗口的子窗口。 Use Spy++ to see the exact window hierarchy. 使用Spy ++查看确切的窗口层次结构。

If you can watch for a particular function call, I would use some kind of hooking library to grab that (EasyHook comes to mind). 如果您可以观看特定的函数调用,则可以使用某种挂钩库来抓取(想到了EasyHook)。

You can hook the MDI create function (assuming there is one), watch for that, then inn your code, call the original and do any lookups using the returned value. 您可以挂钩MDI创建函数(假设有一个),注意这一点,然后编写您的代码,调用原始代码并使用返回的值进行任何查找。 You'll have access to the returned value and any parameters, so you should be able to get some info out of those. 您将有权访问返回的值和任何参数,因此您应该能够从中获取一些信息。

Two options off the top of my head. 我头顶上有两个选择。

  1. Hook the WM_MDIACTIVATE event, the first time the window is being activated, use a flag to determine the first time the window is being activated. 在第一次激活窗口时挂接WM_MDIACTIVATE事件,使用标志来确定第一次激活窗口。

  2. If you need to run your code after the WM_MDICREATE or WM_MDIACTIVATE, you can post a new custom message from one of these messages, which is then handled after these messages have completed. 如果需要在WM_MDICREATE或WM_MDIACTIVATE之后运行代码,则可以从这些消息之一中发布新的自定义消息,然后在这些消息完成之后进行处理。 You then write your code to handle the custom message. 然后,您编写代码以处理自定义消息。

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

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