How to load a transparent Tile Image on Windows 10 Credential Provider?

308 Views Asked by At

I am trying to load an image as a tile on a Windows 10 Credential Provider that was originally written to work on Windows 7. But now the images on Windows 10 are a circle instead of a square and would like to have the rounded edges transparent. I have used a BMP image but that did not work, so I have tried loading a PNG file that is transparent on the edges but this also does not work.

I have used the following code to load a PNG file and the file loads but it only shows it as either black or white background but not transparent (the resourceId is a resource of an image that is PNG).

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

Originally I was using this to load a BMP file but BMP does not really support transparency (in this case the IDB_TILE_IMAGE is a BMP file) :

HRESULT GetBitmapValue(DWORD dwFieldID, HBITMAP* phbmp)
{
    HRESULT hr;
    if ((SFI_TILEIMAGE == dwFieldID) && phbmp)
    {
        HBITMAP hbmp = LoadBitmap(HINST_THISDLL, MAKEINTRESOURCE(IDB_TILE_IMAGE));
        if (hbmp != NULL)
        {
            hr = S_OK;
            *phbmp = hbmp;
        }
        else
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
        }
    }
    else
    {
        hr = E_INVALIDARG;
    }
    
    return hr;
}

Any ideas on how to make a transparent tile image on Windows 10 Credential Provider so I can show an image with rounded transparent edges? What I am looking for is not a square image to be loaded as a tile but an actual circular image to match the Microsoft images that are out of the box from Windows 10.

0

There are 0 best solutions below