示例#1
0
        //Functions related with IconTray

        protected override void OnClosing(CancelEventArgs e)
        {
            if (fMonoFramework)
            {
                base.OnClosing(e);
                return;
            }

            if (!fInstClose)
            {
                e.Cancel = true;
                this.Hide();

                if (!fOneShot)
                {
                    AppNotifyIcon.ShowBalloonTip(3000);
                    fOneShot = true;
                }
            }
            else
            {
                NotifyMenu.Dispose();
                AppNotifyIcon.Dispose();
            }
        }
示例#2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //build the context menu
            _trayContextMenu = new System.Windows.Forms.ContextMenu();
            _trayContextMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("E&xit", ContextMenuExit));

            //setup the system tray icon
            _trayIcon = new NotifyIcon();
            _trayIcon.ContextMenu = _trayContextMenu;
            _trayIcon.Icon = images.IDS04;
            _trayIcon.Click += new EventHandler(TrayIconClick);
            _trayIcon.Visible = true;

            //host the service
            ServiceHost host1 = new ServiceHost(typeof(CrossDomainService));
            host1.Open();
            ServiceHost host2 = new ServiceHost(typeof(BiometricsService));
            host2.Open();

            //display the main window
            _mainWindow = new Main();
            _mainWindow.Closing += new CancelEventHandler(MainWindowClosing);
            _mainWindow.ShowDialog();

            //cleanup
            _trayContextMenu.Dispose();
            _trayIcon.Dispose();
        }
示例#3
0
 /// <summary>
 /// Removes icon from tray, memory cleanup.
 /// </summary>
 public void Dispose()
 {
     trayIcon.Visible = false;
     trayIcon.Icon.Dispose();
     trayMenu.Dispose();
     trayIcon.Dispose();
 }
示例#4
0
        void OnExit(object sender, EventArgs e)
        {
            isExit = true;
            trayIcon.Dispose();
            trayMenu.Dispose();

            System.Windows.Application.Current.Shutdown();
        }
示例#5
0
 public void Dispose()
 {
     OnStatusChanged(this, new SystemTrayNotificationEventArgs(SystemTrayNotificationEventType.Disposing));
     iconTimer.Tick -= new EventHandler(TimerProc);
     if (BaseMenu != null)
     {
         BaseMenu.Dispose();
     }
     notifyIcon.Dispose();
 }
示例#6
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (m_formatTimer != null)
            {
                m_formatTimer.Dispose();
                m_formatTimer = null;
            }

            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }

                mnuTextBox.Dispose();
            }

            base.Dispose(disposing);
        }
示例#7
0
        private void BuildPresets()
        {
            if (cmFilters != null)
            {
                cmFilters.Dispose();
            }

            cmFilters = new ContextMenu();

            MenuItem add = new MenuItem(Pandora.Localization.TextProvider["Props.AddPreset"]);

            add.Click += new EventHandler(add_Click);
            cmFilters.MenuItems.Add(add);

            MenuItem del = new MenuItem(Pandora.Localization.TextProvider["Props.DelPreset"]);

            foreach (string s in Pandora.Profile.Props.Filters)
            {
                MenuItem presDel = new MenuItem(s);
                del.MenuItems.Add(presDel);
                presDel.Click += new EventHandler(presDel_Click);
            }

            cmFilters.MenuItems.Add(del);

            cmFilters.MenuItems.Add("-");

            foreach (string s in Pandora.Profile.Props.Filters)
            {
                MenuItem doPres = new MenuItem(s);
                doPres.Click += new EventHandler(doPres_Click);
                cmFilters.MenuItems.Add(doPres);
            }

            cmFilters.Popup += new EventHandler(cmFilters_Popup);

            cbType.ContextMenu = cmFilters;
        }
