How to Get Window Handle (HWND) in Qt

Posted on Posted in Qt Tutorials, Tutorials

You can use the following approach to get a Window‘s Handle in Qt. This can be useful in case you need to call a Windows API (Win32 API) function that is not implemented in Qt or for any other purposes.

HWND(winId()) can be used to correctly get the handle of a window. For example you can have the following:

MessageBox(HWND(winId()), TEXT(“test”), TEXT(“test”), 0);

MessageBox function above is just an example (and a very simple one) to explain how you can pass a handle to a Windows API function.

Leave a Reply

Your email address will not be published. Required fields are marked *