qwinwidget.cpp
/*!
    \class QWinWidget qwinwidget.h
    \brief The QWinWidget class is a Qt widget that can be child of a
    native Win32 widget.

    The QWinWidget class is the bridge between an existing application
    user interface developed using native Win32 APIs or toolkits like
    MFC, and Qt based GUI elements.

    Using QWinWidget as the parent of QDialogs will ensure that
    modality, placement and stacking works properly throughout the
    entire application. If the child widget is a top level window that
    uses the \c WDestructiveClose flag, QWinWidget will destroy itself
    when the child window closes down.

    Applications moving to Qt can use QWinWidget to add new
    functionality, and gradually replace the existing interface.
*/
\class QWinWidget qwinwidget.h
\brief The QWinWidget class is a Qt widget that can be child of a
native Win32 widget.

The QWinWidget class is the bridge between an existing application
user interface developed using native Win32 APIs or toolkits like
MFC, and Qt based GUI elements.

Using QWinWidget as the parent of QDialogs will ensure that
modality, placement and stacking works properly throughout the
entire application. If the child widget is a top level window that
uses the \c WDestructiveClose flag, QWinWidget will destroy itself
when the child window closes down.

Applications moving to Qt can use QWinWidget to add new
functionality, and gradually replace the existing interface.
\ class QWinWidget qwinwidget . h \ brief The QWinWidget class is a Qt widget that can be child of a native Win32 widget . The QWinWidget class is the bridge between an existing application user interface developed using native Win32 APIs or toolkits like MFC and Qt based GUI elements . Using QWinWidget as the parent of QDialogs will ensure that modality placement and stacking works properly throughout the entire application . If the child widget is a top level window that uses the \ c WDestructiveClose flag QWinWidget will destroy itself when the child window closes down . Applications moving to Qt can use QWinWidget to add new functionality and gradually replace the existing interface .
QWinWidget::QWinWidget()
    : QWidget(nullptr),
      m_Layout(),
      p_Widget(nullptr),
      m_ParentNativeWindowHandle(nullptr),
      _prevFocus(nullptr),
      _reenableParent(false)
{
    p_ParentWinNativeWindow = new WinNativeWindow(1  * window()->devicePixelRatio()
        , 1 * window()->devicePixelRatio()
        , 1 * window()->devicePixelRatio()
        , 1 * window()->devicePixelRatio());
    m_ParentNativeWindowHandle = p_ParentWinNativeWindow->hWnd;
    Q_ASSERT(m_ParentNativeWindowHandle);
    if (m_ParentNativeWindowHandle)
    {
        setWindowFlags(Qt::FramelessWindowHint);
        setProperty("_q_embedded_native_parent_handle", (WId)m_ParentNativeWindowHandle);
        SetWindowLong((HWND)winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
        SetParent((HWND)winId(), m_ParentNativeWindowHandle);
        QEvent e(QEvent::EmbeddingControl);
        QApplication::sendEvent(this, &e);
    }
    p_ParentWinNativeWindow->childWindow = (HWND)winId();
    p_ParentWinNativeWindow->childWidget = this;
    setContentsMargins(0, 0, 0, 0);
    setLayout(&m_Layout);
    m_Layout.setContentsMargins(0, 0, 0, 0);
    m_Layout.setSpacing(0);
    p_Widget = new Widget(this);
    m_Layout.addWidget(p_Widget);
    p_Widget->setParent(this, Qt::Widget);
    p_Widget->setVisible(true);
    BORDERWIDTH = BORDERWIDTH * window()->devicePixelRatio(); 
	if (p_Widget->toolBar)
	{
		TOOLBARHEIGHT = p_Widget->toolBar->height() * window()->devicePixelRatio();
	}
	if (p_Widget->minimizeButton)
	{
		connect(p_Widget->minimizeButton, &QPushButton::clicked, this, &QWinWidget::onMinimizeButtonClicked);
	}
	if (p_Widget->maximizeButton)
	{
		connect(p_Widget->maximizeButton, &QPushButton::clicked, this, &QWinWidget::onMaximizeButtonClicked);
	}
	if (p_Widget->closeButton)
	{
		connect(p_Widget->closeButton, &QPushButton::clicked, this, &QWinWidget::onCloseButtonClicked);
	}
    SendMessage(m_ParentNativeWindowHandle, WM_SIZE, 0, 0);
}
QWinWidget :: QWinWidget ( ) : QWidget ( nullptr ) , m_Layout ( ) , p_Widget ( nullptr ) , m_ParentNativeWindowHandle ( nullptr ) , _prevFocus ( nullptr ) , _reenableParent ( false ) { p_ParentWinNativeWindow = new WinNativeWindow ( 1 * window ( ) -> devicePixelRatio ( ) , 1 * window ( ) -> devicePixelRatio ( ) , 1 * window ( ) -> devicePixelRatio ( ) , 1 * window ( ) -> devicePixelRatio ( ) ) ; m_ParentNativeWindowHandle = p_ParentWinNativeWindow -> hWnd ; Q_ASSERT ( m_ParentNativeWindowHandle ) ; if ( m_ParentNativeWindowHandle ) { setWindowFlags ( Qt :: FramelessWindowHint ) ; setProperty ( " " , ( WId ) m_ParentNativeWindowHandle ) ; SetWindowLong ( ( HWND ) winId ( ) , GWL_STYLE , WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS ) ; SetParent ( ( HWND ) winId ( ) , m_ParentNativeWindowHandle ) ; QEvent e ( QEvent :: EmbeddingControl ) ; QApplication :: sendEvent ( this , & e ) ; } p_ParentWinNativeWindow -> childWindow = ( HWND ) winId ( ) ; p_ParentWinNativeWindow -> childWidget = this ; setContentsMargins ( 0 , 0 , 0 , 0 ) ; setLayout ( & m_Layout ) ; m_Layout . setContentsMargins ( 0 , 0 , 0 , 0 ) ; m_Layout . setSpacing ( 0 ) ; p_Widget = new Widget ( this ) ; m_Layout . addWidget ( p_Widget ) ; p_Widget -> setParent ( this , Qt :: Widget ) ; p_Widget -> setVisible ( true ) ; BORDERWIDTH = BORDERWIDTH * window ( ) -> devicePixelRatio ( ) ; if ( p_Widget -> toolBar ) { TOOLBARHEIGHT = p_Widget -> toolBar -> height ( ) * window ( ) -> devicePixelRatio ( ) ; } if ( p_Widget -> minimizeButton ) { connect ( p_Widget -> minimizeButton , & QPushButton :: clicked , this , & QWinWidget :: onMinimizeButtonClicked ) ; } if ( p_Widget -> maximizeButton ) { connect ( p_Widget -> maximizeButton , & QPushButton :: clicked , this , & QWinWidget :: onMaximizeButtonClicked ) ; } if ( p_Widget -> closeButton ) { connect ( p_Widget -> closeButton , & QPushButton :: clicked , this , & QWinWidget :: onCloseButtonClicked ) ; } SendMessage ( m_ParentNativeWindowHandle , WM_SIZE , 0 , 0 ) ; }
\class QWinWidget qwinwidget.h
\brief The QWinWidget class is a Qt widget that can be child of a
native Win32 widget.
\ class QWinWidget qwinwidget . h \ brief The QWinWidget class is a Qt widget that can be child of a native Win32 widget .
//Create a native window and give it geometry values * devicePixelRatio for HiDPI support //If you want to set a minimize size for your app, do so here //p_ParentWinNativeWindow->setMinimumSize(1024 * window()->devicePixelRatio(), 768 * window()->devicePixelRatio()); //If you want to set a maximum size for your app, do so here //p_ParentWinNativeWindow->setMaximumSize(1024 * window()->devicePixelRatio(), 768 * window()->devicePixelRatio()); //Save the native window handle for shorthand use //Create the child window & embed it into the native one //Pass along our window handle & widget pointer to WinFramelessWidget so we can exchange messages //Clear margins & spacing & add the layout to prepare for the MainAppWidget //Create the true app widget  //Update the BORDERWIDTH value if needed for HiDPI displays //Update the TOOLBARHEIGHT value to match the height of toolBar * if needed, the HiDPI display //You need to keep the native window in sync with the Qt window & children, so wire min/max/close buttons to  //slots inside of QWinWidget. QWinWidget can then talk with the native window as needed  //Send the parent native window a WM_SIZE message to update the widget size 