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