我正在尝试将 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!