Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how I've done this:</p> <pre><code>using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; public partial class MainForm : Form { #region Dll Imports private const int HWND_BROADCAST = 0xFFFF; private static readonly int WM_MY_MSG = RegisterWindowMessage( "WM_MY_MSG" ); [DllImport( "user32" )] private static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); [DllImport( "user32" )] private static extern int RegisterWindowMessage(string message); #endregion Dll Imports static Mutex _single = new Mutex(true, "{4EABFF23-A35E-F0AB-3189-C81203BCAFF1}"); [STAThread] static void Main() { // See if an instance is already running... if (_single.WaitOne(TimeSpan.Zero, true)) { // No...start up normally. Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Application.Run(new MainForm()); } catch (Exception ex) { // handle exception accordingly } finally { _single.ReleaseMutex(); } } else { // Yes...Bring existing instance to top and activate it. PostMessage( (IntPtr) HWND_BROADCAST, WM_MY_MSG, new IntPtr(0xCDCD), new IntPtr(0xEFEF)); } } protected override void WndProc(ref Message m) { if (m.Msg == WM_MY_MSG) { if ((m.WParam.ToInt32() == 0xCDCD) &amp;&amp; (m.LParam.ToInt32() == 0xEFEF)) { if (WindowState == FormWindowState.Minimized) { WindowState = FormWindowState.Normal; } // Bring window to front. bool temp = TopMost; TopMost = true; TopMost = temp; // Set focus to the window. Activate(); } } else { base.WndProc(ref m); } } } </code></pre> <p>I hope I've transcribed this correctly. I had to leave out a lot of other stuff, but I think I got what is necessary. What I have works for me without fail. If you have a problem, let me know, and I'll see what I've missed.</p>
    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.
    3. VO
      singulars
      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