1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;
5 using System.Drawing;
6 using System.Runtime.InteropServices;
7
8 namespace JToolDemo.Tool_Chat
9 {
10 public class NotifyIconForm : Chat_ParentClass
11 {
12 private NotifyIcon _notifyIcon;
13 private Rectangle _bounds;
14
15 public NotifyIconForm()
16 : base()
17 {
18 Init();
19 }
20
21 public NotifyIcon NotifyIcons
22 {
23 get { return _notifyIcon; }
24 set { _notifyIcon = value; }
25 }
26
27 public EventHandler NotifyIconDoubleClick
28 {
29 get { return notifyIconDoubleClick; }
30 }
31
32 public EventHandler NotifyIconForm_Move
33 {
34 get { return notifyIconForm_Move; }
35 }
36
37 protected override void WndProc(ref Message m)
38 {
39 if ((m.Msg == NativeMethods.WM_SYSCOMMAND) && ((int)m.WParam == (int)NativeMethods.SystemCommands.SC_CLOSE))
40 {
41 //this.Visible = false;
42 WmSyscommand(ref m);
43 return;
44 }
45 base.WndProc(ref m);
46 }
47
48 private void Init()
49 {
50 //是否显示
51 //ShowInTaskbar = false;
52 _notifyIcon = new NotifyIcon();
53 _notifyIcon.DoubleClick += new System.EventHandler(notifyIconDoubleClick);
54 this.Move +=new EventHandler(NotifyIconForm_Move);
55 }
56
57 //双击任务栏 还原窗口
58 private void notifyIconDoubleClick(object sender, EventArgs e)
59 {
60 notifyIcon();
61 }
62
63 protected void notifyIcon()
64 {
65 if (WindowState == FormWindowState.Normal)
66 {
67 NativeMethods.SetWindowPos(
68 Handle,
69 new IntPtr(0),
70 _bounds.X,
71 _bounds.Y,
72 _bounds.Width,
73 _bounds.Height,
74 NativeMethods.SWP_NOREDRAW | NativeMethods.SWP_NOZORDER);
75
76 AnimateChangeStateManager.Animate(this, _bounds, true);
77 NativeMethods.ShowWindow(Handle, NativeMethods.SW_NORMAL);
78 Opacity = 1;
79 }
80 }
81
82 //点击关闭 最小化到任务栏动画
83 private void WmSyscommand(ref Message m)
84 {
85 int wparam = m.WParam.ToInt32();
86 switch (wparam)
87 {
88 case (int)NativeMethods.SystemCommands.SC_CLOSE:
89 AnimateChangeStateManager.Animate(this,Bounds, false);
90 _bounds = Bounds;
91 Hide();
92 Opacity = 0;
93 break;
94 }
95 }
96
97 private void notifyIconForm_Move(object sender, EventArgs e)
98 {
99 _bounds = Bounds;
100 }
101 }
102 }