最小化到系统栏
Code
1public class Win32APIS
2 {
3 [DllImport("user32.dll", CharSet = CharSet.Auto)]
4 public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
5 }
6
7 public partial class Form1 : Form
8 {
9 public Form1()
10 {
11 InitializeComponent();
12 }
13 protected override void WndProc(ref Message m)
14 {
15 const int SYSCMD = 0x0112;
16 const int CLOSE = 0xF060;
17 const int MINIMIZE = 0xF020;
18
19 if (m.Msg == SYSCMD && ((int)m.WParam == MINIMIZE || (int)m.WParam == CLOSE))
20 {
21 //最小化到系统栏
22 base.WindowState = FormWindowState.Minimized;
23 base.Hide();
24 return;
25 }
26 base.WndProc(ref m);
27 }
28
29 private void Open_Click(object sender, EventArgs e)
30 {
31 ShowForm();
32 }
33
34 private void Exit_Click(object sender, EventArgs e)
35 {
36 Application.Exit();
37 }
38
39 private void ShowForm()
40 {
41 if (!base.Visible)
42 {
43 base.Show();
44 }
45 if (base.WindowState == FormWindowState.Minimized)
46 {
47 Win32APIS.SendMessage(base.Handle, 0x112, 0xf120, 0);
48 }
49 base.Activate();
50
51 }
52}
1public class Win32APIS
2 {
3 [DllImport("user32.dll", CharSet = CharSet.Auto)]
4 public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
5 }
6
7 public partial class Form1 : Form
8 {
9 public Form1()
10 {
11 InitializeComponent();
12 }
13 protected override void WndProc(ref Message m)
14 {
15 const int SYSCMD = 0x0112;
16 const int CLOSE = 0xF060;
17 const int MINIMIZE = 0xF020;
18
19 if (m.Msg == SYSCMD && ((int)m.WParam == MINIMIZE || (int)m.WParam == CLOSE))
20 {
21 //最小化到系统栏
22 base.WindowState = FormWindowState.Minimized;
23 base.Hide();
24 return;
25 }
26 base.WndProc(ref m);
27 }
28
29 private void Open_Click(object sender, EventArgs e)
30 {
31 ShowForm();
32 }
33
34 private void Exit_Click(object sender, EventArgs e)
35 {
36 Application.Exit();
37 }
38
39 private void ShowForm()
40 {
41 if (!base.Visible)
42 {
43 base.Show();
44 }
45 if (base.WindowState == FormWindowState.Minimized)
46 {
47 Win32APIS.SendMessage(base.Handle, 0x112, 0xf120, 0);
48 }
49 base.Activate();
50
51 }
52}