///使用了本地方法来取taskbar的handle
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
new Tray();
Application.Run();
}
}
}
namespace WindowsApplication1
{
class WindowWrapper:IWin32Window
{
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
class Tray
{
private IContainer container;
private NotifyIcon notifyIcon;
private Timer timer;
private WindowWrapper windowWropper;
public Tray()
{
this.container = new Container();
Icon icon = new Icon(SystemIcons.Application, 16, 16);
this.notifyIcon = new NotifyIcon(this.container);
this.notifyIcon.Icon = icon;
this.notifyIcon.Visible = true;
MenuItem aboutMenuItem = new MenuItem("About");
MenuItem closeMenuItem = new MenuItem("Close");
aboutMenuItem.Click += new EventHandler(this.AboutMenuItemClick);
closeMenuItem.Click += new EventHandler(this.CloseMenuItemClick);
this.notifyIcon.ContextMenu = new ContextMenu(new MenuItem[] { aboutMenuItem, closeMenuItem });
IntPtr handle =FindWindow("Shell_TrayWnd", null);
windowWropper = new WindowWrapper(handle);
timer = new Timer(this.container);
timer.Interval = 5000;
timer.Tick += new EventHandler(this.TimerTick);
timer.Start();
}
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private void TimerTick(object sender, EventArgs e)
{
MessageBox.Show(windowWropper, "TimerTick good!");
}
private void AboutMenuItemClick(object sender, EventArgs e)
{
MessageBox.Show(windowWropper, "AboutMenuItemClick good!");
}
private void CloseMenuItemClick(object sender, EventArgs e)
{
this.container.Dispose();
Application.Exit();
}
}
}
阅读(582) | 评论(0) | 转发(0) |