Created
December 17, 2018 08:26
-
-
Save hexagit/6e2e2d15fa3db6e42e9fdfca303d47da to your computer and use it in GitHub Desktop.
Windows7を便利にしたい3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment