|  | Home

# QWinHost Class Reference

The QWinHost class provides an API to use native Win32 windows in Qt applications. More...

     #include <QWinHost>

Inherits QWidget.

- List of all members, including inherited members

## Public Functions

| QWinHost ( QWidget * parent = 0, Qt::WFlags f = 0 )
| ~QWinHost ()
void | setWindow ( HWND window )
HWND | window () const

- 217 public functions inherited from QWidget
- 13 public functions inherited from QPaintDevice
- 29 public functions inherited from QObject

## Protected Functions

virtual HWND | createWindow ( HWND parent, HINSTANCE instance )

## Reimplemented Protected Functions

virtual bool | event ( QEvent * e )
virtual void | focusInEvent ( QFocusEvent * e )
virtual void | resizeEvent ( QResizeEvent * e )
virtual void | showEvent ( QShowEvent * e )
virtual bool | winEvent ( MSG * msg, long * result )

- 37 protected functions inherited from QWidget
- 1 protected function inherited from QPaintDevice
- 7 protected functions inherited from QObject

### Additional Inherited Members

- 58 properties inherited from QWidget
- 1 property inherited from QObject
- 19 public slots inherited from QWidget
- 1 public slot inherited from QObject
- 1 signal inherited from QWidget
- 1 signal inherited from QObject
- 1 public type inherited from QObject
- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject
- 1 protected slot inherited from QWidget
- 1 protected type inherited from QPaintDevice
- 2 protected variables inherited from QObject

## Detailed Description

The QWinHost class provides an API to use native Win32 windows in Qt applications.

QWinHost exists to provide a QWidget that can act as a parent for any native Win32 control. Since QWinHost is a proper QWidget, it can be used as a toplevel widget (e.g. 0 parent) or as a child of any other QWidget.

QWinHost integrates the native control into the Qt user interface, e.g. handles focus switches and laying out.

Applications moving to Qt may have custom Win32 controls that will take time to rewrite with Qt. Such applications can use these custom controls as children of QWinHost widgets. This allows the application's user interface to be replaced gradually.

When the QWinHost is destroyed, and the Win32 window hasn't been set with setWindow(), the window will also be destroyed.

## Member Function Documentation

### QWinHost::QWinHost ( QWidget * parent = 0, Qt::WFlags f = 0 )

Creates an instance of QWinHost. parent and f are passed on to the QWidget constructor. The widget has by default no background.

Warning: You cannot change the parent widget of the QWinHost instance after the native window has been created, i.e. do not call QWidget::setParent or move the QWinHost into a different layout.

### QWinHost::~QWinHost ()

Destroys the QWinHost object. If the hosted Win32 window has not been set explicitly using setWindow() the window will be destroyed.

### HWND QWinHost::createWindow ( HWND parent, HINSTANCE instance ) `[virtual protected]`

Reimplement this virtual function to create and return the native Win32 window. parent is the handle to this widget, and instance is the handle to the application instance. The returned HWND must be a child of the parent HWND.

The default implementation returns null. The window returned by a reimplementation of this function is owned by this QWinHost instance and will be destroyed in the destructor.

This function is called by the implementation of polish() if no window has been set explicitly using setWindow(). Call polish() to force this function to be called.

See also setWindow().

### bool QWinHost::event ( QEvent * e ) `[virtual protected]`

Reimplemented from QObject::event().

### void QWinHost::focusInEvent ( QFocusEvent * e ) `[virtual protected]`

Reimplemented from QWidget::focusInEvent().

### void QWinHost::resizeEvent ( QResizeEvent * e ) `[virtual protected]`

Reimplemented from QWidget::resizeEvent().

### void QWinHost::setWindow ( HWND window )

Sets the native Win32 window to window. If window is not a child window of this widget, then it is reparented to become one. If window is not a child window (i.e. WS_OVERLAPPED is set), then this function does nothing.

The lifetime of the window handle will be managed by Windows, QWinHost does not call DestroyWindow. To verify that the handle is destroyed when expected, handle WM_DESTROY in the window procedure.

See also window() and createWindow().

### void QWinHost::showEvent ( QShowEvent * e ) `[virtual protected]`

Reimplemented from QWidget::showEvent().

### bool QWinHost::winEvent ( MSG * msg, long * result ) `[virtual protected]`

Reimplemented from QWidget::winEvent().

### HWND QWinHost::window () const

Returns the handle to the native Win32 window, or null if no window has been set or created yet.

See also setWindow() and createWindow().