Esempio n. 1
0
        private void ShowExplorerWindow(IntPtr tabBarHandle, bool fShow)
        {
            if (contextMenuNotifyIcon.InvokeRequired)
            {
                contextMenuNotifyIcon.Invoke(new Action(() => ShowExplorerWindow(tabBarHandle, fShow)));
                return;
            }
            Instance inst;

            if (!dicNotifyIcon.TryGetValue(tabBarHandle, out inst))
            {
                return;
            }
            ITaskbarList o = null;

            try {
                object obj2;
                Guid   rclsid = ExplorerGUIDs.CLSID_TaskbarList;
                Guid   riid   = ExplorerGUIDs.IID_ITaskbarList;
                PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj2);
                o = (ITaskbarList)obj2;
                o.HrInit();
                if (fShow)
                {
                    dicNotifyIcon.Remove(tabBarHandle);
                    o.AddTab(inst.ExplorerHandle);
                    PInvoke.ShowWindow(inst.ExplorerHandle, inst.ShowWindowCode);
                    PInvoke.SetForegroundWindow(inst.ExplorerHandle);
                    notifyIcon.Visible = dicNotifyIcon.Count > 0;
                }
                else
                {
                    PInvoke.ShowWindow(inst.ExplorerHandle, 0);
                    o.DeleteTab(inst.ExplorerHandle);
                    notifyIcon.Visible = true;
                }
                UpdateContextMenu();
                if (notifyIcon.Visible)
                {
                    int count = dicNotifyIcon.Count;
                    notifyIcon.Text = count == 1
                        ? QTUtility.TextResourcesDic["TrayIcon"][0]
                        : string.Format(QTUtility.TextResourcesDic["TrayIcon"][1], count);
                }
            }
            catch (Exception exception) {
                QTUtility2.MakeErrorLog(exception);
            }
            finally {
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                }
            }
        }