回答編集履歴

2

常に最背面にする場合の方法を追加

2017/10/11 06:18

投稿

Harahira
Harahira

スコア243

test CHANGED
@@ -33,3 +33,89 @@
33
33
 
34
34
 
35
35
  [SetWindowPos (user32)](http://www.pinvoke.net/default.aspx/user32/SetWindowPos.html)
36
+
37
+
38
+
39
+ ---
40
+
41
+ 追記2
42
+
43
+
44
+
45
+ 常に最背面にしたいということであれば、以下のコードで実現できます。
46
+
47
+ ```C#
48
+
49
+ public partial class Form1 : Form
50
+
51
+ {
52
+
53
+ private const int WM_WINDOWPOSCHANGING = 0x0046;
54
+
55
+ private IntPtr HWND_BOTTOM = (IntPtr)1;
56
+
57
+
58
+
59
+ [StructLayout(LayoutKind.Sequential)]
60
+
61
+ public struct WINDOWPOS
62
+
63
+ {
64
+
65
+ public IntPtr hwnd;
66
+
67
+ public IntPtr hwndInsertAfter;
68
+
69
+ public int x;
70
+
71
+ public int y;
72
+
73
+ public int cx;
74
+
75
+ public int cy;
76
+
77
+ public uint flags;
78
+
79
+ }
80
+
81
+
82
+
83
+ public Form1()
84
+
85
+ {
86
+
87
+ InitializeComponent();
88
+
89
+ }
90
+
91
+
92
+
93
+ protected override void WndProc(ref Message m)
94
+
95
+ {
96
+
97
+ switch (m.Msg)
98
+
99
+ {
100
+
101
+ case WM_WINDOWPOSCHANGING:
102
+
103
+ WINDOWPOS wp = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));
104
+
105
+ wp.hwndInsertAfter = HWND_BOTTOM;
106
+
107
+ Marshal.StructureToPtr(wp, m.LParam, true);
108
+
109
+ break;
110
+
111
+ }
112
+
113
+ base.WndProc(ref m);
114
+
115
+ }
116
+
117
+ }
118
+
119
+
120
+
121
+ ```

1

SetWindowPosの引数の解説を追記

2017/10/11 06:18

投稿

Harahira
Harahira

スコア243

test CHANGED
@@ -11,3 +11,25 @@
11
11
 
12
12
 
13
13
  この二つを組み合わせれば、お望みの動作が実現できると思います。
14
+
15
+
16
+
17
+ ---
18
+
19
+ 追記
20
+
21
+
22
+
23
+ SetWindowPosのHWND_BOTTOMの値は、1です。
24
+
25
+
26
+
27
+ uFlagsは、SWP_NOSIZE(値としては1)とSWP_NOMOVE(値としては2)のOR、すなわち3を渡してください。
28
+
29
+
30
+
31
+ 以下を参考にしてください。
32
+
33
+
34
+
35
+ [SetWindowPos (user32)](http://www.pinvoke.net/default.aspx/user32/SetWindowPos.html)