开发者

How to get window opened/closed/minimized messages from a native app?

It's tough to write a good title for this one.

I'm working on a WPF application which needs to know about the existence of all other open windows on the system. I'm able to do this by calling the native EnumWindows method just fine, and I can call other native methods to filter out just the windows I'm interested in. This works well.

The problem I'm having is that I want to know when a window is opened or closed (and, ideally, minimized). I can do this 开发者_JS百科by polling with EnumWindows, but I'm finding that to be pretty slow, even if I push it off to another thread.

Is there a better way to get notifications of window opened/closed/minimized? Keep in mind that my knowledge of non-managed code is pretty limited.


You can use windows hook for this type of thing.

Basically once setup your hook, your callback will be called whenever the messages you're interested get called.

There is a good example on codeproject for setting global system wide hooks with C# code.
Note: There is a unmanaged c++ component to this project, but you don't need to work with it directly.


WM_WINDOWPOSCHANGING Message

http://msdn.microsoft.com/en-us/library/ms632653%28VS.85%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