1 // Copyright (C) 2013 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>
\r
3 // This program is part of KancolleSniffer.
\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify
\r
6 // it under the terms of the GNU General Public License as published by
\r
7 // the Free Software Foundation, either version 3 of the License, or
\r
8 // (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
\r
19 using System.Diagnostics;
\r
20 using System.Runtime.InteropServices;
\r
21 using System.Windows.Forms;
\r
23 namespace KancolleSniffer
\r
25 internal static class Program
\r
28 /// アプリケーションのメイン エントリ ポイントです。
\r
31 private static void Main()
\r
33 if (Win32API.ProcessAlreadyExists())
\r
35 Application.EnableVisualStyles();
\r
36 Application.SetCompatibleTextRenderingDefault(false);
\r
37 Application.Run(new MainForm());
\r
42 /// Win32APIを実行するクラス
\r
44 public class Win32API
\r
46 [DllImport("user32.dll")]
\r
47 private static extern bool SetForegroundWindow(IntPtr hWnd);
\r
49 [DllImport("user32.dll")]
\r
50 private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
\r
52 [DllImport("user32.dll")]
\r
53 private static extern bool IsIconic(IntPtr hWnd);
\r
56 /// 同じアプリケーションがすでに起動しているか調べる。起動していたら最前面に表示する。
\r
58 /// <returns>起動していたらtrue</returns>
\r
59 public static bool ProcessAlreadyExists()
\r
61 var cur = Process.GetCurrentProcess();
\r
62 var all = Process.GetProcessesByName(cur.ProcessName);
\r
63 foreach (var p in all)
\r
67 if (p.MainModule.FileName != cur.MainModule.FileName)
\r
69 if (IsIconic(p.MainWindowHandle))
\r
70 ShowWindowAsync(p.MainWindowHandle, 9); // SW_RESTORE
\r
72 SetForegroundWindow(p.MainWindowHandle);
\r