开发者

Get handles to all windows of a process

开发者 https://www.devze.com 2022-12-19 15:21 出处:网络
In C# using the process class I can get the handle to the Main Window of a process but I ne开发者_开发问答ed access to a window that is not the main window of its process. How can I get the handle to

In C# using the process class I can get the handle to the Main Window of a process but I ne开发者_开发问答ed access to a window that is not the main window of its process. How can I get the handle to all of the windows of a process?


The EnumChildWindows function might help you out. The child windows could also have children and so on.

There is also GetWindow and EnumThreadWindows


You can P/Invoke GetWindowThreadProcessId() to get the thread ID for the UI thread that owns the main window. From there, you can find any other top-level window owned by that thread with EnumThreadWindows(). Any child windows (controls) owned by a top-level window can be found with EnumChildWindows(). Visit pinvoke.net for the necessary P/Invoke declarations.


P/Invoking the EnumThreadWindows function of user32, the callback you provide would be given the handles of the windows for a given thread. Process.GetCurrentProcess().Threads should return to you all the relevant threads with which to call EnumThreadWindows.

0

精彩评论

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

关注公众号