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 _UpdateThumbButtons(bool attached) { var nativeButtons = new THUMBBUTTON[c_MaximumThumbButtons]; var hr = _RegisterThumbButtons(); if (hr.Failed) { return(hr); } var thumbButtons = ThumbButtonInfos; try { uint currentButton = 0; if (attached && null != thumbButtons) { foreach (var wrappedTB in thumbButtons) { var nativeTB = new THUMBBUTTON { iId = currentButton, dwMask = THB.FLAGS | THB.TOOLTIP | THB.ICON, }; switch (wrappedTB.Visibility) { case Visibility.Collapsed: nativeTB.dwFlags = THBF.HIDDEN; break; case Visibility.Hidden: nativeTB.dwFlags = THBF.DISABLED | THBF.NOBACKGROUND; nativeTB.hIcon = IntPtr.Zero; break; default: 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; } if (!wrappedTB.IsInteractive) { nativeTB.dwFlags |= THBF.NONINTERACTIVE; } if (wrappedTB.DismissWhenClicked) { nativeTB.dwFlags |= THBF.DISMISSONCLICK; } break; } nativeButtons[currentButton] = nativeTB; ++currentButton; if (currentButton == c_MaximumThumbButtons) { break; } } } for (; currentButton < c_MaximumThumbButtons; ++currentButton) { nativeButtons[currentButton] = new THUMBBUTTON { iId = currentButton, dwFlags = THBF.NOBACKGROUND | THBF.DISABLED | THBF.HIDDEN, dwMask = THB.FLAGS | THB.ICON | THB.TOOLTIP }; } return(_taskbarList.ThumbBarUpdateButtons(_hwndSource.Handle, (uint)nativeButtons.Length, nativeButtons)); } finally { foreach (var nativeButton in nativeButtons) { var hico = nativeButton.hIcon; if (IntPtr.Zero != hico) { Utility.SafeDestroyIcon(ref hico); } } } }
void UpdateButtons() { IEnumerable <THUMBBUTTON> native = GetNativeButtons(); taskbar.ThumbBarUpdateButtons(hwnd, (uint)native.Count(), native.ToArray()); }