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 HRESULT _UpdateThumbButtons(bool attached) { var nativeButtons = new THUMBBUTTON[c_MaximumThumbButtons]; HRESULT hr = _RegisterThumbButtons(); if (hr.Failed) { return hr; } ThumbButtonInfoCollection thumbButtons = ThumbButtonInfos; try { uint currentButton = 0; if (attached && null != thumbButtons) { foreach (ThumbButtonInfo wrappedTB in thumbButtons) { var nativeTB = new THUMBBUTTON { iId = (uint)currentButton, dwMask = THB.FLAGS | THB.TOOLTIP | THB.ICON, }; switch (wrappedTB.Visibility) { case Visibility.Collapsed: // HIDDEN removes the button from layout logic. nativeTB.dwFlags = THBF.HIDDEN; break; case Visibility.Hidden: // To match WPF's notion of hidden, we want this not HIDDEN, // but disabled, without background, and without icon. nativeTB.dwFlags = THBF.DISABLED | THBF.NOBACKGROUND; nativeTB.hIcon = IntPtr.Zero; break; default: case Visibility.Visible: nativeTB.szTip = wrappedTB.Description ?? ""; nativeTB.hIcon = _GetHICONFromImageSource(wrappedTB.ImageSource, _overlaySize); if (!wrappedTB.IsBackgroundVisible) { nativeTB.dwFlags |= THBF.NOBACKGROUND; } if (!wrappedTB.IsEnabled) { nativeTB.dwFlags |= THBF.DISABLED; } else { nativeTB.dwFlags |= THBF.ENABLED; } // This is separate from enabled/disabled if (!wrappedTB.IsInteractive) { nativeTB.dwFlags |= THBF.NONINTERACTIVE; } if (wrappedTB.DismissWhenClicked) { nativeTB.dwFlags |= THBF.DISMISSONCLICK; } break; } nativeButtons[currentButton] = nativeTB; ++currentButton; if (currentButton == c_MaximumThumbButtons) { break; } } } // If we're not attached, or the list is less than the maximum number of buttons // then fill in the rest with collapsed, empty buttons. for (; currentButton < c_MaximumThumbButtons; ++currentButton) { nativeButtons[currentButton] = new THUMBBUTTON { iId = (uint)currentButton, dwFlags = THBF.NOBACKGROUND | THBF.DISABLED | THBF.HIDDEN, dwMask = THB.FLAGS | THB.ICON | THB.TOOLTIP }; } // Finally, apply the update. return _taskbarList.ThumbBarUpdateButtons(_hwndSource.Handle, (uint)nativeButtons.Length, nativeButtons); } finally { foreach (var nativeButton in nativeButtons) { IntPtr hico = nativeButton.hIcon; if (IntPtr.Zero != hico) { Utility.SafeDestroyIcon(ref hico); } } } }
private HRESULT _RegisterThumbButtons() { HRESULT hr = HRESULT.S_OK; if (!_haveAddedButtons) { // The ITaskbarList3 API requires that the maximum number of buttons to ever be used // are registered at the beginning. Modifications can be made to this list later. var nativeButtons = new THUMBBUTTON[c_MaximumThumbButtons]; for (int i = 0; i < c_MaximumThumbButtons; ++i) { nativeButtons[i] = new THUMBBUTTON { iId = (uint)i, dwFlags = THBF.NOBACKGROUND | THBF.DISABLED | THBF.HIDDEN, dwMask = THB.FLAGS | THB.ICON | THB.TOOLTIP }; } // If this gets called (successfully) more than once it usually returns E_INVALIDARG. It's not really // a failure and we potentially want to retry this operation. hr = _taskbarList.ThumbBarAddButtons(_hwndSource.Handle, (uint)nativeButtons.Length, nativeButtons); if (hr == HRESULT.E_INVALIDARG) { hr = HRESULT.S_FALSE; } _haveAddedButtons = hr.Succeeded; } return hr; }
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); }