在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原来的函数调用协议,并实现该函数的功能。
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原来的函数调用协议,并实现该函数的功能。
有过同样的想法,后来老老实实学GDI和OpenGL了 楼主有时间可以研究下CEGUI这套库
TC下的window()函数是在文本模式使用的一个函数,只是定义了一个当前的活动窗口,后面的文本输出都在该窗口中。是可以实现的。但是TC的window()函数的表现很难与VC console 下的API对应上,建立一个屏幕缓冲区( CreateConsoleScreenBuffer )并激活它(SetConsoleActiveScreenBuffer),会将原先原先内容从屏幕上刷掉,和TC下的函数window()函数的表现不一样。拷贝原先的屏幕缓冲区的内容(读原窗口ReadConsoleOutput并写到WriteConsoleOutput新窗口的内容)不能设置当前的活动窗口大小(设置之后窗口变了,窗口之外的内容看不到了),也和TC下的函数表现不一样。
现在的问题是如何在新开一个窗口的同时,新开窗口之外的内容能保持原先的内容,且当前的活动窗口是新开的窗口,
就是创建一个文档-视图项目,然后将你要做的图draw在view上。
好像没有这样的函数吧。
或许能找到替代的方法.
至于加载后编译能不能通过,我手头没有tc,无法试验,lz可以自行试验
加载方法在tools-〉options-〉direction里
针对控制台的程序,微软提供有一堆API下面的链接介绍怎么用
http://www.builder.com.cn/2007/1030/590785.shtml
http://www.builder.com.cn/2007/1030/590775.shtml
#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的窗口位置。谢谢大家的提醒。