Question

I've googled, seen examples, other questions here, MSDN and Downloaded Example code. I cannot figure out what is wrong with this.

// setting up the memory DC and selecting in the bitmap
HDC hdc = GetDC(hWnd);
HDC hdcMem = CreateCompatibleDC(hdc);
ReleaseDC(hWnd, hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap.hbmLogo);

// setting up the blend function
BLENDFUNCTION bStruct; 
bStruct.BlendOp = AC_SRC_OVER;
bStruct.BlendFlags = 0;
bStruct.SourceConstantAlpha = 255;
bStruct.AlphaFormat = AC_SRC_ALPHA;

// try
BOOL check = AlphaBlend(buffer.getBufferDC(), 0, 0, bitmap.bmLogo.bmWidth, bitmap.bmLogo.bmHeight, hdcMem, 0, 0, bitmap.bmLogo.bmWidth, bitmap.bmLogo.bmHeight, bStruct);
if (check == FALSE) MessageBox(0,0,0,0);

// this is how I load the bitmap, it is a resource. 
bitmap.hbmLogo = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LOGO_0));
if (bitmap.hbmLogo == NULL) { MessageBox(NULL, "Could not read the logo bitmap.", "Error", MB_OK); return false; }
GetObject(bitmap.hbmLogo, sizeof(bitmap.bmLogo), &bitmap.bmLogo);

I use the message box to quickly check the result. Check always returns TRUE. The bitmap and its dimensions are correct.

I've tried it over different background colors, alpha values, and still nothing, replacing that with BitBlt or TransparentBitBlt, no problem, the logo displays. All my attempts with the AlphaBlend function has resulted in no change. The logo does not appear, even for a second, on the screen.

Any ideas?

Thanks.

Here is the bitmap.

Was it helpful?

Solution

Found the solution after looking closer at an example.

I set the BLENDFUNCTION as a global, and in the WM_CREATE message I used:

    m_bf.BlendOp = AC_SRC_OVER;
    m_bf.BlendFlags = 0;
    m_bf.SourceConstantAlpha = 100; // any 0 to 255
    m_bf.AlphaFormat = 0;
    LoadBitmapsFromResource();

and it is now working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top