wintaskbar.c revision 35c4bbdf
1/* 2 Permission is hereby granted, free of charge, to any person obtaining a 3 copy of this software and associated documentation files (the "Software"), 4 to deal in the Software without restriction, including without limitation 5 the rights to use, copy, modify, merge, publish, distribute, sublicense, 6 and/or sell copies of the Software, and to permit persons to whom the 7 Software is furnished to do so, subject to the following conditions: 8 9 The above copyright notice and this permission notice (including the next 10 paragraph) shall be included in all copies or substantial portions of the 11 Software. 12 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 DEALINGS IN THE SOFTWARE. 20*/ 21 22#ifdef HAVE_XWIN_CONFIG_H 23#include <xwin-config.h> 24#endif 25 26#include "win.h" 27#include "winwindow.h" 28 29const GUID CLSID_TaskbarList = {0x56fdf344,0xfd6d,0x11d0,{0x95,0x8a,0x0,0x60,0x97,0xc9,0xa0,0x90}}; 30const GUID IID_ITaskbarList = {0x56fdf342,0xfd6d,0x11d0,{0x95,0x8a,0x0,0x60,0x97,0xc9,0xa0,0x90}}; 31 32#ifdef INTERFACE 33#undef INTERFACE 34#endif 35 36#define INTERFACE ITaskbarList 37DECLARE_INTERFACE_(ITaskbarList, IUnknown) 38{ 39 /* IUnknown methods */ 40 STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **ppv) PURE; 41 STDMETHOD_(ULONG, AddRef) (THIS) PURE; 42 STDMETHOD_(ULONG, Release) (THIS) PURE; 43 44 /* ITaskbarList methods */ 45 STDMETHOD(HrInit) (THIS) PURE; 46 STDMETHOD(AddTab) (THIS_ HWND hWnd) PURE; 47 STDMETHOD(DeleteTab) (THIS_ HWND hWnd) PURE; 48 STDMETHOD(ActivateTab) (THIS_ HWND hWnd) PURE; 49 STDMETHOD(SetActiveAlt) (THIS_ HWND hWnd) PURE; 50}; 51#undef INTERFACE 52 53/* 54 The stuff above needs to be in win32api headers, not defined here, 55 or at least generated from the MIDL :-) 56*/ 57 58/* 59 This is unnecessarily heavyweight, we could just call CoInitialize() once at 60 startup and CoUninitialize() once at shutdown 61*/ 62 63/* 64 The documentation for ITaskbarList::AddTab says that we are responsible for 65 deleting the tab ourselves when the window is deleted, but that doesn't actually 66 seem to be the case 67*/ 68 69void winShowWindowOnTaskbar(HWND hWnd, BOOL show) 70{ 71 ITaskbarList* pTaskbarList = NULL; 72 73 if (SUCCEEDED(CoInitialize(NULL))) 74 { 75 if (SUCCEEDED(CoCreateInstance((const CLSID *)&CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, (const IID *)&IID_ITaskbarList, (void**)&pTaskbarList))) 76 { 77 if (SUCCEEDED(pTaskbarList->lpVtbl->HrInit(pTaskbarList))) 78 { 79 if (show) 80 { 81 pTaskbarList->lpVtbl->AddTab(pTaskbarList,hWnd); 82 } 83 else 84 { 85 pTaskbarList->lpVtbl->DeleteTab(pTaskbarList,hWnd); 86 } 87 } 88 pTaskbarList->lpVtbl->Release(pTaskbarList); 89 } 90 CoUninitialize(); 91 } 92} 93