c – Use QT5 to get hWnd on Windows (from WID)

I am trying to convert a Qt4 application to Qt5.
The only thing I want to know is how to get the HWND of the Widget.
This program uses EcWin7 to display tasks on win 7 The progress of the bar icon, but requires an HWND. After changing Q_WS_WIN to Q_OS_WIN, the lib itself seems to compile well)
In Qt4 on Windows, Wid is just a typedef of HWND, so this is fine.
In Qt5 , This is no longer the case.
I found some mailing list postings that can provide clues, but it seems that QPlatformNativeInterface is no longer part of Qt5’s public API.

This program calls EcWin7. init(this-> winId()); I need some way to convert this ID to HWND ID or other ways to get this ID.

In Qt5, winEvent is replaced by nativeEvent:

bool winEvent(MSG* pMsg, long* result)

It’s now

bool nativeEvent(const QByteArray & eventType, void * message, long *result)

In EcWin7::winEvent you Must be forced to MSG:

bool EcWin7::winEvent(void * message, long * result)
{
MSG* msg = reinterpret_cast(message);
if (msg->message == mTaskbarMessageId)
{
...

I can make the application work! Just replace:

mWindowId = wid;

Same

mWindowId = (HWND)wid ;

I am trying to convert a Qt4 application to Qt5.
The only thing I want to know is how to get the HWND of the Widget.
The program uses EcWin7 to The progress of the taskbar icon on win 7 is displayed, but an HWND is required. After changing Q_WS_WIN to Q_OS_WIN, the lib itself seems to compile well)
In Qt4 on Windows, WId is just a typedef of HWND, so this is no problem.
br>In Qt5, this is no longer the case.
I found some mailing list postings that can provide clues, but it seems that QPlatformNativeInterface is no longer part of Qt5’s public API.

The program calls EcWin7.init(this->winId()); I need some way to convert this ID to HWND ID or other ways to get this ID.

In Qt5, winEvent is replaced by nativeEvent:

bool winEvent(MSG* pMsg, long* result)

It’s now< /p>

bool nativeEvent(const QByteArray & eventType, void * message, long *result)

In EcWin7::winEvent you must force conversion to MSG:< /p>

bool EcWin7::winEvent(void * message, long * result)
{
MSG* msg = reinterpret_cast(message);< br /> if (msg->message == mTaskbarMessageId)
{
...

I can make the application work! Just replace:

mWindowId = wid;

Same

mWindowId = (HWND)wid ;

Leave a Comment

Your email address will not be published.