Guest User

Untitled

a guest
Dec 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Reflection;
  5.  
  6. namespace MyApp
  7. {
  8. partial class MyApp : Form
  9. {
  10. // タスクトレイアイコン
  11. NotifyIcon _icon = null;
  12.  
  13. MouseUnderScroll.MouseHook _mouseHook = null;
  14. TopMostWindow.TopMostHotKey _topMostHotKey = null;
  15.  
  16. // コンストラクタ
  17. public MyApp()
  18. {
  19. ShowInTaskbar = false;
  20. _icon = CreateNotifyIcon();
  21.  
  22. _mouseHook = new MouseUnderScroll.MouseHook();
  23. _topMostHotKey = new TopMostWindow.TopMostHotKey(Handle, _icon);
  24. }
  25.  
  26. // デストラクタ
  27. ~MyApp()
  28. {
  29. }
  30.  
  31. // ウィンドウプロシージャ
  32. protected override void WndProc(ref Message m)
  33. {
  34. base.WndProc(ref m);
  35.  
  36. if( _topMostHotKey != null ) {
  37. _topMostHotKey.WndProc(ref m);
  38. }
  39. }
  40.  
  41. // タスクトレイアイコンの作成
  42. private NotifyIcon CreateNotifyIcon()
  43. {
  44. var icon = new NotifyIcon();
  45. var assembly = Assembly.GetExecutingAssembly();
  46. var stream = assembly.GetManifestResourceStream("MyApp.app.ico");
  47. icon.Icon = new Icon(stream);
  48. icon.Visible = true;
  49. icon.Text = "MyApp";
  50.  
  51. var menu = new ContextMenuStrip();
  52. var menuItem = new ToolStripMenuItem();
  53. menuItem.Text = "&終了";
  54. menuItem.Click += new EventHandler(CloseClick);
  55. menu.Items.Add(menuItem);
  56. icon.ContextMenuStrip = menu;
  57.  
  58. return icon;
  59. }
  60.  
  61. // 終了ボタンのクリックイベント
  62. private void CloseClick(object sender, EventArgs e)
  63. {
  64. Application.Exit();
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment