private HRESULT _RegisterThumbButtons()
        {
            var hr = HRESULT.S_OK;

            if (!_haveAddedButtons)
            {
                var nativeButtons = new THUMBBUTTON[c_MaximumThumbButtons];
                for (var 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
                    };
                }

                hr = _taskbarList.ThumbBarAddButtons(_hwndSource.Handle, (uint)nativeButtons.Length, nativeButtons);
                if (hr == HRESULT.E_INVALIDARG)
                {
                    hr = HRESULT.S_FALSE;
                }
                _haveAddedButtons = hr.Succeeded;
            }
            return(hr);
        }
Example #2
0
        private HRESULT _RegisterThumbButtons()
        {
            HRESULT hresult = HRESULT.S_OK;

            if (!this._haveAddedButtons)
            {
                THUMBBUTTON[] array = new THUMBBUTTON[7];
                for (int i = 0; i < 7; i++)
                {
                    array[i] = new THUMBBUTTON
                    {
                        iId     = (uint)i,
                        dwFlags = (THBF.DISABLED | THBF.NOBACKGROUND | THBF.HIDDEN),
                        dwMask  = (THB.ICON | THB.TOOLTIP | THB.FLAGS)
                    };
                }
                hresult = this._taskbarList.ThumbBarAddButtons(this._hwndSource.Handle, (uint)array.Length, array);
                if (hresult == HRESULT.E_INVALIDARG)
                {
                    hresult = HRESULT.S_FALSE;
                }
                this._haveAddedButtons = hresult.Succeeded;
            }
            return(hresult);
        }
        internal void AddThumbnailBarButtons()
        {
            var buttons     = (IList <ThumbnailBarButton>) this.ThumbnailBarButtons;
            var buttonCount = buttons.Count;

            if (buttonCount < 1)
            {
                return;
            }

            var unmanagedButtons = new THUMBBUTTON[buttonCount];

            for (int i = 0; i < buttonCount; i++)
            {
                buttons[i].Initialize(this.windowHandle);
                unmanagedButtons[i]  = buttons[i].GetUnmanagedButton();
                buttons[i].OnUpdate += this.TaskbarButton_OnUpdate;
            }

            this.taskbarList.ThumbBarAddButtons(this.windowHandle, (uint)buttonCount, unmanagedButtons);

            if (!thumbnailBarButtonsCache.ContainsKey(this.windowHandle))
            {
                thumbnailBarButtonsCache.Add(this.windowHandle, buttons);
            }
        }
Example #4
0
        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);
        }
        internal void RefreshThumbButtons()
        {
            //THUMBBUTTON[] win32Buttons =
            //    (from thumbButton in _thumbButtons.Values
            //     select thumbButton.Win32ThumbButton).ToArray();

            int index = 0;

            THUMBBUTTON[] win32Buttons = new THUMBBUTTON[_thumbButtons.Count];

            foreach (ThumbButton thumbButton in _thumbButtons.Values)
            {
                win32Buttons[index] = thumbButton.Win32ThumbButton;
                index++;
            }

            if (_buttonsLoaded)
            {
                Windows7Taskbar.TaskbarList.ThumbBarUpdateButtons(
                    _hwnd, (uint)win32Buttons.Length, win32Buttons);
            }
            else //First time
            {
                Windows7Taskbar.TaskbarList.ThumbBarAddButtons(
                    _hwnd, (uint)win32Buttons.Length, win32Buttons);
                _buttonsLoaded = true;
            }
        }
        internal THUMBBUTTON GetUnmanagedButton()
        {
            THUMBBUTTON button = new THUMBBUTTON();

            button.Id    = this.id;
            button.Mask  = THBMASK.THB_FLAGS;
            button.Flags = THBFLAGS.THBF_ENABLED;

            this.BeforeGetUnmanagedButton(ref button);

            if (this.IconHandle != null && !this.IconHandle.IsInvalid)
            {
                button.IconHandle = this.iconHandle.DangerousGetHandle();

                button.Mask |= THBMASK.THB_ICON;
            }

            if (!string.IsNullOrEmpty(this.Tooltip))
            {
                button.ToolTip = this.Tooltip;

                button.Mask |= THBMASK.THB_TOOLTIP;
            }

            if (this.IsDisabled)
            {
                button.Flags |= THBFLAGS.THBF_DISABLED;
            }

            if (this.IsDismissedOnClick)
            {
                button.Flags |= THBFLAGS.THBF_DISMISSONCLICK;
            }

            if (!this.HasBackground)
            {
                button.Flags |= THBFLAGS.THBF_NOBACKGROUND;
            }

            if (this.IsHidden)
            {
                button.Flags |= THBFLAGS.THBF_HIDDEN;
            }

            return(button);
        }
        internal THUMBBUTTON[] ToArray()
        {
            var ret = new THUMBBUTTON[maxBtns];

            for (var i = 0; i < maxBtns; i++)
            {
                if (i < Count)
                {
                    ret[i] = this[i].btn;
                }
                else
                {
                    ret[i] = THUMBBUTTON.Default;
                }
                ret[i].iId = (uint)i;
            }
            return(ret);
        }
    public ThumbnailToolbarButton(Icon icon, string tooltip)
    {
      // Set our id
      Id = _nextId;

      // increment the ID
      if (_nextId == Int32.MaxValue)
        _nextId = 101; // our starting point
      else
        _nextId++;

      // Set user settings
      Icon = icon;
      Tooltip = tooltip;

      // Create a native 
      _win32ThumbButton = new THUMBBUTTON();
    }
