'중복 실행'에 해당되는 글 1건

  1. 2009.07.28 C# :: 프로그램 중복 실행

[System.Runtime.InteropServices.DllImport( "user32.dll" )]
  public static extern void BringWindowToTop( IntPtr hWnd );
  [System.Runtime.InteropServices.DllImport( "user32.dll" )]
  public static extern void SetForegroundWindow( IntPtr hWnd );

  [System.Runtime.InteropServices.DllImport( "user32.dll" )]
  public static extern IntPtr FindWindow( string lpClassName, string lpWindowName );

  [System.Runtime.InteropServices.DllImport( "user32.dll" )]
  public static extern IntPtr SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam );

  [System.Runtime.InteropServices.DllImport( "user32.dll" )]
  static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );

  /// <summary>
  /// 해당 응용 프로그램의 주 진입점입니다.
  /// </summary>
  [STAThread]
  static void Main()
  {
   bool isNew;
   Mutex dup = new Mutex( true, "RunManager", out isNew );

   if ( isNew )
   {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault( false );
    Application.Run( new Form1() );
    dup.ReleaseMutex();
   }
   else
   {
    IntPtr wHandle = FindWindow( null, "RunManager" );
    if(wHandle != IntPtr.Zero)
    {
     ShowWindow( wHandle, 1 );
     BringWindowToTop( wHandle );
     SetForegroundWindow( wHandle );
    }
    Application.Exit();
   }
  }

신고
Posted by 나비 나비:D

BLOG main image
by 나비:D

공지사항

카테고리

분류 전체보기 (278)
Programming? (0)
----------------------------- (0)
나비의삽질 (5)
Application (177)
SQL (51)
Web (27)
etc. (14)
Omnia (0)
---------------------------.. (0)

글 보관함

달력

«   2017/08   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Total : 870,086
Today : 41 Yesterday : 412