使用SetLayeredWindowAttributes无法使子窗口半透明 [英] Can't make child window semi-transparent with SetLayeredWindowAttributes
问题描述
尝试使子窗口透明。 无论向SetLayeredWindowAttributes提供什么值,向子窗口提供 WS_EX_LAYERED 都会使其不可见。 然后我将以下MSDN代码
复制并粘贴到孩子的WM_CREATE处理程序中:
Trying to make a child window transparent. Providing WS_EX_LAYERED to the child window renders it invisible no matter what values are provided to SetLayeredWindowAttributes. Then I copied and pasted the following MSDN code to the child's WM_CREATE handler:
// Set WS_EX_LAYERED on this window
SetWindowLong(hwnd,
GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
// Make this window 70% alpha
SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
因为孩子的窗口背景为白色,我也尝试将该功能的第二个参数从0(零)更改为RGB(255,255,255),但它不起作用。 有没有人有一个简单的代码示例,可以让孩子的窗口半透明?
$
Since child's window background is white, I also tried to change 2nd parameter of that function from 0(zero) to RGB(255,255,255) but it didn't work. Does anyone have a simple code sample that can make a child window semi-transparent?
推荐答案
以下是一些代码:
Here is some code:
HWND hWnd2=CreateWindowEx(WS_EX_LAYERED,lpWcx2.lpszClassName,TEXT("window name2"),WS_CHILD|WS_VISIBLE,0,0,100,100,hWnd,NULL,NULL,NULL);
case WM_CREATE:
{
// Make this window 70% alpha
SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);
return 0;
}
适用于顶级窗口,但不适用于子窗口。 我在Windows 8系统上,所以该功能可以设置子窗口。出于某种原因,不是我的情况。
Works with top level window but not with child window. I'm on Windows 8 system so the function can set child windows alike. For some reason not in my case.
这篇关于使用SetLayeredWindowAttributes无法使子窗口半透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!