Example #9
0
        private static void AddThumbnailBarButtons(IntPtr windowHandle, IList <ThumbnailBarButton> buttons, IntPtr imagelistHandle)
        {
            if (!Win32.IsWindows7)
            {
                return;
            }

            CheckOperation();

            var buttonCount = buttons.Count;

            if (buttonCount < 1 || buttonCount > 7)
            {
                throw new ArgumentOutOfRangeException("buttons", "At least 1 and at most 7 buttons should be provided.");
            }

            if (imagelistHandle != IntPtr.Zero)
            {
                instance.TaskbarList.ThumbBarSetImageList(windowHandle, imagelistHandle);

                if (!thumbnailBarImageListHandles.ContainsKey(windowHandle))
                {
                    thumbnailBarImageListHandles.Add(windowHandle, imagelistHandle);
                }
            }

            var unmanagedButtons = new THUMBBUTTON[buttonCount];

            for (int i = 0; i < buttonCount; i++)
            {
                buttons[i].Initialize(windowHandle);
                unmanagedButtons[i] = buttons[i].GetUnmanagedButton();
            }

            instance.TaskbarList.ThumbBarAddButtons(windowHandle, (uint)buttonCount, unmanagedButtons);

            if (!thumbnailBarButtons.ContainsKey(windowHandle))
            {
                thumbnailBarButtons.Add(windowHandle, buttons);
            }
        }
Example #10
0
		protected void WndProcWindows7(ref Message m)
		{
			if (m.Msg == (int)RegisterWindowMessage("TaskbarButtonCreated"))
			{
				newbtn = new THUMBBUTTON()
				{
					iId = 1001,
					szTip = "新建下载任务",
					dwFlags = THBFLAGS.THBF_ENABLED,
					dwMask = THBMASK.THB_FLAGS | THBMASK.THB_ICON | THBMASK.THB_TOOLTIP,
					hIcon = ((Bitmap)btnNew.Image).GetHicon()
				};
				taskbarList.ThumbBarAddButtons(this.Handle, 1, new THUMBBUTTON[1] { newbtn });
			}

			if (m.Msg == 0x0111) //thumbbutton clicked
			{
				if ((short)(m.WParam.ToInt64() >> 16) == 0x1800)
				{
					int buttonId = (short)(m.WParam.ToInt64() & 0xFFFF);
					switch (buttonId)
					{
						case 1001:
							btnNew_Click(this, EventArgs.Empty);
							break;
						default:
							break;
					}

				}
			}
		}
Example #11
0
        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];
            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);
                    }
                }
            }
        }
Example #13
0
        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);
                    }
                }
            }
        }
Example #14
0
        internal override void BeforeGetUnmanagedButton(ref THUMBBUTTON button)
        {
            button.Bitmap = this.imageIndex;

            button.Mask |= THBMASK.THB_BITMAP;
        }
 internal virtual void BeforeGetUnmanagedButton(ref THUMBBUTTON button)
 {
 }