在MFC中的一个设备上下文中绘制多个位图 - winapi

时间:2012-04-19 15:35:53

标签: c++ windows winapi mfc

我想使用单个CDC来绘制位于CDC中的3位图,然后将其传递给UpdateLayeredWindow。我的问题是我无法正确获取UpdateLayeredWindow函数的SIZE* psize参数!有人可以帮忙吗?我该怎么办?

BLENDFUNCTION bBlendFnc = {
    AC_SRC_OVER,
    0,
    255,
    AC_SRC_ALPHA
};

CBitmap btCdcBuff;
CBitmap* cache;
BITMAP hbCdcBuff;

btCdcBuff.CreateCompatibleBitmap(pCdcMain, szWndSize.cx, szWndSize.cy); btCdcBuff.GetBitmap(&hbCdcBuff);

cache = pCdcMain->SelectObject(&btCdcBuff); // pCdcMain is a compatible CDC with the screen (pCdcScreen)

Blend(&btIcon); // This function just creates a compatible CDC from a CPaintDC, selects the passed in CBitmap via SelectObject and AlphaBlends it to the pCdcMain.
pCdcMain->SelectObject(cache);

UpdateLayeredWindow(pCdcScreen, NULL, new CSize(hbCdcBuff.bmWidth, hbCdcBuff.bmHeight), pCdcMain, new CPoint(0, 0), 0, &bBlendFnc, ULW_ALPHA) // This fails and returns false

1 个答案:

答案 0 :(得分:0)

将CreateCompatibleBitmap与UpdateLayeredWindow一起使用时,请确保传入屏幕的CDC(即pCdcScreen而不是pCdcMain),以便创建的位图格式正确。请参阅此主题:http://social.msdn.microsoft.com/Forums/en/windowsuidevelopment/thread/1fbcf5e4-b9eb-4537-bf0b-d330aa333fea