c++ - 带有 WS_EX_LAYERED 的 Qt 透明子窗口总是失败
问题描述
我通过创建子窗口并将窗口句柄传递给 libVLC 以呈现视频,将 libVLC 集成到 Windows 上的 Qt Quick 应用程序中。
这工作正常。
但是,我正在尝试使用该WS_EX_LAYERED
样式创建子窗口,以便对其应用一些透明度。我根本无法让它工作。
这是代码:
const auto parentWindow = quickWindow()->winId(); //The native window handle
const auto windowClassName = QString("VLCWindow-").append(QString::number(reinterpret_cast<int64_t>(this), 16)).toStdWString();
WNDCLASSEXW wcx = {};
wcx.cbSize = sizeof(wcx);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = DefWindowProcW;
wcx.hbrBackground = static_cast<HBRUSH>(::GetStockObject(BLACK_BRUSH));
wcx.hInstance = ::GetModuleHandle(nullptr);
wcx.lpszClassName = windowClassName.data();
if (!::RegisterClassExW(&wcx)) {
const auto lastError = ::GetLastError();
if (lastError != ERROR_CLASS_ALREADY_EXISTS) {
qCritical() << "RegisterClassEx failed:" << lastError;
return;
}
}
const auto nativeWindowHandle = ::CreateWindowExW(WS_EX_LAYERED, wcx.lpszClassName, L"", WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 0, 0, reinterpret_cast<HWND>(parentWindow), nullptr, ::GetModuleHandle(nullptr), nullptr);
if (nativeWindowHandle) {
qInfo() << "Created native window for VLC rendering; handle:" << nativeWindowHandle;
} else {
auto err = ::GetLastError();
qCritical() << "CreateWindowEx failed:" << err;
return;
}
以上CreateWindowExW
总是失败并GetLastEror()
返回 0!一旦我删除WS_EX_LAYERED
,一切都很好,但我需要WS_EX_LAYERED
. 我在 Windows 10 上运行代码,因此WS_EX_LAYERED
对 pre-Windows 8 的限制不适用。
我尝试了以下方法:
调用
CreateWindowsExW(0, ...
(成功)然后调用SetWindowLongPtrW
applyWS_EX_LAYERED
,但SetWindowLongPtrW
返回 0GetLastError
也返回 0!将我自己的信息传递
lpfnWndProc
到RegisterClassEx
我记录收到的所有消息类型的地方;我收到的唯一消息是 aWM_NCDESTROY
,之前没有WM_NCCREATE
发送过任何消息!
非常感谢!
解决方案
推荐阅读
- java - 无法在未调用 Looper.prepare() 的线程 Thread[create_react_context,5,main] 中创建处理程序
- c++ - 是否建议将 =default 析构函数与空构造函数一起使用?
- javascript - 如何将javascript代码更改为angular中的打字稿
- angular - 在 CF 上部署时出错:“ERR 服务命令需要在 Angular 项目中运行,但找不到项目定义。”
- java - 当我关闭数据库时,永远不会从 Spring JPA 调用 TransactionException - 为什么?
- sql - 计算 SQL 中每个类别经过的时间
- node.js - 使用“projects.locations.instances.create”获得 404,firebase + node.js
- swift - 如何在 Swift UI 中从 Cloud Firebase 中检索数组中的数据?
- vba - 在 MS-Access 中将 CURL 请求转换为 VBA xml 对象
- node.js - Nodemailer 谷歌工作区在开发中工作,但在生产中,电子邮件变成垃圾邮件