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

MFC CWnd as child window of QWidget



  • I'm porting a large application from MFC to Qt.

    I've replaced the main window with a QMainWindow, but I am at a loss as how I can have MFC windows as children.

    I thought initially that QWinHost was the tool for this, but AFAICT it just isn't intended to do that.

    Having QWidgets as a child of a CWnd I understand: I just use a QWinWidget as an MFC CWnd that also happens to be a QWidget, so can host another QWidget.

    So how do I get a QWidget to host a CWnd ? Or do I only convert the main window as the very last stage AFTER all MFC windows and dialogs have been converted to QWidgets?

    Thanks
    David


  • Lifetime Qt Champion

    Hi
    What do you mean by
    "MFC windows as children."
    You mean free windows, belonging to your app ?
    OR now use Windows as widgets ?
    Or you call components from MFC for windows also ? ( as the win API also does)

    Try with
    WId externalWindow = (WId)FindWindow(NULL, L"Untitled - Notepad"); // only if external.
    QWindow *myWindow = QWindow::fromWinId(externalWindow);
    QWidget *myWidget = QWidget::createWindowContainer(myWindow);

    But on windows, it has issues with keys and mouse wheel but clicking did work fine.



  • I mean having MFC windows inside a widget.

    So I might have a layout (e.g. a grid) that has both Widgets and MFC windows in it.

    D.


Log in to reply