在TC下window的函数说明是:
declaration: void window(int _left, int _top, int _right, int _bottom);
s:
The top left corner of the screen is (1,1)
window() function defines a text window onscreen. If the coordinates are
  * in any way invalid, the call to window is ignored.  * (left, top) is the (x, y) position of the window's upper left corner.  * (right, bottom) is the (x, y) position of the window's lower right corner.  * The minimum size of the text window is one column by one line.  * The default window is full screen, with these coordinates:
  *  80-column mode:  (1, 1, 80, 25)
  *  40-column mode:  (1, 1, 40, 25)
但在VC下没有对应的函数,如何能编写一个在VC++6控制台下使用的window函数,遵循TC原来的函数调用协议,并实现该函数的功能。

解决方案 »

  1.   

    我在学校时曾经考虑把TC的graphic图形库移植到VC6环境下使用,后来放弃了。
      

  2.   


    有过同样的想法,后来老老实实学GDI和OpenGL了 楼主有时间可以研究下CEGUI这套库
      

  3.   

    续问题:
        TC下的window()函数是在文本模式使用的一个函数,只是定义了一个当前的活动窗口,后面的文本输出都在该窗口中。是可以实现的。但是TC的window()函数的表现很难与VC console 下的API对应上,建立一个屏幕缓冲区( CreateConsoleScreenBuffer )并激活它(SetConsoleActiveScreenBuffer),会将原先原先内容从屏幕上刷掉,和TC下的函数window()函数的表现不一样。拷贝原先的屏幕缓冲区的内容(读原窗口ReadConsoleOutput并写到WriteConsoleOutput新窗口的内容)不能设置当前的活动窗口大小(设置之后窗口变了,窗口之外的内容看不到了),也和TC下的函数表现不一样。
        现在的问题是如何在新开一个窗口的同时,新开窗口之外的内容能保持原先的内容,且当前的活动窗口是新开的窗口,
      

  4.   

    思路要变一下,用MFC的View实现。
    就是创建一个文档-视图项目,然后将你要做的图draw在view上。
      

  5.   

    就是要动态创建一个CView类。
      

  6.   

    如何能编写一个在VC++6控制台下使用的window函数,遵循TC原来的函数调用协议,并实现该函数的功能。
    好像没有这样的函数吧。
      

  7.   

    MSDN中搜索console function
    或许能找到替代的方法.
      

  8.   

    这个一定要用VC吗?用TC不就得了。
      

  9.   

    起码要加载window函数相关的库和头文件
    至于加载后编译能不能通过,我手头没有tc,无法试验,lz可以自行试验
    加载方法在tools-〉options-〉direction里
      

  10.   

    费力,是不是想要黑屏效果?把窗口刷成黑色的就可以了,用窗口自己也可以事先命令输入,而且更灵活,用控制台模拟很费力的,搞的那么麻烦
    针对控制台的程序,微软提供有一堆API下面的链接介绍怎么用
    http://www.builder.com.cn/2007/1030/590785.shtml
    http://www.builder.com.cn/2007/1030/590775.shtml
      

  11.   

    to 14楼 binsir543,加载TC的头文件和库文件通不过编译,不同的编译器有不同的“方言”,库函数的实现大都有自己编译器的特性。要修改太难了。另外lib库的文件格式也不一样。即使编译通过,也链接不上。TO 15楼hurryboylqs TC的window函数只是定义了一个窗口,不是把窗口刷成黑色,那应该是clrscr()的任务。VC提供的控制台API应该能够实现该功能。现在我已基本实现了一些相关的函数。Window的实现应该不是太难。谢谢关注和支持。
      

  12.   

    结贴。参照TC的帮助说明和网上搜寻的资料在VC6实现了部分TC的函数。关于window()和相关的函数分享。希望对大家有帮助。少走弯路。
    #include<windows.h>// current window position
    static SMALL_RECT gs_srCurrentWinPos = { 0, 0, 79, 24 };
    void gotoxy(int x,int y)
    {
    BOOL bSuccess;
    COORD To = {x-1,y-1};
    if( x<1 || x>80 || y<1 || y>25 ) 
    {
    SetLastError(87);//参数错误
    return;
    } bSuccess = SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),To);
    PERR(bSuccess,"SetConsoleCursorPosition");//自定义宏

    }
    void clrscr(void)
    {

    HANDLE hConsole; 
        COORD coordScreen = { 0, 0 };    /* here's where we'll home the cursor */ 
        BOOL bSuccess;
        DWORD cCharsWritten;
        CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ 
        DWORD dwConSize;                 /* number of character cells in the current buffer */ 
    short iStartCol,iEndCol;
    int i;
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    /* get the number of character cells in the current buffer */ 
    if(0 == gs_srCurrentWinPos.Left && 0 == gs_srCurrentWinPos.Top && 
    79 == gs_srCurrentWinPos.Right && 24 == gs_srCurrentWinPos.Bottom)
        {
    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
    PERR( bSuccess, "GetConsoleScreenBufferInfo" );
    dwConSize = csbi.dwSize.X ;
    iStartCol = csbi.srWindow.Top; iEndCol =csbi.dwMaximumWindowSize.Y; 
    coordScreen.X = csbi.srWindow.Left; coordScreen.Y = csbi.srWindow.Top;
        }
    else
    {
    iStartCol = gs_srCurrentWinPos.Top; iEndCol = gs_srCurrentWinPos.Bottom;
    dwConSize = gs_srCurrentWinPos.Right-gs_srCurrentWinPos.Left+1;
    coordScreen.X = gs_srCurrentWinPos.Left; coordScreen.Y = gs_srCurrentWinPos.Top; }
        /* fill the entire screen with blanks */ 
    for(i = iStartCol;i<=iEndCol;i++)
    {
    bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
    dwConSize, coordScreen, &cCharsWritten );
    PERR( bSuccess, "FillConsoleOutputCharacter" );
    coordScreen.Y++;
    }
        /* get the current text attribute */ 

        bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
        PERR( bSuccess, "ConsoleScreenBufferInfo" );

        /* now set the buffer's attributes accordingly */ 
    for(i = iStartCol,coordScreen.Y=iStartCol; i<=iEndCol; i++)
    {

    bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
    dwConSize, coordScreen, &cCharsWritten );
    PERR( bSuccess, "FillConsoleOutputAttribute" );
    coordScreen.Y++;
    }

        /* put the cursor at (srCurrentWinPos.Left,srCurrentWinPos.Top) */

    coordScreen.Y -= ( iEndCol - iStartCol+1);
        bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
        PERR( bSuccess, "SetConsoleCursorPosition" );
        return;

    }
    void window(int _left, int _top, int _right, int _bottom)
    {
    // actual window position in VC console api is from (0,0),(79,24) 
    if ( _left <1 || _top <1 || _right >80 || _bottom >25) return;
    if ( _left >  _right || _top > _bottom ) return; gs_srCurrentWinPos.Left = _left - 1;
    gs_srCurrentWinPos.Top = _top - 1;
    gs_srCurrentWinPos.Right = _right - 1;
    gs_srCurrentWinPos.Bottom = _bottom -1; gotoxy(_left,_top);
    }
    其他函数如果和window()窗口相关,是需要重写的,需要用到window的窗口位置。谢谢大家的提醒。