How to get list or enumerate all handles of unmanaged windows with same class and name

只谈情不闲聊 提交于 2019-12-22 11:23:53

问题


Using pinvoke I can find Handle of a window with particular class & name easily:

[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = FindWindow("Foo Class", "Foo Window");

The above code works perfect if there is only 0 or 1 matching windows. However the unmanaged application I am working with spans multiple windows. Calling FindWindow multiple times returns the same Window Handle each time.

What do I need to do to get ALL windows with particular class and name.

I will also accept answer for alternate solution the same goal. (I am thinking maybe it can be done by finding process ID of application and then getting all top level windows, and filtering for the ones needed).


回答1:


You probably need to call EnumWindows to enumerate ALL top-level windows. You'll have to use their window handles to get their titles and window class information.

See http://www.pinvoke.net/default.aspx/user32/enumwindows.html for an example that does very close to what you're asking.



来源:https://stackoverflow.com/questions/6237249/how-to-get-list-or-enumerate-all-handles-of-unmanaged-windows-with-same-class-an

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!