Thursday, December 22, 2016

[HowTo] Prevent app to be pinned to the taskbar



#include <shellapi.h>
#include <propsys.h>
#include <propkey.h>
#include <propvarutil.h>

HRESULT MakeWindowUnpinnable(HWND hwnd)
{
    IPropertyStore* propertyStore;
    HRESULT hr = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&propertyStore));
    if (SUCCEEDED(hr))
    {
        PROPVARIANT propVariant;
        hr = InitPropVariantFromBoolean(TRUE, &propVariant);
        if (SUCCEEDED(hr))
        {
            hr = propertyStore->SetValue(PKEY_AppUserModel_PreventPinning, propVariant);
            PropVariantClear(&propVariant);
        }
        propertyStore->Release();
    }
    return hr;
}

No comments:

Post a Comment