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

Hide Window by CreateProcess WinApi



  • Hello,

    I would like to hide qemu application and create application something like fsproxy. I find very interesting function WinApi "CreateProcess" and structure "STARTUPINFO". So i Wrote:

    wchar_t qemu_args[2048] = L"\"C:\\Users\Tom\\Desktop\\apps\\qemu.exe (here args)\"";
    wchar_t path[256]= L"C:\\Users\\Tom\\Desktop\\apps\\";
    
    STARTUPINFO si;
    memset(&si, 0, sizeof(STARTUPINFO));
    GetStartupInfo(&si);
    si.dwFlags	   = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;
    
    CreateProcess(NULL, qemu_args, NULL, NULL, FALSE, 0, NULL, path, &si, &xa);
    

    When I set si (dwFlags and wShowWindow) I get 2 windows: myQTApplication ( xyz.exe ) and qemu
    When I don't set si I get 3 windows: myQTApplication ( xyz.exe ), qemu and consoleWindow (its name is pathToBuildXYZexe)

    So si structure only hide that ConsoleWindow ( pathToBuildXYZexe ).

    I know that I can get hmnd to qemu window by name and hide window, but I would like to do that when process is created.

    And my second question is: Why I can't set the 8-th parameter ( path ) to NULL. When I give here NULL, QEMU don't start. I have to give path to qemu folder.

    EDIT:
    Now I wrote very basic console application in QT abc.exe:

    #include <QCoreApplication>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        qDebug()<<"1";
        return a.exec();
    }
    

    When I execute abc.exe from xyz.exe ( myMainQTGUIApplication ) by CreateProcess and when si is set I get 2 windows: xyz.exe and consoleWindow (its name is pathToBuildXYZexe) with text "1" ( this is output from abc.exe).
    When I execute abc.exe from xyz.exe ( myMainQTGUIApplication ) by CreateProcess and when si isn't set I get 2 windows: xyz.exe and consoleWindow (its name is pathToBuildXYZexe) with notext.

    EDIT2
    Back to qemu. When I don't set si there are 3 windows. But when I close qemu, the window with name pathToBuildXYZexe is closed too. When I close pathToBuildXYZexe, qemu is closed too. In manager I see 2 processess: qemu and xyz.exe.

    EDIT3
    I think qemu is not hidden beacuse it's blocking terminal Application. But I think there is another solution...