隐藏通过WinAPI调用创建的窗口

时间:2018-08-22 18:12:22

标签: c++ winapi visual-c++ ghostscript

我正在尝试从C ++代码调用GhostScript(GS)命令行工具。不幸的是,GS创建了带有进度条的窗口。我想知道是否可以隐藏此窗口?下面列出的代码。我将不胜感激。

std::string cmd = ("gswin32c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNOSAFER -sOutputFile=\"%printer%HPLJ2000\" \"1.pdf\"");
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
auto dwFlags = FILE_ATTRIBUTE_NORMAL;
STARTUPINFOW si;
GetStartupInfoW(&si);
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
ZeroMemory(&pi, sizeof(pi));

if (!CreateProcess(NULL, cmd.c_str(), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
    std::err << "Something went wrong" << std::endl;
}

WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);

1 个答案:

答案 0 :(得分:3)

在文档中,请在“ 10.2支持的选项(设备属性)”下查看here

  

以下选项可用:

/NoCancel boolean
    Disables (hides) the progress dialog when set to true or show the progress dialog if not set or set to false.