Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually after looking at the code jlvaquero posted above I found the following on the same site </p> <p><a href="http://pinvoke.net/default.aspx/user32/EnumDesktopWindows.html" rel="nofollow">EnumDesktopWindows (user32)</a></p> <p>I added the following using statements to my laucher script:</p> <ol> <li><code>using System.Text;</code></li> <li><code>using System.Runtime.InteropServices;</code></li> </ol> <p>I then added the following class to my launcher script</p> <pre><code> /// &lt;summary&gt; /// EnumDesktopWindows Demo - shows the caption of all desktop windows. /// Authors: Svetlin Nakov, Martin Kulov /// Bulgarian Association of Software Developers - http://www.devbg.org/en/ /// &lt;/summary&gt; public class user32 { /// &lt;summary&gt; /// filter function /// &lt;/summary&gt; /// &lt;param name="hWnd"&gt;&lt;/param&gt; /// &lt;param name="lParam"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public delegate bool EnumDelegate(IntPtr hWnd, int lParam); /// &lt;summary&gt; /// check if windows visible /// &lt;/summary&gt; /// &lt;param name="hWnd"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWindowVisible(IntPtr hWnd); /// &lt;summary&gt; /// return windows text /// &lt;/summary&gt; /// &lt;param name="hWnd"&gt;&lt;/param&gt; /// &lt;param name="lpWindowText"&gt;&lt;/param&gt; /// &lt;param name="nMaxCount"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; [DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount); /// &lt;summary&gt; /// enumarator on all desktop windows /// &lt;/summary&gt; /// &lt;param name="hDesktop"&gt;&lt;/param&gt; /// &lt;param name="lpEnumCallbackFunction"&gt;&lt;/param&gt; /// &lt;param name="lParam"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; [DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)] public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam); } </code></pre> <p>I then added the following function in my launch script to call the new class and do the processing to discover the active windows</p> <pre><code>/// &lt;summary&gt; /// Checks if application window open. /// &lt;/summary&gt; /// &lt;returns&gt;&lt;/returns&gt; private static bool IfApplicationWindowOpen(string windowName) { List&lt;string&gt; collection = new List&lt;string&gt;(); user32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder strbTitle = new StringBuilder(255); int nLength = user32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); if (user32.IsWindowVisible(hWnd) &amp;&amp; string.IsNullOrEmpty(strTitle) == false) { collection.Add(strTitle); } return true; }; if (user32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { foreach (string item in collection) { if (item.ToString().Equals(windowName)) { return true; break; } } } return false; } </code></pre> <p>And finally I modified my launch function to include the check for the active windows</p> <pre><code>/// &lt;summary&gt; /// Starts the new customer. /// &lt;/summary&gt; /// &lt;param name="param"&gt;The param.&lt;/param&gt; public static void StartNewCustomer(Parameter param) { string windowName = "New Customer"; if (!IfApplicationWindowOpen(windowName)) { GlobalFactory globalfactory = param.GlobalFactory; try { Generic objNewCustomer = new Generic(); objNewCustomer.StartNewCustomerFromCustomer(param); } catch (TypeInitializationException tx) { globalfactory.ErrorHandler.Log(tx, (int)msmsError.ErrorSeverity.Major | (int)msmsError.ErrorSeverity.User); } catch (Exception ex) { globalfactory.ErrorHandler.Log(ex, (int)msmsError.ErrorSeverity.Major | (int)msmsError.ErrorSeverity.User); } } else { MessageBox.Show("The application " + windowName + " is already open", windowName + ": Launch Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } </code></pre> <p>Hope this helps anyone else with the same problem</p> <p>Regards,</p> <p>Comic Coder</p>
 

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