Search code examples
c++cwinapiwindows-10credential-providers

Windows 10 CredentialProvider Tile Image transparency


A while ago, I have created a CredentialProvider for Windows 7 that showed a custom tile image for the user. When I tested my CredentialProvider on Windows 10, I noticed that the tile image is not round as the usual Windows user image is, so I assumed, I have to provide my own round image with transparency. I tried to load a transparent PNG with the round shape and pass the corresponding HBITMAP in the ICredentialProviderCredentiall::GetBitmapValue() function. Unfortunately, instead of being transparent, the background of the PNG is white. Is there any way to show the actual transparency? Since the HBITMAP is drawn by LogonUI itself, I cannot modify the drawing behavior.

To create the HBITMAP out of my PNG resource, I use the following function:

HBITMAP LoadPNG(HINSTANCE hInst, int resourceId)
{
    HGLOBAL     hGlobal;
    LPSTREAM    pStream;
    HBITMAP tBmp = NULL;
    ULONG_PTR token = 0;
    Gdiplus::GdiplusStartupInput input = NULL;
    Gdiplus::GdiplusStartup(&token, &input, NULL);
    if (token != 0)
    {
        HRSRC   hRsrc = FindResource(hInst, MAKEINTRESOURCE(resourceId), TEXT("PNG"));
        HGLOBAL hGlob1 = LoadResource(hInst, hRsrc);

        int size = SizeofResource(hInst, hRsrc);

        hGlobal = GlobalAlloc(GMEM_FIXED, size);
        LPVOID  resPtr = LockResource(hGlob1);
        memcpy(hGlobal, resPtr, size);
        FreeResource(hGlob1);
        CreateStreamOnHGlobal(hGlobal, true, &pStream);
        Gdiplus::Bitmap* bmp = new Gdiplus::Bitmap(pStream, false);

        bmp->GetHBITMAP(Gdiplus::Color::Transparent, &tBmp);

        Gdiplus::GdiplusShutdown(token);
    }
    return tBmp;
}

I tried also other values for the GetHBITMAP() background color parameter such as AlphaMask and AlphaShift, but these did not work either (instead, the white background turned black)

Is there any way to accomplish my goal?


Solution

  • The newest Credential Provider Technical Reference (which is not that easy to find on MSDN) actually tells what the issue with the tile image is:

    In Windows 10, the selected User/V1/PLAP credential provider has an image size of 192x192. The ones on the bottom left list is of 48x48. Note LogonUI uses circular image for user and square image for V1/PLAP according to the new design direction. The image size of V2 Credential Provider tile under a selected user is 48x48.