gpt4 book ai didi

winapi - 如何在子控件上使用 WS_EX_LAYERED

转载 作者:行者123 更新时间:2023-12-02 05:28:26 26 4
gpt4 key购买 nike

自 Windows 8 起,WS_EX_LAYERED 可在子控件上使用(MSDN 如此说),但是我一直无法使其工作。在下面的代码中,我尝试使子控件半透明,但是当在控件上使用 WS_EX_LAYERED 时,不会绘制任何内容。

int APIENTRY wWinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInst, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
WNDCLASSEX wc = {};

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszClassName = _T("main");
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClassEx(&wc);

HWND MWhwnd = CreateWindowEx(NULL, _T("main"), _T(""),
WS_OVERLAPPEDWINDOW| WS_CLIPCHILDREN,
CW_USEDEFAULT, 0, CW_USEDEFAULT,0, NULL, NULL, hInst, NULL);

wc.lpfnWndProc = WndProcPanel;
wc.lpszClassName = _T("CPanel");
wc.style = NULL;
RegisterClassEx(&wc);

HWND Panelhwnd = CreateWindowEx(WS_EX_LAYERED, _T("CPanel"), _T(""),
WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS| WS_CLIPCHILDREN,
100, 10, 400, 400, MWhwnd, NULL, hInst, NULL);

COLORREF crefKey = RGB(0, 255, 0);
SetLayeredWindowAttributes(Panelhwnd, crefKey, 155, LWA_ALPHA);

ShowWindow(MWhwnd, nCmdShow);

在此示例中,我使用自定义控件,但我尝试使用 WC_BUTTON 获得相同的结果。控件无法绘制。但我可以毫无问题地使主窗口透明。

使用 WINDOWS 10 和 VS2015 以及普通 win32(无 MFC、ATL 等)

最佳答案

感谢 @Hans 建议的链接,我找到了答案。需要一个 list 条目来指定至少 Windows 8 兼容性(子分层支持仅从 Windows 8 开始)。对于任何想要使用分层子窗口的人来说,以下内容应作为 list 文件包含在内。

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates app support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>

为了完整起见,我包含了整个文件,但相关标签是 <compatibility>指定 Windows 8 GUID 的元素。

您也可以声明对其他操作系统版本的兼容性,如文档页面“Targeting your application for Windows”中所述。

关于winapi - 如何在子控件上使用 WS_EX_LAYERED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42569348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com