問題描述
我正在嘗試將 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)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!