0
votes

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.

1
you're gonna give us a little more details than that. do you have the bitmap selected to the hdcmem? what are the values in bstruct? etc. what do you expect to see? what do you actually see?thang
My mistake, updating now.Evan Carslake
you're gonna have to give the piece of code that creates the bitmap... the format of the bitmap matters.thang
Also, DeleteDC on a DC you get back from GetDC isn't a good idea (particularly when you also call ReleaseDC on the same thing two lines later).Jonathan Potter
yup: msdn.microsoft.com/en-us/library/windows/desktop/dd183393(v=vs.85).aspx. the documentation confirms - When the AlphaFormat member is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, the AlphaBlend function will fail. if you want to use alpha, you need to have alpha.thang

1 Answers

1
votes

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.