Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Reflection;
- namespace MyApp
- {
- partial class MyApp : Form
- {
- // タスクトレイアイコン
- NotifyIcon _icon = null;
- MouseUnderScroll.MouseHook _mouseHook = null;
- TopMostWindow.TopMostHotKey _topMostHotKey = null;
- // コンストラクタ
- public MyApp()
- {
- ShowInTaskbar = false;
- _icon = CreateNotifyIcon();
- _mouseHook = new MouseUnderScroll.MouseHook();
- _topMostHotKey = new TopMostWindow.TopMostHotKey(Handle, _icon);
- }
- // デストラクタ
- ~MyApp()
- {
- }
- // ウィンドウプロシージャ
- protected override void WndProc(ref Message m)
- {
- base.WndProc(ref m);
- if( _topMostHotKey != null ) {
- _topMostHotKey.WndProc(ref m);
- }
- }
- // タスクトレイアイコンの作成
- private NotifyIcon CreateNotifyIcon()
- {
- var icon = new NotifyIcon();
- var assembly = Assembly.GetExecutingAssembly();
- var stream = assembly.GetManifestResourceStream("MyApp.app.ico");
- icon.Icon = new Icon(stream);
- icon.Visible = true;
- icon.Text = "MyApp";
- var menu = new ContextMenuStrip();
- var menuItem = new ToolStripMenuItem();
- menuItem.Text = "&終了";
- menuItem.Click += new EventHandler(CloseClick);
- menu.Items.Add(menuItem);
- icon.ContextMenuStrip = menu;
- return icon;
- }
- // 終了ボタンのクリックイベント
- private void CloseClick(object sender, EventArgs e)
- {
- Application.Exit();
- }
- }
- }
Add Comment
Please, Sign In to add comment