在Windows上使用Qt5(从WId)获取HWND [英] Get HWND on windows with Qt5 (from WId)
问题描述
我试图将Qt4应用程序转换为Qt5。
我唯一无法想出的是如何获得一个Widget的 HWND 。
此程序使用 EcWin7 以显示win 7+上的任务栏图标的进度,但希望有一个 HWND 。 lib本身似乎编译正确后更改* Q_WS_WIN *到* Q_OS_WIN *)
在Windows上的Qt4 WId 只是一个typedef的 HWND ,所以这是没问题。
在Qt5这不是这样的情况了。
我发现了一些邮件列表发布,可以提供线索,但似乎
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
:
bool winEvent(MSG* pMsg, long* result)
现在是
bool nativeEvent(const QByteArray & eventType, void * message, long *result)
而在 EcWin7 :: winEvent
必须将 void
转换为 MSG
:
bool EcWin7::winEvent(void * message, long * result)
{
MSG* msg = reinterpret_cast<MSG*>(message);
if (msg->message == mTaskbarMessageId)
{
...
b $ b
我能够使应用程序工作!只需替换:
I was able to get the application to work! Just replace:
mWindowId = wid;
mWindowId = (HWND)wid;
这篇关于在Windows上使用Qt5(从WId)获取HWND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!