Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML's Native parent Window



  • I write a QML Window like this

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: text1.width
        height: text1.height
        title: qsTr("Hello World")
        flags: Qt.FramelessWindowHint
        color: "#70000000"
        x: 0
        y: 0
        Text {
            id: text1
            x: 0
            y: 0
            text: "Hello World"
            color: "#FFFF0000"
        }
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
        QQuickView::setSceneGraphBackend(QSGRendererInterface::Software);
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        if (engine.rootObjects().isEmpty())
            return -1;
        QQuickWindow *pMainWnd = qobject_cast<QQuickWindow*>(engine.rootObjects()[0]);
        HWND hShowWnd = (HWND)pMainWnd->winId();
    
        DWORD dwStyle = GetWindowLong(hShowWnd, GWL_STYLE);
        SetWindowLong(hShowWnd, GWL_STYLE, dwStyle | WS_POPUP | WS_VISIBLE);
        DWORD dwExStyle = GetWindowLong(hShowWnd, GWL_EXSTYLE);
        SetWindowLong(hShowWnd, GWL_EXSTYLE, dwExStyle | WS_EX_TOOLWINDOW);
        HWND hWndParent = FindWindow(nullptr, TEXT("MFCApplication1"));
        SetParent(hShowWnd, hWndParent); //Windows API
        return app.exec();
    }
    

    it can not display on MFCApplication1 Window


Log in to reply