QT中打開另一個應用程序


QString strExt = "Notepad";
    ui.setupUi(this);


    WId parent_HWND = winId();
    setProperty("_q_embedded_native_parent_handle", QVariant(parent_HWND));

    QString cmd = "C:/Windows/system32/" + strExt + ".exe";

    STARTUPINFO si = { sizeof(si) };
    PROCESS_INFORMATION pi;
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = true;

    bool bRet = CreateProcess(
        NULL,
        (LPWSTR)cmd.toStdWString().c_str(),
        NULL,
        NULL,
        FALSE,
        CREATE_NEW_CONSOLE,
        NULL,
        NULL, &si, &pi);

    Sleep(1000);
    HWND hhd = FindWindow(L"Notepad", NULL);
    QString Name = strExt;
    HWND SimpackWnd = hhd;
    if (SimpackWnd != NULL)
    {
        RECT rc;
        GetClientRect((HWND)(this->winId()), &rc);
        LONG style = ::GetWindowLong(SimpackWnd, GWL_STYLE);
        style &= ~WS_CLIPSIBLINGS;
        ::SetWindowLong(SimpackWnd, GWL_STYLE, style);
        ::SetParent(SimpackWnd, (HWND)(this->winId()));
        ::SetWindowPos(SimpackWnd, HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW | SWP_FRAMECHANGED);
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM