请问如何在Windows Application中使用CreateWindow创建出类似控制台的窗口 一个比较简单的问题,希望大家不要笑话 :) 

解决方案 »

  1.   

    不用CreateWindow
    AllocConsole ()一下就有了。
      

  2.   

    要想去掉控制台窗口,就FreeConsole ()一下
      

  3.   

    AllocConsole ()之后如果想使用stdin, stdout, stderr这些东西可以这样#include <io.h>
    #include ...void setup_stdio ()
    {
      int fd_stdin = _open_oosfhandle (GetStdHandle (STD_INPUT_HANDLE), _O_RDONLY);
      int fd_stdout = _open_oosfhandle (GetStdHandle (STD_OUTPUT_HANDLE), _O_TEXT);
      int fd_stderr = _open_oosfhandle (GetStdHandle (STD_ERROR_HANDLE), _O_TEXT);
      _dup2 (fd_stdin, 0);
      _dup2 (fd_stdout, 1);
      _dup2 (fd_stderr, 2);
      _close (fd_stdin);
      _close (fd_stdout);
      _close (fd_stderr);
      *stdin = *_fdopen (0, "r");
      *stdin = *_fdopen (1, "w");
      *stderr = *_fdopen (2, "w");
    };调用setup_stdio后,就可以使用printf, scanf,之类的函数了
      

  4.   

    感谢你的回复不过我想用CreateWindow,是因为我想得到窗口的HWND,用什么方法可以得到控制台窗口的句柄?谢谢!
      

  5.   

    我想使用GetConsoleWindow这个函数,但是在编译的时候不能通过,可能是该函数要求Platform SDK: DLLs, Processes, and Threads。还有其他的方法吗?
      

  6.   

    你用下面的方法试试!
    AllocConsole();
    char buf[100];
    GetConsoleTitle(buf, 100);
    CWnd *pWnd = FindWindow(NULL, buf);
             HWND hwnd = pWnd->GetSafeHwnd();
      

  7.   

    GetConsoleWindow从win2000才开始有所以你应该定义#define _WIN32_WINNT 0x500把它加在stdafx.h中最前面
      

  8.   

    请问xstring(麻雀) 你说的
    void setup_stdio ()
    {
    ....
    }
    怎么使用?我把它加在主程序中提示“error C2065: '_open_oosfhandle' : undeclared identifier”,加在stdafx.cpp中也提示错误。谢谢!