質問するログイン新規登録

質問編集履歴

4

ソースの編集。試したことの追加。

2018/05/09 11:00

投稿

urazumi
urazumi

スコア7

title CHANGED
File without changes
body CHANGED
@@ -7,73 +7,17 @@
7
7
  Windows10 Home
8
8
 
9
9
  Program.cs
10
+
10
11
  ```C#
11
12
  using System;
12
- using System.Runtime.InteropServices;
13
13
  using System.Windows.Forms;
14
- using System.Drawing;
15
- using System.Text;
16
14
 
17
- namespace TTrainer
15
+ namespace MinimizeList
18
16
  {
19
- public class Program
17
+ static class Program
20
18
  {
21
- [DllImport("user32.dll")]
22
- static extern int ShowWindow(IntPtr hWnd, int command);
23
- [DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)]
24
- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
25
- [DllImport("user32.dll")]
26
- public static extern Boolean IsIconic(IntPtr hWnd);
19
+ public static Form1 form = new Form1();
27
- [DllImport("user32.dll")]
28
- private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam);
29
- // EnumWindowsから呼び出されるコールバック関数WNDENUMPROCのデリゲート
30
- private delegate bool WNDENUMPROC(IntPtr hWnd, IntPtr lParam);
31
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
32
- static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
33
- [DllImport("user32.dll")]
34
- [return: MarshalAs(UnmanagedType.Bool)]
35
- static extern bool SetForegroundWindow(IntPtr hWnd);
36
20
 
37
- public static ContextMenuStrip rmenu = new ContextMenuStrip();
38
- public static ToolStripMenuItem rmenuItem = new ToolStripMenuItem();
39
- // ウィンドウを列挙するためのコールバックメソッド
40
- private static bool EnumerateWindow(IntPtr hWnd, IntPtr lParam)
41
- {
42
- // ウィンドウが最小化されているかかどうか調べる
43
- if (IsIconic(hWnd))
44
- {
45
- PrintCaptionAndProcess(hWnd);
46
- }
47
- return true;
48
- }
49
-
50
- static void PrintCaptionAndProcess(IntPtr hWnd)
51
- {
52
- StringBuilder caption = new StringBuilder(0x1000);
53
- GetWindowText(hWnd, caption, caption.Capacity);
54
- if (caption.Length != 0)
55
- {
56
- rmenuItem = new ToolStripMenuItem();
57
- rmenuItem.Text = caption.ToString();
58
-
59
- if (rmenuItem.Text != "PnpMgr" &&
60
- rmenuItem.Text != "DWM Notification Window")
61
- {
62
- rmenuItem.Click += new EventHandler(MenuItemClickHandler);
63
- rmenu.Items.Add(rmenuItem);
64
- }
65
- }
66
-
67
- }
68
-
69
- static void MenuItemClickHandler(object sender, EventArgs ej)
70
- {
71
- ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
72
- IntPtr hWnd = FindWindow(null, clickedItem.Text);
73
- ShowWindow(hWnd, 1);
74
- SetForegroundWindow(hWnd);
75
- }
76
-
77
21
  static void Khooked(object sender, KeyboardHookedEventArgs e)
78
22
  {
79
23
  if (e.UpDown == KeyboardUpDown.Down)
@@ -84,75 +28,68 @@
84
28
  }
85
29
  }
86
30
  }
87
-
31
+
88
32
  public static void OpenMenu()
89
33
  {
90
- rmenu.Items.Clear();
34
+ form.contextMenuStrip1.Items.Clear();
91
- EnumWindows(EnumerateWindow, IntPtr.Zero);
92
- rmenu.Items.Add("-");
93
- rmenu.Items.Add("キャンセル");
35
+ form.contextMenuStrip1.Items.Add("キャンセル");
94
- rmenu.Show(Cursor.Position, ToolStripDropDownDirection.BelowRight);
36
+ form.contextMenuStrip1.Show(Cursor.Position, ToolStripDropDownDirection.BelowRight);
95
- rmenu.ShowImageMargin = false;
37
+ form.contextMenuStrip1.ShowImageMargin = false;
38
+
96
39
  }
97
40
 
98
41
  [STAThread]
99
42
  static void Main()
100
43
  {
101
- Tasktray task = new Tasktray();
102
44
  KeyboardHook Khook = new KeyboardHook();
103
45
  Khook.KeyboardHooked += new KeyboardHookedEventHandler(Khooked);
104
- Application.Run();
46
+ Application.Run(form);
105
47
  }
106
48
  }
49
+ }
50
+ ```
51
+ Form1.cs
52
+ ```C#
53
+ using System;
54
+ using System.ComponentModel;
55
+ using System.Windows.Forms;
107
56
 
57
+ namespace MinimizeList
58
+ {
108
- class Tasktray : Form
59
+ public partial class Form1 : Form
109
60
  {
61
+ public Form1()
62
+ {
110
- NotifyIcon icon = new NotifyIcon();
63
+ InitializeComponent();
111
- ContextMenuStrip menu = new ContextMenuStrip();
64
+ }
112
- ToolStripMenuItem menuItem = new ToolStripMenuItem();
113
65
 
114
- public Tasktray()
66
+ private void Form1_Load(object sender, EventArgs e)
115
67
  {
116
68
  this.ShowInTaskbar = false;
117
- this.SetComponents();
69
+ this.Hide();
118
70
  }
119
71
 
120
- private void Close_Click(object sender, EventArgs e)
72
+ private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
121
73
  {
122
- icon.Visible = false;
74
+
123
- Application.Exit();
124
75
  }
76
+
125
- private void Mouse_Click(object sender, MouseEventArgs e)
77
+ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
126
78
  {
127
- if (e.Button == MouseButtons.Right)
128
- {
129
- menuItem.Text = "&終了";
130
- menu.Items.Add(menuItem);
131
- menuItem.Click += new EventHandler(Close_Click);
132
- menu.ShowImageMargin = false;
133
- icon.ContextMenuStrip = menu;
134
- }
135
- else
136
- {
137
- Program.OpenMenu();
138
- }
139
- }
140
79
 
141
- private void SetComponents()
142
- {
143
- icon.Icon = new Icon("Icon1.ico");
144
- icon.Visible = true;
145
- icon.MouseClick += new MouseEventHandler(Mouse_Click);
146
80
  }
147
-
148
81
  }
149
82
  }
83
+ ```
150
84
 
