[Interest] Convert WId to HWND

Bo Thorsen bo at fioniasoftware.dk
Fri Dec 28 11:02:03 CET 2012


Den 28-12-2012 10:44, Bo Thorsen skrev:
> [...] My goal now is just to call a windows specific function with the 
> HWND from a QWidget window. Something like this:
>
> WindowsFunction(getHWND(myWidget));
>
> If this is not possible in Qt 5 without bad hacks, then it's a problem 
> that needs to be adressed. 

For future reference, this is the "solution" I came up with:

#include<5.0.0/QtGui/qpa/qplatformnativeinterface.h>


static  QWindow*  windowForWidget(const  QWidget*  widget)  {
     if  (QWindow*  window  =  widget->windowHandle())  {
         return  window;
     }
     if  (const  QWidget*  nativeParent  =  widget->nativeParentWidget())  {
         return  nativeParent->windowHandle();
     }
     return  0;
}


HWND  getHWNDForWidget(const  QWidget*  widget)  {
     if  (QWindow*  window  =  ::windowForWidget(widget))  {
         if  (window->handle())  {
             return  static_cast<HWND>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("handle"),  window));
         }
     }
     return  0;
}


This is pretty much a cut'n'paste from qapplication_p.h.

This sucks :(

Bo Thorsen.

-- 
Fionia Software - Qt experts for hire.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121228/36622782/attachment.html>


More information about the Interest mailing list