示例#8
0
        public static int PopUpSystemContextMenu(IDLWrapper idlw, Point pntShow, ref IContextMenu2 pIContextMenu2, IntPtr hwndParent, bool fCanRemove) {
            IShellFolder ppv = null;
            int num5;
            try {
                IntPtr ptr;
                if((!idlw.Available || (PInvoke.SHBindToParent(idlw.PIDL, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) != 0)) || (ppv == null)) {
                    return -1;
                }
                IntPtr[] apidl = new IntPtr[] { ptr };
                uint rgfReserved = 0;
                Guid riid = ExplorerGUIDs.IID_IContextMenu;
                object obj2 = null;
                ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2);
                if(pIContextMenu2 != null) {
                    Marshal.ReleaseComObject(pIContextMenu2);
                    pIContextMenu2 = null;
                }
                pIContextMenu2 = obj2 as IContextMenu2;
                if(pIContextMenu2 == null) {
                    return -2;
                }
                ContextMenu menu = new ContextMenu();
                uint uFlags = 0;
                if((Control.ModifierKeys & Keys.Shift) == Keys.Shift) {
                    uFlags |= 0x100;
                }
                pIContextMenu2.QueryContextMenu(menu.Handle, 0, 1, 0xffff, uFlags);
                if(fCanRemove) {
                    PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null);
                    PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xffff), QTUtility.ResMain[0x19]);
                }
                if((idlw.HasPath && (idlw.Path.Length > 3)) && (idlw.IsFileSystemFolder || idlw.IsFileSystemFile)) {
                    if(!fCanRemove) {
                        PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null);
                    }
                    PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xfffe), QTUtility.ResMain[0x1a]);
                }
                uint num3 = PInvoke.TrackPopupMenu(menu.Handle, 0x100, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero);
                int num4 = -3;
                switch(num3) {
                    case 0:
                        num4 = 0xfffd;
                        break;

                    case 0xffff:
                        menu.Dispose();
                        return 0xffff;

                    case 0xfffe:
                        if(idlw.HasPath) {
                            try {
                                string directoryName = Path.GetDirectoryName(idlw.Path);
                                if(Directory.Exists(directoryName)) {
                                    IntPtr currentHandle = QTUtility.instanceManager.CurrentHandle;
                                    if(PInvoke.IsWindow(currentHandle)) {
                                        QTUtility2.SendCOPYDATASTRUCT(currentHandle, (IntPtr)0x10, directoryName, IntPtr.Zero);
                                        num4 = 0xfffe;
                                    }
                                    else {
                                        Process.Start(directoryName);
                                        num4 = -4;
                                    }
                                }
                            }
                            catch {
                                SystemSounds.Asterisk.Play();
                            }
                        }
                        break;

                    default: {
                            CMINVOKECOMMANDINFO structure = new CMINVOKECOMMANDINFO();
                            structure.cbSize = Marshal.SizeOf(structure);
                            structure.fMask = 0;
                            structure.hwnd = hwndParent;
                            structure.lpVerb = (IntPtr)((num3 - 1) & 0xffff);
                            structure.lpParameters = IntPtr.Zero;
                            structure.lpDirectory = IntPtr.Zero;
                            structure.nShow = 1;
                            structure.dwHotKey = 0;
                            structure.hIcon = IntPtr.Zero;
                            num4 = pIContextMenu2.InvokeCommand(ref structure);
                            break;
                        }
                }
                menu.Dispose();
                num5 = num4;
            }
            catch {
                num5 = -1;
            }
            finally {
                if(ppv != null) {
                    Marshal.ReleaseComObject(ppv);
                    ppv = null;
                }
            }
            return num5;
        }
示例#9
0
 public static string TrackGroupContextMenu(string groupName, Point pnt, IntPtr pDropDownHandle) {
     string str;
     string name = string.Empty;
     if(!QTUtility.GroupPathsDic.TryGetValue(groupName, out str)) {
         return name;
     }
     string[] strArray = str.Split(QTUtility.SEPARATOR_CHAR);
     ContextMenu menu = new ContextMenu();
     if(!QTUtility.IsXP) {
         foreach(string str2 in strArray) {
             string text;
             if(str2.StartsWith(@"\\")) {
                 text = str2;
             }
             else {
                 text = ShellMethods.GetDisplayName(str2);
             }
             MenuItem item = new MenuItem(text);
             item.Name = str2;
             menu.MenuItems.Add(item);
         }
     }
     else {
         foreach(string path in strArray) {
             string displayName;
             if(path.StartsWith(@"\\")) {
                 displayName = path;
             }
             else {
                 displayName = ShellMethods.GetDisplayName(path);
             }
             MenuItemEx ex = new MenuItemEx(displayName);
             ex.Name = path;
             ex.Image = QTUtility.ImageListGlobal.Images[QTUtility.GetImageKey(path, null)];
             menu.MenuItems.Add(ex);
         }
     }
     List<IntPtr> list = new List<IntPtr>();
     if(!QTUtility.IsXP) {
         for(int k = 0; k < strArray.Length; k++) {
             string imageKey = QTUtility.GetImageKey(strArray[k], null);
             IntPtr hbitmap = ((Bitmap)QTUtility.ImageListGlobal.Images[imageKey]).GetHbitmap(Color.Black);
             if(hbitmap != IntPtr.Zero) {
                 list.Add(hbitmap);
                 PInvoke.SetMenuItemBitmaps(menu.Handle, k, 0x400, hbitmap, IntPtr.Zero);
             }
         }
     }
     uint maxValue = uint.MaxValue;
     if(menu.MenuItems.Count > 0) {
         maxValue = PInvoke.TrackPopupMenu(menu.Handle, 0x180, pnt.X, pnt.Y, 0, pDropDownHandle, IntPtr.Zero);
         if(maxValue != 0) {
             for(int m = 0; m < menu.MenuItems.Count; m++) {
                 if(maxValue == PInvoke.GetMenuItemID(menu.Handle, m)) {
                     name = menu.MenuItems[m].Name;
                     break;
                 }
             }
         }
     }
     menu.Dispose();
     if(!QTUtility.IsXP) {
         foreach(IntPtr ptr2 in list) {
             PInvoke.DeleteObject(ptr2);
         }
     }
     if(maxValue != 0) {
         return name;
     }
     return null;
 }
