Kladdy

Untitled

Aug 15th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #using <System.dll>
  2. #using <System.Windows.Forms.dll>
  3. #using <System.Drawing.dll>
  4.  
  5. using namespace System;
  6. using namespace System::Drawing;
  7. using namespace System::Windows::Forms;
  8. public ref class Form1: public System::Windows::Forms::Form
  9. {
  10. private:
  11.    System::Windows::Forms::NotifyIcon^ notifyIcon1;
  12.    System::Windows::Forms::ContextMenu^ contextMenu1;
  13.    System::Windows::Forms::MenuItem^ menuItem1;
  14.    System::ComponentModel::IContainer^ components;
  15.  
  16. public:
  17.    Form1()
  18.    {
  19.       this->components = gcnew System::ComponentModel::Container;
  20.       this->contextMenu1 = gcnew System::Windows::Forms::ContextMenu;
  21.       this->menuItem1 = gcnew System::Windows::Forms::MenuItem;
  22.  
  23.       // Initialize contextMenu1
  24.       array<System::Windows::Forms::MenuItem^>^temp0 = {this->menuItem1};
  25.       this->contextMenu1->MenuItems->AddRange( temp0 );
  26.  
  27.       // Initialize menuItem1
  28.       this->menuItem1->Index = 0;
  29.       this->menuItem1->Text = "E&xit";
  30.       this->menuItem1->Click += gcnew System::EventHandler( this, &Form1::menuItem1_Click );
  31.  
  32.       // Set up how the form should be displayed.
  33.       this->ClientSize = System::Drawing::Size( 292, 266 );
  34.       this->Text = "Notify Icon Example";
  35.  
  36.       // Create the NotifyIcon.
  37.       this->notifyIcon1 = gcnew System::Windows::Forms::NotifyIcon( this->components );
  38.  
  39.       // The Icon property sets the icon that will appear
  40.       // in the systray for this application.
  41.       notifyIcon1->Icon = gcnew System::Drawing::Icon( "appicon.ico" );
  42.  
  43.       // The ContextMenu property sets the menu that will
  44.       // appear when the systray icon is right clicked.
  45.       notifyIcon1->ContextMenu = this->contextMenu1;
  46.  
  47.       // The Text property sets the text that will be displayed,
  48.       // in a tooltip, when the mouse hovers over the systray icon.
  49.       notifyIcon1->Text = "Form1 (NotifyIcon example)";
  50.       notifyIcon1->Visible = true;
  51.  
  52.       // Handle the DoubleClick event to activate the form.
  53.       notifyIcon1->DoubleClick += gcnew System::EventHandler( this, &Form1::notifyIcon1_DoubleClick );
  54.    }
  55.  
  56. protected:
  57.    ~Form1()
  58.    {
  59.       if ( components != nullptr )
  60.       {
  61.          delete components;
  62.       }
  63.    }
  64.  
  65. private:
  66.    void notifyIcon1_DoubleClick( Object^ /*Sender*/, EventArgs^ /*e*/ )
  67.    {
  68.  
  69.       // Show the form when the user double clicks on the notify icon.
  70.       // Set the WindowState to normal if the form is minimized.
  71.       if ( this->WindowState == FormWindowState::Minimized )
  72.             this->WindowState = FormWindowState::Normal;
  73.  
  74.       // Activate the form.
  75.       this->Activate();
  76.    }
  77.  
  78.    void menuItem1_Click( Object^ /*Sender*/, EventArgs^ /*e*/ )
  79.    {
  80.  
  81.       // Close the form, which closes the application.
  82.       this->Close();
  83.    }
  84.  
  85. };
  86.  
  87. [STAThread]
  88. int main()
  89. {
  90.    Application::Run( gcnew Form1 );
  91. }
Advertisement
Add Comment
Please, Sign In to add comment