151
- ```
152
85
  KeyboardHook.cs
153
86
  http://hongliang.seesaa.net/article/7539988.html
154
87
  こちらのサイトのKeyboardHook3.cs
155
- ```
88
+
156
89
  ### 試したこと
157
90
 
158
- タスクトレイを左クリックした際にContextMenuStripが表示されるよう作ってみましたが、その時にもタスクバーは出てしまいました。
91
+ タスクトレイを左クリックした際にContextMenuStripが表示されるよう作ってみましたが、その時にもタスクバーは出てしまいました。
92
+ 現象の起きる最低限のプログラムを作成しました。(ソース修正しました。)
93
+ FormにnotifyIconとcontextMenuStripを追加してHideさせてみましたが、
94
+ タスクトレイを右クリックした時にはタスクバーに表示はされませんが、
95
+ RControlキーを押してマウスポインターの位置でContextMenuStripを出すとやはりタスクバーが出てしまいました。

3

アプリ説明の修正

2018/05/09 11:00

投稿

urazumi
urazumi

スコア7

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  タスクトレイのみで常駐するWindowsFormアプリケーションです。
2
- 任意のキーを押したらマウスポインターの位置にContextMenuStripが表示されるプログラムを作っています。その時にContextMenuStrip自身のタスクバーも表示されてしまいます。
2
+ RContrlキーを押したらマウスポインターの位置にContextMenuStripが表示されるプログラムを作っています。その時にContextMenuStrip自身のタスクバーも表示されてしまいます。
3
3
  そのタスクバー表示を非表示にする方法を教えて頂きたいです。
4
4
 
5
5
  C# Visual Studio Community 2017 v15.7.0

2

ソースの詳細追加。

2018/05/09 00:09

投稿

urazumi
urazumi

スコア7

title CHANGED
File without changes
body CHANGED
@@ -5,7 +5,75 @@
5
5
  C# Visual Studio Community 2017 v15.7.0
6
6
  .NET v4.7.03056
7
7
  Windows10 Home
