Beispiel #1
0
        private static Standard.IShellItem2 GetShellItemForPath(string path)
        {
            object obj2;

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            Guid riid = new Guid("7e9fb0d3-919f-4307-ab2e-9b1860310c93");

            Standard.HRESULT hresult = Standard.NativeMethods.SHCreateItemFromParsingName(path, null, ref riid, out obj2);
            if ((hresult == ((Standard.HRESULT)Standard.Win32Error.ERROR_FILE_NOT_FOUND)) || (hresult == ((Standard.HRESULT)Standard.Win32Error.ERROR_PATH_NOT_FOUND)))
            {
                hresult = Standard.HRESULT.S_OK;
                obj2    = null;
            }
            hresult.ThrowIfFailed();
            return((Standard.IShellItem2)obj2);
        }
 private Standard.HRESULT _RegisterThumbButtons()
 {
     Standard.HRESULT hresult = Standard.HRESULT.S_OK;
     if (!this._haveAddedButtons)
     {
         Standard.THUMBBUTTON[] pButtons = new Standard.THUMBBUTTON[7];
         for (int i = 0; i < 7; i++)
         {
             pButtons[i] = new Standard.THUMBBUTTON {
                 iId = (uint)i, dwFlags = Standard.THBF.DISABLED | Standard.THBF.HIDDEN | Standard.THBF.NOBACKGROUND, dwMask = Standard.THB.FLAGS | Standard.THB.ICON | Standard.THB.TOOLTIP
             };
         }
         hresult = this._taskbarList.ThumbBarAddButtons(this._hwndSource.Handle, (uint)pButtons.Length, pButtons);
         if (hresult == Standard.HRESULT.E_INVALIDARG)
         {
             hresult = Standard.HRESULT.S_FALSE;
         }
         this._haveAddedButtons = hresult.Succeeded;
     }
     return(hresult);
 }
        private Standard.HRESULT _UpdateThumbButtons(bool attached)
        {
            Standard.HRESULT       hresult2;
            Standard.THUMBBUTTON[] pButtons = new Standard.THUMBBUTTON[7];
            Standard.HRESULT       hresult  = this._RegisterThumbButtons();
            if (hresult.Failed)
            {
                return(hresult);
            }
            ThumbButtonInfoCollection thumbButtonInfos = this.ThumbButtonInfos;

            try
            {
                uint index = 0;
                if (attached && (thumbButtonInfos != null))
                {
                    foreach (ThumbButtonInfo info in thumbButtonInfos)
                    {
                        Standard.THUMBBUTTON thumbbutton = new Standard.THUMBBUTTON {
                            iId    = index,
                            dwMask = Standard.THB.FLAGS | Standard.THB.ICON | Standard.THB.TOOLTIP
                        };
                        switch (info.Visibility)
                        {
                        case Visibility.Hidden:
                            thumbbutton.dwFlags = Standard.THBF.DISABLED | Standard.THBF.NOBACKGROUND;
                            thumbbutton.hIcon   = IntPtr.Zero;
                            break;

                        case Visibility.Collapsed:
                            thumbbutton.dwFlags = Standard.THBF.ENABLED | Standard.THBF.HIDDEN;
                            break;

                        default:
                            thumbbutton.szTip = info.Description ?? "";
                            thumbbutton.hIcon = this._GetHICONFromImageSource(info.ImageSource, this._overlaySize);
                            if (!info.IsBackgroundVisible)
                            {
                                thumbbutton.dwFlags |= Standard.THBF.ENABLED | Standard.THBF.NOBACKGROUND;
                            }
                            if (!info.IsEnabled)
                            {
                                thumbbutton.dwFlags |= Standard.THBF.DISABLED;
                            }
                            else
                            {
                                thumbbutton.dwFlags = thumbbutton.dwFlags;
                            }
                            if (!info.IsInteractive)
                            {
                                thumbbutton.dwFlags |= Standard.THBF.ENABLED | Standard.THBF.NONINTERACTIVE;
                            }
                            if (info.DismissWhenClicked)
                            {
                                thumbbutton.dwFlags |= Standard.THBF.DISMISSONCLICK;
                            }
                            break;
                        }
                        pButtons[index] = thumbbutton;
                        index++;
                        if (index == 7)
                        {
                            break;
                        }
                    }
                }
                while (index < 7)
                {
                    pButtons[index] = new Standard.THUMBBUTTON {
                        iId = index, dwFlags = Standard.THBF.DISABLED | Standard.THBF.HIDDEN | Standard.THBF.NOBACKGROUND, dwMask = Standard.THB.FLAGS | Standard.THB.ICON | Standard.THB.TOOLTIP
                    };
                    index++;
                }
                hresult2 = this._taskbarList.ThumbBarUpdateButtons(this._hwndSource.Handle, (uint)pButtons.Length, pButtons);
            }
            finally
            {
                foreach (Standard.THUMBBUTTON thumbbutton4 in pButtons)
                {
                    IntPtr hIcon = thumbbutton4.hIcon;
                    if (IntPtr.Zero != hIcon)
                    {
                        Standard.Utility.SafeDestroyIcon(ref hIcon);
                    }
                }
            }
            return(hresult2);
        }