-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleCDViewer.cs
More file actions
54 lines (40 loc) · 1.42 KB
/
ToggleCDViewer.cs
File metadata and controls
54 lines (40 loc) · 1.42 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
static class ToggleCDViewer
{
private const int WS_MAXIMIZE = 0x01000000;
private const int WS_MINIMIZE = 0x00020000;
public const int SW_MINIMIZE = 6;
public const int GWL_STYLE = -16;
[DllImport("User32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("User32.dll")]
public static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[STAThread]
static void Main()
{
Process[] processes = Process.GetProcessesByName("CDViewer");
foreach (Process p in processes)
{
IntPtr windowHandle = p.MainWindowHandle;
int style = GetWindowLong(windowHandle, GWL_STYLE);
if ((style & WS_MAXIMIZE) == WS_MAXIMIZE)
{
//It's maximized
ShowWindow(windowHandle, SW_MINIMIZE);
}
else if ((style & WS_MINIMIZE) == WS_MINIMIZE)
{
//It's minimized
ShowWindowAsync(windowHandle, 4);
SetForegroundWindow(windowHandle);
}
}
}
}