8
+
9
+ Program.cs
8
- ```
10
+ ```C#
11
+ using System;
12
+ using System.Runtime.InteropServices;
13
+ using System.Windows.Forms;
14
+ using System.Drawing;
15
+ using System.Text;
16
+
17
+ namespace TTrainer
18
+ {
19
+ public class Program
20
+ {
21
+ [DllImport("user32.dll")]
22
+ static extern int ShowWindow(IntPtr hWnd, int command);
23
+ [DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)]
24
+ public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
25
+ [DllImport("user32.dll")]
26
+ public static extern Boolean IsIconic(IntPtr hWnd);
27
+ [DllImport("user32.dll")]
28
+ private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam);
29
+ // EnumWindowsから呼び出されるコールバック関数WNDENUMPROCのデリゲート
30
+ private delegate bool WNDENUMPROC(IntPtr hWnd, IntPtr lParam);
31
+ [DllImport("user32.dll", CharSet = CharSet.Auto)]
32
+ static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
33
+ [DllImport("user32.dll")]
34
+ [return: MarshalAs(UnmanagedType.Bool)]
35
+ static extern bool SetForegroundWindow(IntPtr hWnd);
36
+
37
+ public static ContextMenuStrip rmenu = new ContextMenuStrip();
38
+ public static ToolStripMenuItem rmenuItem = new ToolStripMenuItem();
39
+ // ウィンドウを列挙するためのコールバックメソッド
40
+ private static bool EnumerateWindow(IntPtr hWnd, IntPtr lParam)
41
+ {
42
+ // ウィンドウが最小化されているかかどうか調べる
43
+ if (IsIconic(hWnd))
44
+ {
45
+ PrintCaptionAndProcess(hWnd);
46
+ }
47
+ return true;
48
+ }
49
+
50
+ static void PrintCaptionAndProcess(IntPtr hWnd)
51
+ {
52
+ StringBuilder caption = new StringBuilder(0x1000);
53
+ GetWindowText(hWnd, caption, caption.Capacity);
54
+ if (caption.Length != 0)
55
+ {
56
+ rmenuItem = new ToolStripMenuItem();
57
+ rmenuItem.Text = caption.ToString();
58
+
59
+ if (rmenuItem.Text != "PnpMgr" &&
60
+ rmenuItem.Text != "DWM Notification Window")
61
+ {
62
+ rmenuItem.Click += new EventHandler(MenuItemClickHandler);
63
+ rmenu.Items.Add(rmenuItem);
64
+ }
65
+ }
66
+
67
+ }
68
+
69
+ static void MenuItemClickHandler(object sender, EventArgs ej)
70
+ {
71
+ ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
72
+ IntPtr hWnd = FindWindow(null, clickedItem.Text);
73
+ ShowWindow(hWnd, 1);
74
+ SetForegroundWindow(hWnd);
75
+ }
76
+
9
77
  static void Khooked(object sender, KeyboardHookedEventArgs e)
10
78
  {
11
79
  if (e.UpDown == KeyboardUpDown.Down)
@@ -25,9 +93,66 @@
25
93
  rmenu.Items.Add("キャンセル");
26
94
  rmenu.Show(Cursor.Position, ToolStripDropDownDirection.BelowRight);
27
95
  rmenu.ShowImageMargin = false;
28
-
29
96
  }
30
97
 
98
+ [STAThread]
99
+ static void Main()
100
+ {
101
+ Tasktray task = new Tasktray();
102
+ KeyboardHook Khook = new KeyboardHook();
103
+ Khook.KeyboardHooked += new KeyboardHookedEventHandler(Khooked);
104
+ Application.Run();
105
+ }
106
+ }
107
+
108
+ class Tasktray : Form
109
+ {
110
+ NotifyIcon icon = new NotifyIcon();
111
+ ContextMenuStrip menu = new ContextMenuStrip();
112
+ ToolStripMenuItem menuItem = new ToolStripMenuItem();
113
+
114
+ public Tasktray()
115
+ {
116
+ this.ShowInTaskbar = false;
117
+ this.SetComponents();
118
+ }
119
+
120
+ private void Close_Click(object sender, EventArgs e)
121
+ {
122
+ icon.Visible = false;
123
+ Application.Exit();
124
+ }
125
+ private void Mouse_Click(object sender, MouseEventArgs e)
126
+ {
127
+ if (e.Button == MouseButtons.Right)
128
+ {
129
+ menuItem.Text = "&終了";
130
+ menu.Items.Add(menuItem);
131
+ menuItem.Click += new EventHandler(Close_Click);
132
+ menu.ShowImageMargin = false;
133
+ icon.ContextMenuStrip = menu;
134
+ }
135
+ else
136
+ {
137
+ Program.OpenMenu();
138
+ }
139
+ }
140
+
141
+ private void SetComponents()
142
+ {
143
+ icon.Icon = new Icon("Icon1.ico");
144
+ icon.Visible = true;
145
+ icon.MouseClick += new MouseEventHandler(Mouse_Click);
146
+ }
147
+
148
+ }
149
+ }
150
+
151
+ ```
152
+ KeyboardHook.cs
153
+ http://hongliang.seesaa.net/article/7539988.html
154
+ こちらのサイトのKeyboardHook3.cs
155
+ ```
31
156
  ### 試したこと
32
157
 
33
158
  タスクトレイを左クリックした際にContextMenuStripが表示されるよう作ってみましたが、その時にもタスクバーは出てしまいました。

1

開発環境の記載追加。作成しているアプリの詳細追加。

2018/05/08 23:58

投稿

urazumi
urazumi

スコア7

title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,10 @@
1
- タスクトレイのみで常駐します。
1
+ タスクトレイのみで常駐するWindowsFormアプリケーションです
2
2
  任意のキーを押したらマウスポインターの位置にContextMenuStripが表示されるプログラムを作っています。その時にContextMenuStrip自身のタスクバーも表示されてしまいます。
3
3
  そのタスクバー表示を非表示にする方法を教えて頂きたいです。
4
4
 
5
- C# Visual Studio 2017
5
+ C# Visual Studio Community 2017 v15.7.0
6
+ .NET v4.7.03056
7
+ Windows10 Home
6
8
  ```
7
9
  static void Khooked(object sender, KeyboardHookedEventArgs e)
8
10
  {