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); }
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); }