我正在尝试将Qt4应用程序转换为Qt5。我唯一搞不懂的就是如何获得Widget的HWND。该程序使用EcWin7来显示win 7+上任务栏图标上的进度,但期望有一个HWND。在将Q_WS_WIN更改为Q_OS_WIN之后,库本身似乎编译得很好,在Windows WId上的Qt4中,它只是一个用于HWND的类型胡枝子,所以这是没有问题的。在Qt5中,情况不再是这样了。我发现了一些可以提供线索的邮寄名单投寄,但似乎QPlatformNativeInterface不再是Qt5的公共API的一部分了。
该程序调用EcWin7.init( this ->winId());我需要某种方式将这个ID转换为HWND id,或者以其他方式获得这个id。
发布于 2013-04-21 23:59:08
在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)
{
...我能让应用程序开始工作!只需替换:
mWindowId = wid;使用
mWindowId = (HWND)wid;发布于 2013-01-24 11:27:56
#include <QtGui/5.0.0/QtGui/qpa/qplatformnativeinterface.h>
static QWindow* windowForWidget(const QWidget* widget)
{
QWindow* window = widget->windowHandle();
if (window)
return window;
const QWidget* nativeParent = widget->nativeParentWidget();
if (nativeParent)
return nativeParent->windowHandle();
return 0;
}
HWND getHWNDForWidget(const QWidget* widget)
{
QWindow* window = ::windowForWidget(widget);
if (window && window->handle())
{
QPlatformNativeInterface* interface = QGuiApplication::platformNativeInterface();
return static_cast<HWND>(interface->nativeResourceForWindow(QByteArrayLiteral("handle"), window));
}
return 0;
}发布于 2013-01-09 22:23:55
你可以尝试:
(HWND)QWidget::winId();https://stackoverflow.com/questions/14048565
复制相似问题