示例#10
0
        public void AddNewDeal(MenuItem _mi_)
        {
            //_mi_.MenuItems.Clear();

            // Сначала просканировать линии на наличие незаконченных и неопределенных сдач
            ArrayOfInt NotDefinedLines = new ArrayOfInt();
            for (int i = 0; i < VALUES.Count; i++)
            {
                for(int j = 0 ; j < VALUES[i].Count ; j++)
                {
                    if(VALUES[i, j] != null && !NotNecessaryValues.Contains(j) && VALUES[i, j].GetType().IsSubclassOf(typeof(BaseChangedData)) && (VALUES[i, j] as BaseChangedData).IsDefined() == false)
                    {
                        // пропускать пустые значения из-за "нет контракта"
                        bool skip_if_no_contract = false;
                        for (int k = 0; k < ContractColumns.Count; k++)
                        {
                            if (VALUES[i, ContractColumns[k]] != null && (VALUES[i, ContractColumns[k]] as Contract).NoContract)
                                if (NotNecessaryValues_NOCONTRACT[k].Contains(j))
                                    skip_if_no_contract = true;
                        }
                        if (skip_if_no_contract)
                            continue;

                        // если нет в списке пропущенных столбцов, значит линия НЕЗАПОЛНЕНА
                        if (!NotDefinedLines.Contains(i))
                            NotDefinedLines.Add(i);
                    }
                }
            }
            if(NotDefinedLines.Count != 0)
            {
                String s = "Сначала введите все данные в сдачи:\n";
                for(int i = 0 ; i < NotDefinedLines.Count ; i++)
                {
                    if(i > 0)
                        s += ", ";
                    if (this.isRobber)
                        s += (PAGE__VIEW ? "" : (ROBBERS.GetRobberNo(NotDefinedLines[i]) + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString() + ".") + (ROBBERS.GetRobDealNo(NotDefinedLines[i]) + 1).ToString();
                    else
                        s += (PAGE__VIEW ? "" : (MATCHES_GetMatchNo(NotDefinedLines[i]) + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString() + ".") + (MATCHES_GetMDealNo(NotDefinedLines[i]) + 1).ToString();
                }
                MessageBox.Show(s);
                return;
            }

            if (this.isRobber)
            {
                ArrayOfInt arrNotCompletedRobbers = new ArrayOfInt();
                if (ROBBERS.Count > 1)
                {
                    for (int i = 0; i < (ROBBERS.Count - 1); i++)
                        if (ROBBERS[i].IsCompleted() == false)
                            arrNotCompletedRobbers.Add(i);
                }

                if (arrNotCompletedRobbers.Count == 0) //нет незаконченных робберов
                {
                    NewDealMenu_NewRDeal(null, null);
                }
                else //в меню возможность закончить робберы
                {
                    ContextMenu ContMenu = new ContextMenu();
                    for (int i = 0; i < arrNotCompletedRobbers.Count; i++)
                    {
                        MenuItem_RDeal mi = new MenuItem_RDeal();
                        mi.robNo = arrNotCompletedRobbers[i];
                        mi.Text = "Продолжить роббер " + (mi.robNo + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString();
                        mi.Click += NewDealMenu_InsertRDeal;
                        ContMenu.MenuItems.Add(mi);
                    }
                    MenuItem mi2 = new MenuItem();
                    mi2.Text = (ROBBERS.Count == 0 || ROBBERS[ROBBERS.Count - 1].IsCompleted()) ? "Новый роббер" : "Текущий роббер";
                    mi2.Click += NewDealMenu_NewRDeal;
                    ContMenu.MenuItems.Add(mi2);
                    ContMenu.Show(Program.MainForm, new Point(0, Program.MainForm.Height - MENUHEIGHT - 1));

                    // Удалить конт.меню
                    ContMenu.MenuItems.Clear();
                    ContMenu.Dispose();
                    ContMenu = null;
                }
            }
            else if (this.isSplit)
            {
                ArrayList arrNotCompletedDeals = new ArrayList();
                for (int i = 0; i < VALUES.Count; i++)
                {
                    for (int j = 0; j < SUBDEALS.Count; j++)
                    {
                        if (VALUES[i, SUBDEALS[j, 0]] == null)
                        {
                            arrNotCompletedDeals.Add(new subdeal(i, j));
                        }
                    }
                }

                if (arrNotCompletedDeals.Count == 0) //нет незаконченных сдач
                {
                    NewDealMenu_NewMDeal(null, null);
                }
                else //в меню возможность закончить сдачу под всеми столами
                {
                    ContextMenu ContMenu = new ContextMenu();
                    for (int i = 0; i < arrNotCompletedDeals.Count; i++)
                    {
                        MenuItem_SubDeal mi = new MenuItem_SubDeal();
                        mi.subdeal = (subdeal)arrNotCompletedDeals[i];
                        mi.Text = "Сдача ";
                        if (this.isRobber)
                            mi.Text += (PAGE__VIEW ? "" : (ROBBERS.GetRobberNo(mi.subdeal.line) + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString() + ".") + (ROBBERS.GetRobDealNo(mi.subdeal.line) + 1).ToString();
                        else
                            mi.Text += (PAGE__VIEW ? "" : (MATCHES_GetMatchNo(mi.subdeal.line) + 1 + (PAGE__VIEW ? PAGE__NO : 0)).ToString() + ".") + (MATCHES_GetMDealNo(mi.subdeal.line) + 1).ToString();
                        mi.Text += " за столом " + (mi.subdeal.level + 1).ToString();
                        mi.Click += NewDealMenu_NewSubDeal;
                        ContMenu.MenuItems.Add(mi);
                    }
                    MenuItem mi2 = new MenuItem();
                    mi2.Text = "Новая сдача";
                    mi2.Click += NewDealMenu_NewMDeal;
                    ContMenu.MenuItems.Add(mi2);
                    ContMenu.Show(Program.MainForm, new Point(0, Program.MainForm.Height - MENUHEIGHT - 1));

                    // Удалить конт.меню
                    ContMenu.MenuItems.Clear();
                    ContMenu.Dispose();
                    ContMenu = null;
                }
            }
            else
            {
                NewDealMenu_NewMDeal(null, null);
            }
        }
示例#11
0
        public void AddServer(IMetadataProvider provider, ConnectionInfo connection)
        {
            //Check if the current connection can create subscription
            DataTable dt = null;

            try
            {
                dt = connection.Query("SELECT CanCreate FROM Metadata.Entity WHERE FullName='System.Subscription'");
            }
            catch (ApplicationException e)
            {
                log.Info("Exception checking if we can create subscriptions.", e);
            }

            if (dt != null && (dt.Rows.Count == 1 && dt.Columns.Count == 1))
            {
                connection.CanCreateSubscription = Convert.ToBoolean(dt.Rows[0][0]);
            }

            var tableContextMenu = new ContextMenu();
            tableContextMenu.MenuItems.Add("Generate Select Statement", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, false));
            tableContextMenu.MenuItems.Add("Generate Select Statement (with Inherited Properties)", (s, e) => GenerateSelectStatement(_contextMenuNode.Tag as Entity, true));

            if (connection.CanCreateSubscription)
                tableContextMenu.MenuItems.Add("Subscribe", StartSubscription);

            _tableContextMenuItems.Add(connection.Title, tableContextMenu);

            var serverContextMenu = new ContextMenu();
            serverContextMenu.MenuItems.Add("Refresh", (s, e) => RefreshServer(_contextMenuNode));

            if (connection.CanCreateSubscription)
                serverContextMenu.MenuItems.Add("Activity Monitor", (s, e) => OpenActivityMonitor(_contextMenuNode));

            serverContextMenu.MenuItems.Add("Generate C# Code...", (s, e) => GenerateCSharpCode(_contextMenuNode));
            serverContextMenu.MenuItems.Add("Close", (s, e) => CloseServer(_contextMenuNode));

            _serverContextMenuItems.Add(connection.Title, serverContextMenu);


            TreeNode node = CreateDatabaseNode(provider, connection);

            TreeNode[] existingNodes = _tree.Nodes.Find(node.Name, false);
            if (existingNodes.Length == 0)
            {
                // Node doesn't already exist.  Add it
                _tree.Nodes.Add(node);
                _tree.SelectedNode = node;
                RefreshServer(node);
            }
            else
            {
                // Node exists.  Just focus on it.
                _tree.SelectedNode = existingNodes[0];
            }

            connection.ConnectionClosed += (o, e) =>
            {
                _tableContextMenuItems.Remove(connection.Title);
                tableContextMenu.Dispose();
                tableContextMenu = null;

                _serverContextMenuItems.Remove(connection.Title);
                serverContextMenu.Dispose();
                serverContextMenu = null;
            };
        }
示例#12
0
		public void ShowHideTest ()
		{
			ContextMenu formMenu = new ContextMenu ();
			formMenu.MenuItems.Add ("form item 1");
			Form.ContextMenu = formMenu;

			Label label = new Label ();
			label.Text = "I have my own context menu";
			ContextMenu labelMenu = new ContextMenu ();
			labelMenu.MenuItems.Add ("label item 1");
			label.ContextMenu = labelMenu;
			Form.Controls.Add (label);
			label.Show ();

			var labelProvider = ProviderFactory.FindProvider (label);
			Assert.IsNotNull (labelProvider,
			                  "Form's label should have a provider");

			// No menu providers unless shown
			IRawElementProviderFragment formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			               "Form menu provider not expected until shown");
			IRawElementProviderFragment labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider not expected until shown");

			bridge.ResetEventLists ();

			// Test showing Form menu
			System.Windows.Point winPoint = (System.Windows.Point)
				FormProvider.GetPropertyValue (AEIds.ClickablePointProperty.Id);
			formMenu.Show (Form, new System.Drawing.Point ((int) winPoint.X, (int) winPoint.Y));

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNotNull (formMenuProvider,
			                  "Form menu provider expected once menu is shown");
			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider not expected until shown");

			Assert.AreEqual (FormProvider,
			                 formMenuProvider.Navigate (NavigateDirection.Parent),
			                 "Form menu parent should be Form");
			Assert.IsTrue (ProviderContainsChild (FormProvider, formMenuProvider),
			               "Form menu should be Form's child");

			var tuple = bridge.GetAutomationEventFrom (formMenuProvider,
			                                           AEIds.MenuOpenedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuOpenedEvent expected");

			bridge.ResetEventLists ();

			// Test closing Form menu
			formMenu.Dispose ();

			tuple = bridge.GetAutomationEventFrom (formMenuProvider,
			                                       AEIds.MenuClosedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuClosedEvent expected");

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			               "Form menu provider should be gone after menu closed");
			Assert.IsFalse (ProviderContainsChildOfType (FormProvider, ControlType.Menu),
			                "Form should have no menu child after menu closed");

			bridge.ResetEventLists ();

			// Test showing Label menu
			winPoint = (System.Windows.Point)
				labelProvider.GetPropertyValue (AEIds.ClickablePointProperty.Id);
			labelMenu.Show (label, new System.Drawing.Point ((int) winPoint.X, (int) winPoint.Y));

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			                  "Form menu provider not expected while closed");
			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNotNull (labelMenuProvider,
			               "Label menu provider expected once menu is shown");

			Assert.AreEqual (labelProvider,
			                 labelMenuProvider.Navigate (NavigateDirection.Parent),
			                 "Label menu parent should be Label");
			Assert.IsTrue (ProviderContainsChild (labelProvider, labelMenuProvider),
			               "Label menu should be Label's child");

			tuple = bridge.GetAutomationEventFrom (labelMenuProvider,
			                                           AEIds.MenuOpenedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuOpenedEvent expected");

			bridge.ResetEventLists ();

			// Test closing Label menu
			labelMenu.Dispose ();

			tuple = bridge.GetAutomationEventFrom (labelMenuProvider,
			                                       AEIds.MenuClosedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuClosedEvent expected");

			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider should be gone after menu closed");
			Assert.IsFalse (ProviderContainsChildOfType (labelProvider, ControlType.Menu),
			                "Label should have no menu child after menu closed");
		}
        private void RebuildTaskbarMenu()
        {
            trayMenu = new ContextMenu();
            /*This first checks if we have a tray icon already so we can toggle it off */
            if (trayIcon != null)
            {
                trayIcon.Visible = false;
                trayMenu.Dispose();
                trayIcon.Dispose();
            }

            /*Set up and build tray menu */
            trayMenu.MenuItems.Add(Btn1.Text, Btn1_Click);
            trayMenu.MenuItems.Add(Btn2.Text, Btn2_Click);
            trayMenu.MenuItems.Add(Btn3.Text, Btn3_Click);
            trayMenu.MenuItems.Add(Btn4.Text, Btn4_Click);
            trayMenu.MenuItems.Add(Btn5.Text, Btn5_Click);
            trayMenu.MenuItems.Add(Btn6.Text, Btn6_Click);
            trayMenu.MenuItems.Add(Btn7.Text, Btn7_Click);
            trayMenu.MenuItems.Add(Btn8.Text, Btn8_Click);
            trayMenu.MenuItems.Add(Btn9.Text, Btn9_Click);
            trayMenu.MenuItems.Add(Btn10.Text, Btn10_Click);

            foreach (MenuItem item in trayMenu.MenuItems)
            {
                if (item.Text == "")
                {
                    item.Dispose();
                }
            }

            trayMenu.MenuItems.Add("-");
            trayMenu.MenuItems.Add("Show App", ShowApp);
            trayMenu.MenuItems.Add("Exit", exitBtn_Click);

            trayIcon = new NotifyIcon();
            trayIcon.Text = "Eclipse Tech Dashboard";
            trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);

            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible = true;
        }
示例#14
0
    /// <summary>
    /// Shows a context menu for a shell item.
    /// </summary>
    /// 
    /// <param name="control">
    /// The parent control.
    /// </param>
    /// 
    /// <param name="pos">
    /// The position on <paramref name="control"/> that the menu
    /// should be displayed at.
    /// </param>
    /// <param name="aditionalFlags"></param>
    /// <param name="IsOnEmpty"></param>
    public void ShowContextMenu(Control control, Point pos, CMF aditionalFlags = 0, bool IsOnEmpty = false) {
      using (ContextMenu mnu = new ContextMenu()) {
        pos = control.PointToScreen(pos);
        Populate(mnu, aditionalFlags);
        ContextMenu view = new ContextMenu();
        ContextMenu sortMenu = new ContextMenu();
        ContextMenu groupMenu = new ContextMenu();
        int count = User32.GetMenuItemCount(mnu.Handle);
        var itemInfo = new MENUITEMINFO();
        itemInfo.cbSize = (uint)Marshal.SizeOf(itemInfo);
        itemInfo.fMask = MIIM.MIIM_FTYPE | MIIM.MIIM_DATA | MIIM.MIIM_STRING | MIIM.MIIM_SUBMENU;
        if (User32.GetMenuItemInfo(mnu.Handle, count - 1, true, ref itemInfo)) {
          if ((itemInfo.fType & 2048) != 0) {
            User32.DeleteMenu(mnu.Handle, count - 1, MF.MF_BYPOSITION);
          }
        }

        if (IsOnEmpty) {
          this.RemoveDefaultExplorerItems(mnu, control, ref itemInfo);
        }
        User32.GetMenuItemInfo(mnu.Handle, User32.GetMenuItemCount(mnu.Handle) - 3, true, ref itemInfo);
        if (itemInfo.hSubMenu == IntPtr.Zero) {
          User32.GetMenuItemInfo(mnu.Handle, User32.GetMenuItemCount(mnu.Handle) - 1, true, ref itemInfo);
        }
        this._NewMenuPtr = itemInfo.hSubMenu;

        if (IsOnEmpty) {
          this.GenerateExplorerBackgroundMenuItems(view, mnu, sortMenu, groupMenu);
        } else {
          if (this._Items.FirstOrDefault()?.IsFolder == true) {
            this.GenerateMenuItem(mnu, System.Windows.Application.Current?.FindResource("mnuOpenNewTab")?.ToString(), 301, false, 1);
          }
        }

        this.RemoveDuplicatedSeparators(mnu);

        int command = User32.TrackPopupMenuEx(mnu.Handle, TPM.TPM_RETURNCMD, pos.X, pos.Y, m_MessageWindow.Handle, IntPtr.Zero);
        if (command > 0 && command < m_CmdFirst) {
          switch (command) {
            case 245:
              this._ShellView.SetGroupOrder(false);
              break;
            case 246:
              this._ShellView.SetGroupOrder();
              break;
            case 247:
              var colasc = this._ShellView.Collumns.FirstOrDefault(w => w.ID == this._ShellView.LastSortedColumnId);
              this._ShellView.SetSortCollumn(true, colasc, SortOrder.Ascending);
              break;
            case 248:
              var coldesc = this._ShellView.Collumns.FirstOrDefault(w => w.ID == this._ShellView.LastSortedColumnId);
              this._ShellView.SetSortCollumn(true, coldesc, SortOrder.Descending);
              break;
            case 249:
              this._ShellView.PasteAvailableFiles();
              break;
            case 250:
              this._ShellView.RefreshContents();
              break;
            case 251:
              this._ShellView.View = ShellViewStyle.ExtraLargeIcon;
              break;
            case 252:
              this._ShellView.View = ShellViewStyle.LargeIcon;
              break;
            case 253:
              this._ShellView.View = ShellViewStyle.Medium;
              break;
            case 254:
              this._ShellView.View = ShellViewStyle.SmallIcon;
              break;
            case 255:
              this._ShellView.View = ShellViewStyle.List;
              break;
            case 256:
              this._ShellView.View = ShellViewStyle.Details;
              break;
            case 257:
              this._ShellView.View = ShellViewStyle.Tile;
              break;
            case 258:
              this._ShellView.View = ShellViewStyle.Content;
              break;
            case 259:
              this._ShellView.View = ShellViewStyle.Thumbstrip;
              break;
            case 260:
              if (this._ShellView.IsGroupsEnabled) {
                this._ShellView.DisableGroups();
              }
              break;
            case 301:
              this._ShellView.RaiseMiddleClickOnItem(this._Items.First());
              break;
            default:
              break;
          }
          if (command >= 262 && command <= 262 + this._ShellView.Collumns.Count) {
            this._ShellView.SetSortCollumn(true, this._ShellView.Collumns[command - 262], SortOrder.Ascending);
          } else if (command > 260 && command != 301) {
            if (!this._ShellView.IsGroupsEnabled)
              this._ShellView.EnableGroups();
            this._ShellView.GenerateGroupsFromColumn(this._ShellView.Collumns[command - (262 + this._ShellView.Collumns.Count) - 1], false);
          }
        }
        if (command > m_CmdFirst) {
          string info = string.Empty;
          byte[] bytes = new byte[256];
          int index;

          m_ComInterface.GetCommandString(command - (int)m_CmdFirst, 4, 0, bytes, 260);

          index = 0;
          while (index < bytes.Length - 1 && (bytes[index] != 0 || bytes[index + 1] != 0)) { index += 2; }

          if (index < bytes.Length - 1)
            info = Encoding.Unicode.GetString(bytes, 0, index);

          switch (info) {
            case "open":
              (control as ShellView)?.OpenOrNavigateItem();
              break;
            case "rename":
              (control as ShellView)?.RenameSelectedItem();
              break;
            case "cut":
              (control as ShellView)?.CutSelectedFiles();
              break;
            case "copy":
              (control as ShellView)?.CopySelectedFiles();
              break;
            default:
              InvokeCommand((IntPtr)(command - m_CmdFirst), pos, (IntPtr)(command - m_CmdFirst));
              break;
          }
        }

        //if (command == 0) {
        //	if (this._ShellView != null)
        //		this._ShellView.IsRenameNeeded = false;
        //}
        User32.DestroyMenu(mnu.Handle);
        view.Dispose();
        User32.DestroyMenu(view.Handle);
        sortMenu.Dispose();
        User32.DestroyMenu(sortMenu.Handle);
        groupMenu.Dispose();
        User32.DestroyMenu(groupMenu.Handle);

      }
      Marshal.ReleaseComObject(m_ComInterface);
      Marshal.ReleaseComObject(m_ComInterface2);
      Marshal.ReleaseComObject(m_ComInterface3);
      Marshal.Release(_Result);
      _Result = IntPtr.Zero;
    }