Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Original Answer</h2> <p>Use <code>EnumWindows</code> and enumerate through all the windows, using <code>GetWindowText</code> to get each window's text, then filter it however you want.</p> <pre><code>[DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount); [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam); // Delegate to filter which windows to include public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); /// &lt;summary&gt; Get the text for the window pointed to by hWnd &lt;/summary&gt; public static string GetWindowText(IntPtr hWnd) { int size = GetWindowTextLength(hWnd); if (size &gt; 0) { var builder = new StringBuilder(size + 1); GetWindowText(hWnd, builder, builder.Capacity); return builder.ToString(); } return String.Empty; } /// &lt;summary&gt; Find all windows that match the given filter &lt;/summary&gt; /// &lt;param name="filter"&gt; A delegate that returns true for windows /// that should be returned and false for windows that should /// not be returned &lt;/param&gt; public static IEnumerable&lt;IntPtr&gt; FindWindows(EnumWindowsProc filter) { IntPtr found = IntPtr.Zero; List&lt;IntPtr&gt; windows = new List&lt;IntPtr&gt;(); EnumWindows(delegate(IntPtr wnd, IntPtr param) { if (filter(wnd, param)) { // only add the windows that pass the filter windows.Add(wnd); } // but return true here so that we iterate all windows return true; }, IntPtr.Zero); return windows; } /// &lt;summary&gt; Find all windows that contain the given title text &lt;/summary&gt; /// &lt;param name="titleText"&gt; The text that the window title must contain. &lt;/param&gt; public static IEnumerable&lt;IntPtr&gt; FindWindowsWithText(string titleText) { return FindWindows(delegate(IntPtr wnd, IntPtr param) { return GetWindowText(wnd).Contains(titleText); }); } </code></pre> <p>For example, to get all of the windows with "Notepad" in the title:</p> <pre><code>var windows = FindWindowsWithText("Notepad"); </code></pre> <h2>Win32Interop.WinHandles</h2> <p>This answer proved popular enough that I created an OSS project, <a href="https://github.com/zastrowm/Win32Interop.WinHandles" rel="noreferrer">Win32Interop.WinHandles</a> to provide an abstraction over IntPtrs for win32 windows. Using the library, to get all of the windows that contains "Notepad" in the title:</p> <pre><code>var allNotepadWindows = TopLevelWindowUtils.FindWindows(wh =&gt; wh.GetWindowText().Contains("Notepad")); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload