How to Get Window Handle (HWND) in Qt

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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.