[Interest] Convert WId to HWND

Bo Thorsen bo at fioniasoftware.dk
Thu Dec 20 12:11:43 CET 2012


Hi everyone,

In Qt4, WId was a platform independent window handle. On Windows this 
was just a typedef from HWND. But in Qt5, that's no longer the case.

This was how I usually did it:

class X {
   void f(WId id);
};

x_win.cpp:

void X::f(WId id) {
   HWND hWnd = id;
   ...

But this is no longer directly possible. A google search for conversion 
from WId to HWND didn't give anything useful. And the qapplication_p.h 
function getHWNDForWidget suggests this is pretty difficult to do now.

I don't actually care about the conversion itself. I care about having a 
platform independent way of accessing platform specific windows. This 
was what WId was useful for earlier.

Any ideas on how to achieve this now without ifdefs in my header files? 
The goal isn't to avoid complicated code but instead to keep clean 
interfaces.

For an idea of what I'm doing with this, and why it's needed: I have an 
application that creates an overlay window over other applications. To 
do this, I have to write very platform specific code to handle the 
windows. But all my interfaces were platform independent and only the 
implementations were written for each platform. So to achieve this, I 
get the HWND from the Windows specific code, and used WId as the type. 
But maybe this was a pipe dream, because I didn't so far implement this 
on other than Windows, so perhaps it wasn't even really possible before.

Bo Thorsen.

-- 
Fionia Software - Qt experts for hire.




More information about the Interest mailing list