microsoftxiao

记忆 流逝

导航

还是WinGUI Win32 WinMain中嵌如控制台

#include <fcntl.h>
#include <io.h>
//-------------
//函数名: StdPipe
//目的: 在WinMain中嵌入窗口
//-------------
int StdConsole()
{
   AllocConsole();
 
    hIn = GetStdHandle(STD_INPUT_HANDLE);
 hOut = GetStdHandle(STD_OUTPUT_HANDLE);
 hErr = GetStdHandle(STD_ERROR_HANDLE);

    SetConsoleTitle("内嵌Cmd");
    FILE *hf = NULL;
 char buf[2];

    //输出
 int hCrt = 0;
 hCrt = (long)_open_osfhandle((intptr_t)hOut,_O_TEXT);
 hf = _fdopen(hCrt,"w");    //表示可写
 setvbuf(hf,buf,_IONBF,1);
 *stdout = *hf;
   
 //输入
 int hCirt = 0;
 hCirt = _open_osfhandle((intptr_t)hIn,_O_TEXT);
 FILE    *hfIn = NULL;
 hfIn = _fdopen(hCirt,"r");
    setvbuf(hfIn,buf,_IONBF,1);
 *stdin = *hfIn;
   
 //错误
 int hErt = 0;
 hErt = _open_osfhandle((intptr_t)hErr,_O_TEXT);
 FILE   *hfErr = NULL;
    hfErr = _fdopen(hErt,"w");
    setvbuf(hfErr,buf,_IONBF,1);
 *stderr = *hfErr;

    return 0;
}

posted on 2006-09-30 09:21  龙巢NET刀  阅读(547)  评论(0)    收藏  举报