C++ 具有UpdateLayeredWindow的透明度
我有分层窗口(C++ 具有UpdateLayeredWindow的透明度,c++,winapi,C++,Winapi,我有分层窗口(WS_EX_layered),我正在尝试使用UpdateLayeredWindow在窗口上显示位图 位图是一种不规则形状,具有纯色背景RGB(30,30,30)。我想使用ULW\u COLORKEY选项使背景透明 当我调用UpdateLayeredWindow时,图像在屏幕上呈现,但背景是不透明的 // Draw background rectangle COLORREF transparent_colour = RGB(30, 30, 30); HBRUS
WS_EX_layered
),我正在尝试使用UpdateLayeredWindow
在窗口上显示位图
位图是一种不规则形状,具有纯色背景RGB(30,30,30)
。我想使用ULW\u COLORKEY
选项使背景透明
当我调用UpdateLayeredWindow
时,图像在屏幕上呈现,但背景是不透明的
// Draw background rectangle
COLORREF transparent_colour = RGB(30, 30, 30);
HBRUSH hTranparentBrush = CreateSolidBrush(transparent_colour);
HBRUSH hOldBrush = SelectObject(hSrcDC, hTransparentBrush);
// the rectangle is the size of the splash screen / layered window
hresult = Rectangle(hSrcDC, 0, 0, szSplash.cx, szSplash.cy);
//error checking has been removed
// Paint rotated bitmap over background
hresult = SetGraphicsMode(hSrcDC, GM_ADVANCED);
float s = math::sin(degree * pi / 180);
float c = math::cos(degree * pi / 180);
XFORM x;
x.em11 = c;
x.em12 = s;
x.em21 = -s;
x.em22 = c;
x.eDx = (1-c)*szImg.cx + s*szImg.cy;
x.eDy = (1-c)*szImg.cy - s*szImg.cx;
hresult = SetWorldTransform(hSrcDC, x);
// the BitBlt below succeeds. hSrcDC contains a bitmap with a solid
// background and the rotated image over it.
hresult = BitBlt(hSrcDC, 100, 100, szImg.cx, szImg.cy, hImgDC, 0, 0, SRCCOPY);
// Print to screen
POINT ptZero = {0, 0};
SIZE szBmp = szSplash; //size of the splash screen
BLENDFUNCTION blend;
blend.BlendOp = ARC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
//this call succeeds - the bitmap is printed to the screen, but the
//background is still visible?
hresult = UpdateLayeredWindow(hwndSplash,
hSplashDC,
&ptZero,
&szBmp,
hSrcDC,
&ptZero,
transparent_colour,
&blend,
ULW_COLORKEY);
如果我将
ULW_COLORKEY
替换为ULW_ALPHA
,则图像的背景和其他部分都会变得透明,看起来很糟糕。我只希望背景是透明的-我缺少什么吗?你能发布你的参数(ptZero,ptZero,blend)中的值吗?&hSrcDC
首先应该是hSrcDC
,但是如果没有更多的代码,我们就无法知道你是否犯了其他错误。谢谢大家,我已经添加了更多的代码。