1 // Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
22 namespace KancolleSniffer
\r
24 public class Win32API
\r
26 [DllImport("user32.dll")]
\r
27 private static extern bool SetForegroundWindow(IntPtr hWnd);
\r
29 [DllImport("user32.dll")]
\r
30 private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
\r
32 [DllImport("user32.dll")]
\r
33 private static extern bool IsIconic(IntPtr hWnd);
\r
35 public static bool ProcessAlreadyExists()
\r
37 var cur = Process.GetCurrentProcess();
\r
38 var all = Process.GetProcessesByName(cur.ProcessName);
\r
39 foreach (var p in all)
\r
43 if (p.MainModule.FileName != cur.MainModule.FileName)
\r
45 if (IsIconic(p.MainWindowHandle))
\r
46 ShowWindowAsync(p.MainWindowHandle, 9); // SW_RESTORE
\r
48 SetForegroundWindow(p.MainWindowHandle);
\r
54 [DllImport("user32.dll")]
\r
55 private static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
\r
57 public static void FlashWindow(IntPtr handle)
\r
59 var info = new FLASHWINFO();
\r
60 info.cbSize = Convert.ToUInt32(Marshal.SizeOf(info));
\r
62 info.dwFlags = 3; // FLASHW_ALL
\r
65 FlashWindowEx(ref info);
\r
68 [StructLayout(LayoutKind.Sequential)]
\r
69 private struct FLASHWINFO
\r
71 public UInt32 cbSize;
\r
73 public UInt32 dwFlags;
\r
74 public UInt32 uCount;
\r
75 public UInt32 dwTimeout;
\r