现在的位置: 首页 > 综合 > 正文

在Windows程序中打开控制台的程序

2013年05月28日 ⁄ 综合 ⁄ 共 415字 ⁄ 字号 评论关闭

//在Windows程序中打开控制台的程序
#include <stdio.h>
#include <io.h>
#include <fcntl.h>

BOOL CreateConsole(void)
{
  FreeConsole();       
  if ( AllocConsole() )
   {
         int hCrt = _open_osfhandle((long)
     GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
         *stdout = *(::_fdopen(hCrt, "w"));
     ::setvbuf(stdout, NULL, _IONBF, 0);
     *stderr = *(::_fdopen(hCrt, "w"));
     ::setvbuf(stderr, NULL, _IONBF, 0);
         return TRUE;
    }return FALSE;
}
在程序启动时调用该函数即可

【上篇】
【下篇】

抱歉!评论已关闭.