Get HWND on windows with Qt5 (from WId)(使用 Qt5 在 Windows 上获取 HWND(来自 WId))
问题描述
我正在尝试将 Qt4 应用程序转换为 Qt5.我唯一想不通的是如何获得小部件的HWND.该程序使用 EcWin7 在 win 7+ 的任务栏图标上显示进度,但需要 HWND.将 Q_WS_WIN 更改为 Q_OS_WIN 后,lib 本身似乎可以正常编译)在 Windows 上的 Qt4 中,WId 只是 HWND 的 typedef,所以这没问题.在 Qt5 中,情况不再如此.我发现了一些 邮件列表发布 可以提供线索,但它似乎 QPlatformNativeInterface 不再是 Qt5 公共 API 的一部分.
I am trying to convert a Qt4 Application to Qt5. The only thing I couldn't figure out is how to get the HWND of a Widget. The program uses EcWin7 to show the progress on the taskbar icon on win 7+ but expects a HWND. The lib itself seems to compile fine after changing Q_WS_WIN to Q_OS_WIN) In Qt4 on Windows WId was just a typedef for HWND, so this was no problem. In Qt5 this is not the case anymore. I found some mailing list posting that could give a clue but it seems QPlatformNativeInterface is not part of the public API of Qt5 anymore.
程序调用 EcWin7.init(this->winId()); 并且我需要某种方式将此 ID 转换为 HWND id 或其他方式得到这个.
The program calls EcWin7.init(this->winId()); and I need to some way to convert this ID into the HWND id or some other way to get this.
推荐答案
在 Qt5 中 winEvent
被 nativeEvent
取代:
In Qt5 winEvent
was replaced by nativeEvent
:
bool winEvent(MSG* pMsg, long* result)
现在
bool nativeEvent(const QByteArray & eventType, void * message, long *result)
并且在 EcWin7::winEvent
中,您必须将 void
转换为 MSG
:
And in EcWin7::winEvent
you have to cast void
to MSG
:
bool EcWin7::winEvent(void * message, long * result)
{
MSG* msg = reinterpret_cast<MSG*>(message);
if (msg->message == mTaskbarMessageId)
{
...
我能够让应用程序运行!只需替换:
I was able to get the application to work! Just replace:
mWindowId = wid;
与
mWindowId = (HWND)wid;
这篇关于使用 Qt5 在 Windows 上获取 HWND(来自 WId)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Qt5 在 Windows 上获取 HWND(来自 WId)


基础教程推荐
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01