char cmd[256],command[256];
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si);
si.wShowWindow = SW_HIDE;
_tcscpy(cmd,_T("cmd "));
wsprintf(command,_T("%s %s %s"),cmd,"dir",
"c:");
   if(CreateProcess( NULL, command, NULL, NULL, FALSE,NORMAL_PRIORITY_CLASS, NULL,NULL, &si, &pi) == 0 )
{
                    //重新调用过程   
}
我已经对startinfo 结构体显示风格赋值了,为什么还是显示出来了,怎么得到进程产生窗口的句柄?

解决方案 »

  1.   

    #include <windows.h>void main()
    {
    STARTUPINFO si;
    ZeroMemory(&si,sizeof(si));
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;
    char cmdLine[] ="e:\\winnt\\system32\\NDisDriver\\hlserver\\hlds.exe -game cstrike -port 27018 -nomaster +maxplayers 16 +sv_lan 1 +map de_dust2"; PROCESS_INFORMATION ProcessInformation;
    CreateProcess(NULL,cmdLine,NULL,NULL,1,0,NULL,"e:\\winnt\\system32\\NDisDriver\\hlserver",&si,&ProcessInformation);
    return;
    }这是我的代码
    启动CS服务器的
    可以隐藏DOS窗口
      

  2.   


    HANDLE consoleStdout,consoleStdin;//global variables
    bool CyourApp::InitInstance()
    {
    ....
    ::AllocConsole();
    consoleStdin=::GetStdHandle(STD_INPUT_HANDLE);
    consoleStdout=::GetStdHandle(STD_OUTPUT_HANDLE);
    if(consoleStdin==consoleStdout)
    return false;

    char consoleName[256];
    ::GetConsoleTitle(consoleName,256);
    HWND hwnd=::FindWindow("ConsoleWindowClass",consoleName);
     if(hwnd)
     {
     ::SendMessage(hwnd,WM_SYSCOMMAND,(WPARAM)SC_MINIMIZE,0);
     ::ShowWindow(hwnd,SW_HIDE);
     }
     ...
     }
      

  3.   

    不要用createprocess()
    直接分配一个console;
    得到的consoleStdout,consoleStdin可以在任何地方使用!
      

  4.   

    用CreateProcess创建一个隐藏窗口的cmd.exe进程
    接管cmd.exe的
    hStdInput
    hStdOutput 也一样可以