public TaskbarItemInfo() { if (!DesignerProperties.GetIsInDesignMode(this)) { ITaskbarList taskbarList = null; try { taskbarList = CLSID.CoCreateInstance <ITaskbarList>(CLSID.TaskbarList); taskbarList.HrInit(); // This QI will only work on Win7. _taskbarList = taskbarList as ITaskbarList3; taskbarList = null; } finally { Utility.SafeRelease(ref taskbarList); } _overlaySize = new Size( NativeMethods.GetSystemMetrics(SM.CXSMICON), NativeMethods.GetSystemMetrics(SM.CYSMICON)); } // Set ThumbButtons to an empty list so callers can just use the property. ThumbButtonInfos = new ThumbButtonInfoCollection(); }
public TaskbarItemInfo() { if (!DesignerProperties.GetIsInDesignMode(this)) { ITaskbarList taskbarList = null; try { taskbarList = CLSID.CoCreateInstance <ITaskbarList>("56FDF344-FD6D-11d0-958A-006097C9A090"); taskbarList.HrInit(); this._taskbarList = (taskbarList as ITaskbarList3); taskbarList = null; } finally { Utility.SafeRelease <ITaskbarList>(ref taskbarList); } this._overlaySize = new Size((double)NativeMethods.GetSystemMetrics(SM.CXSMICON), (double)NativeMethods.GetSystemMetrics(SM.CYSMICON)); } this.ThumbButtonInfos = new ThumbButtonInfoCollection(); }
private HRESULT _UpdateThumbButtons(bool attached) { THUMBBUTTON[] array = new THUMBBUTTON[7]; HRESULT result = this._RegisterThumbButtons(); if (result.Failed) { return(result); } ThumbButtonInfoCollection thumbButtonInfos = this.ThumbButtonInfos; HRESULT result2; try { uint num = 0u; if (!attached || thumbButtonInfos == null) { goto IL_1AE; } using (FreezableCollection <ThumbButtonInfo> .Enumerator enumerator = thumbButtonInfos.GetEnumerator()) { while (enumerator.MoveNext()) { ThumbButtonInfo thumbButtonInfo = enumerator.Current; THUMBBUTTON thumbbutton = new THUMBBUTTON { iId = num, dwMask = (THB.ICON | THB.TOOLTIP | THB.FLAGS) }; switch (thumbButtonInfo.Visibility) { case Visibility.Visible: goto IL_A5; case Visibility.Hidden: thumbbutton.dwFlags = (THBF.DISABLED | THBF.NOBACKGROUND); thumbbutton.hIcon = IntPtr.Zero; break; case Visibility.Collapsed: thumbbutton.dwFlags = THBF.HIDDEN; break; default: goto IL_A5; } IL_146: array[(int)((UIntPtr)num)] = thumbbutton; num += 1u; if (num != 7u) { continue; } break; IL_A5: thumbbutton.szTip = (thumbButtonInfo.Description ?? ""); thumbbutton.hIcon = this._GetHICONFromImageSource(thumbButtonInfo.ImageSource, this._overlaySize); if (!thumbButtonInfo.IsBackgroundVisible) { thumbbutton.dwFlags |= THBF.NOBACKGROUND; } if (!thumbButtonInfo.IsEnabled) { thumbbutton.dwFlags |= THBF.DISABLED; } else { thumbbutton.dwFlags = thumbbutton.dwFlags; } if (!thumbButtonInfo.IsInteractive) { thumbbutton.dwFlags |= THBF.NONINTERACTIVE; } if (thumbButtonInfo.DismissWhenClicked) { thumbbutton.dwFlags |= THBF.DISMISSONCLICK; goto IL_146; } goto IL_146; } goto IL_1AE; } IL_179: array[(int)((UIntPtr)num)] = new THUMBBUTTON { iId = num, dwFlags = (THBF.DISABLED | THBF.NOBACKGROUND | THBF.HIDDEN), dwMask = (THB.ICON | THB.TOOLTIP | THB.FLAGS) }; num += 1u; IL_1AE: if (num < 7u) { goto IL_179; } result2 = this._taskbarList.ThumbBarUpdateButtons(this._hwndSource.Handle, (uint)array.Length, array); } finally { foreach (THUMBBUTTON thumbbutton2 in array) { IntPtr hIcon = thumbbutton2.hIcon; if (IntPtr.Zero != hIcon) { Utility.SafeDestroyIcon(ref hIcon); } } } return(result2); }
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 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); }