本文整理汇总了C++中SetConsoleWindowInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ SetConsoleWindowInfo函数的具体用法?C++ SetConsoleWindowInfo怎么用?C++ SetConsoleWindowInfo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetConsoleWindowInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: changeSize
void changeSize(){
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
BOOL ok;
coord.X = WINDOW_WIDTH;
coord.Y = WINDOW_HEIGHT + 1;
ok = SetConsoleScreenBufferSize(hStdout, coord);
SMALL_RECT test = { 0, 0, coord.X - 1, coord.Y - 1 };
SetConsoleWindowInfo(hStdout, ok, &test);
}
示例2: main
int main(int argc, char* argv[])
{
/*
char arg[200]={0};
arg[0]='\"';
strcpy(arg+1, argv[0]);
int len=int(strlen(arg));
arg[len]='\"';
HWND hWnd=FindWindow(NULL, arg); //找到程序运行窗口的句柄
HDC hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
HPEN hPen, hOldPen; //画笔
int j=0;
for(; j<500; ++j)
SetPixel(hDC, 10+j, 10+j, 0x0000ff);//用画点的办法画一根线,最后一个参数是颜色(32位)
hPen=CreatePen(PS_SOLID, 2, 0x00ff00);//生成绿色画笔
hOldPen=(HPEN)SelectObject(hDC, hPen);//把画笔引入设备场境
MoveToEx(hDC, 20, 50, NULL); //设置画线起点
LineTo(hDC, 520, 550); //画到终点
Arc(hDC, 100, 100, 300, 300, 350, 500, 350, 500);//画圆
SelectObject(hDC, hOldPen);
//下面是对比,表明它确实是控制台程序
printf("hello console");
system("pause");
*/
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
// 获取标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO bInfo; // 窗口缓冲区信息
GetConsoleScreenBufferInfo(hOut, &bInfo );
// 获取窗口缓冲区信息
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN);
char strTitle[255];
GetConsoleTitle(strTitle, 255); // 获取窗口标题
printf("当前窗口标题是:%s\n", strTitle);
_getch();
SetConsoleTitle("控制台窗口操作"); // 获取窗口标题
_getch();
COORD size = {80, 25};
SetConsoleScreenBufferSize(hOut,size); // 重新设置缓冲区大小
_getch();
SMALL_RECT rc = {0,0, 80-1, 25-1}; // 重置窗口位置和大小
SetConsoleWindowInfo(hOut,true ,&rc);
CloseHandle(hOut); // 关闭标准输出设备句柄
}
示例3: console_set_winsize
/*
* call-seq:
* io.winsize = [rows, columns]
*
* Tries to set console size. The effect depends on the platform and
* the running environment.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_set_winsize(VALUE io, VALUE size)
{
rb_io_t *fptr;
rb_console_size_t ws;
#if defined _WIN32
HANDLE wh;
int newrow, newcol;
#endif
VALUE row, col, xpixel, ypixel;
const VALUE *sz;
int fd;
GetOpenFile(io, fptr);
size = rb_Array(size);
rb_check_arity(RARRAY_LENINT(size), 2, 4);
sz = RARRAY_CONST_PTR(size);
row = sz[0], col = sz[1], xpixel = sz[2], ypixel = sz[3];
fd = GetWriteFD(fptr);
#if defined TIOCSWINSZ
ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0;
#define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
SET(row);
SET(col);
SET(xpixel);
SET(ypixel);
#undef SET
if (!setwinsize(fd, &ws)) rb_sys_fail(0);
#elif defined _WIN32
wh = (HANDLE)rb_w32_get_osfhandle(fd);
#define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
SET(row);
SET(col);
#undef SET
if (!NIL_P(xpixel)) (void)NUM2UINT(xpixel);
if (!NIL_P(ypixel)) (void)NUM2UINT(ypixel);
if (!GetConsoleScreenBufferInfo(wh, &ws)) {
rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo");
}
if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) ||
(ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) {
if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) {
rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo");
}
}
ws.srWindow.Left = 0;
ws.srWindow.Top = 0;
ws.srWindow.Right = newcol;
ws.srWindow.Bottom = newrow;
if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) {
rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo");
}
#endif
return io;
}
示例4: UpdateCSBI
void WinConsoleHelper::SetConsoleSize(int x, int y)
{
UpdateCSBI();
COORD windowSize = { csbi.srWindow.Right - csbi.srWindow.Left + 1, csbi.srWindow.Bottom - csbi.srWindow.Top + 1 };
if (windowSize.X > x || windowSize.Y > y)
{
SMALL_RECT info =
{
0,
0,
x < windowSize.X ? x - 1 : windowSize.X - 1,
y < windowSize.Y ? y - 1 : windowSize.Y - 1
};
SetConsoleWindowInfo(hStdOut, TRUE, &info);
}
SMALL_RECT info = { 0, 0, x - 1, y - 1 };
SetConsoleScreenBufferSize(hStdOut, { (SHORT)x, (SHORT)y });
SetConsoleWindowInfo(hStdOut, TRUE, &info);
}
示例5: SetConsoleInfo
void SetConsoleInfo()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD BufferSize = {108, 320};
SMALL_RECT WinRect = {0, 0, BufferSize.X - 1, 27};
SetConsoleScreenBufferSize(hConsole, BufferSize);
SetConsoleWindowInfo(hConsole, true, &WinRect);
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
}
示例6: ossgmx
/* get the display metrics */
void ossgmx(int *max_linep, int *max_columnp)
{
CONSOLE_SCREEN_BUFFER_INFO info;
/* get the console handle */
G_out_bufhdl = GetStdHandle(STD_OUTPUT_HANDLE);
/* get the size of the screen and return it to the caller's variables */
if (GetConsoleScreenBufferInfo(G_out_bufhdl, &info))
{
/*
* If it's scrolled down, scroll it to the top. If the screen
* buffer size is larger than the window size, reduce the buffer
* size to match the window size: we do all of the scrolling
* ourselves, so we don't want to do that on top of a separate
* scrolling canvas managed by the system.
*/
if (!os_f_plain
&& (info.srWindow.Top != 0 || info.srWindow.Left != 0
|| info.dwSize.X > info.srWindow.Right + 1
|| info.dwSize.Y > info.srWindow.Bottom + 1))
{
COORD buf_size;
/* scroll it to the top left */
info.srWindow.Bottom -= info.srWindow.Top;
info.srWindow.Top = 0;
info.srWindow.Right -= info.srWindow.Left;
info.srWindow.Left = 0;
SetConsoleWindowInfo(G_out_bufhdl, TRUE, &info.srWindow);
/* remember the original buffer size */
S_orig_buffer_size = info.dwSize;
/* set the window buffer size to equal the window size */
buf_size.X = info.srWindow.Right + 1;
buf_size.Y = info.srWindow.Bottom + 1;
SetConsoleScreenBufferSize(G_out_bufhdl, buf_size);
}
/* got the information - use the current window size */
*max_columnp = info.srWindow.Right - info.srWindow.Left;
*max_linep = info.srWindow.Bottom - info.srWindow.Top;
}
else
{
/* failed to get info - use default sizes */
*max_columnp = 79;
*max_linep = 24;
}
/* note the screen width for our own use */
S_scrwid = info.dwMaximumWindowSize.X;
}
示例7: setConsoleSize
// sets the size of the console
void setConsoleSize(unsigned short consoleWidth, unsigned short consoleHeight)
{
SMALL_RECT windowSize = {0, 0, consoleWidth-1, consoleHeight-1};
COORD buffSize = {consoleWidth, consoleHeight};
HANDLE hConsole = hScreenBuffer;//GetStdHandle( STD_OUTPUT_HANDLE );
BOOL bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &windowSize);
PERR( bSuccess, "SetConsoleWindowInfo" );
bSuccess = SetConsoleScreenBufferSize(hConsole, buffSize);
PERR( bSuccess, "SetConsoleWindowInfo" );
}
示例8: Win32EnableConsole
void Win32EnableConsole()
{
int consoleHandle;
long stdHandle;
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
FILE *file;
const int bufferSize = 500;
// allocate a console for this app
AllocConsole();
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo);
consoleInfo.dwSize.Y = bufferSize;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), consoleInfo.dwSize);
// redirect unbuffered STDOUT to the console
stdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
consoleHandle = _open_osfhandle(stdHandle, _O_TEXT);
file = _fdopen(consoleHandle, "w");
*stdout = *file;
setvbuf(stdout, NULL, _IONBF, 0);
// redirect unbuffered STDIN to the console
stdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
consoleHandle = _open_osfhandle(stdHandle, _O_TEXT);
file = _fdopen(consoleHandle, "r");
*stdin = *file;
setvbuf(stdin, NULL, _IONBF, 0);
// redirect unbuffered STDERR to the console
stdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
consoleHandle = _open_osfhandle(stdHandle, _O_TEXT);
file = _fdopen(consoleHandle, "w");
*stderr = *file;
setvbuf(stderr, NULL, _IONBF, 0);
// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std::ios::sync_with_stdio();
GetConsoleScreenBufferInfo((HANDLE)consoleHandle, &consoleInfo);
consoleInfo.srWindow.Top = 800;
SetConsoleWindowInfo((HANDLE)consoleHandle, false, &consoleInfo.srWindow);
/*
SetWindowPos(
(HWND)GetStdHandle(STD_OUTPUT_HANDLE),
HWND_TOP,
1920+100, 800,
500, 200,
SWP_NOSIZE | SWP_SHOWWINDOW);*/
}
示例9: SetWindowSize
/*-----------------------------------------------------------------------------
Console: Static Functions
---------------------------------------------------------------------------*/
static void SetWindowSize(HANDLE hOut, int height, int width)
{
COORD coPos = {(SHORT)width, (SHORT)height};
SMALL_RECT sr = {0, 0, (SHORT)(width-1), (SHORT)(height-1)};
if (SetConsoleWindowInfo(hOut, TRUE, &sr) == 0) {
fprintf(stderr, "error: SetConsoleWindowInfo: %ld\n", GetLastError());
}
if (SetConsoleScreenBufferSize(hOut, coPos) == 0) {
fprintf(stderr, "error: SetConsoleScreenBufferSize: %ld\n", GetLastError());
}
}
示例10: SetConsoleCursorPosition
/******************************************************************************
* SetConsoleCursorPosition [[email protected]]
* Sets the cursor position in console
*
* PARAMS
* hConsoleOutput [I] Handle of console screen buffer
* dwCursorPosition [I] New cursor position coordinates
*
* RETURNS STD
*/
BOOL WINAPI SetConsoleCursorPosition(HANDLE hcon, COORD pos)
{
BOOL ret;
CONSOLE_SCREEN_BUFFER_INFO csbi;
int do_move = 0;
int w, h;
TRACE("%x %d %d\n", hcon, pos.X, pos.Y);
SERVER_START_REQ(set_console_output_info)
{
req->handle = hcon;
req->cursor_x = pos.X;
req->cursor_y = pos.Y;
req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_POS;
ret = !wine_server_call_err( req );
}
SERVER_END_REQ;
if (!ret || !GetConsoleScreenBufferInfo(hcon, &csbi))
return FALSE;
/* if cursor is no longer visible, scroll the visible window... */
w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
if (pos.X < csbi.srWindow.Left)
{
csbi.srWindow.Left = min(pos.X, csbi.dwSize.X - w);
do_move++;
}
else if (pos.X > csbi.srWindow.Right)
{
csbi.srWindow.Left = max(pos.X, w) - w + 1;
do_move++;
}
csbi.srWindow.Right = csbi.srWindow.Left + w - 1;
if (pos.Y < csbi.srWindow.Top)
{
csbi.srWindow.Top = min(pos.Y, csbi.dwSize.Y - h);
do_move++;
}
else if (pos.Y > csbi.srWindow.Bottom)
{
csbi.srWindow.Top = max(pos.Y, h) - h + 1;
do_move++;
}
csbi.srWindow.Bottom = csbi.srWindow.Top + h - 1;
ret = (do_move) ? SetConsoleWindowInfo(hcon, TRUE, &csbi.srWindow) : TRUE;
return ret;
}
示例11: main
int main()
{
//////////
//Setup///
//////////
srand( (unsigned)time(0) );
Combat* pCombat = new Combat();
Report* pDamageReport = new Report( "damage_report.txt" );
pDamageReport->mFile.open( pDamageReport->getFilename(), ios::out | ios::app );
Report* pInitReport = new Report( "init_report.txt", false, 1 );
pDamageReport->addToReport( "Damage Report\n\n" );
pInitReport->addToReport( "Initialization Report\n\n" );
pDamageReport->mFile.close();
COORD newConsoleSize = {82,45}; //Resized the console so a more detailed output
SMALL_RECT rDisplayArea = {0,0,0,0}; //of damage values, criticals, ability names,
SetConsoleScreenBufferSize( pCombat->getHandle(), newConsoleSize ); //mana costs, and Damage Over Time ticks
rDisplayArea.Right = newConsoleSize.X - 1; //could be seen on screen without scrolling
SetConsoleWindowInfo( pCombat->getHandle(), true, &rDisplayArea );
Unit* pPlayer = pCombat->charInit();
Boss* pBoss = new Boss();
pCombat->units = pCombat->enemyInit( GameFunctions::getNumEnemies() );
pInitReport->initReport( pPlayer, pCombat->units ); //Output name, health, mana, armor, abilities and their names and values
//for player and units vector of enemies
pCombat->storyMsg( pPlayer->getPlayerName() );
stringstream initString;
initString << "\nPrinting Story Message. Function call: storyMsg( pPlayer->getPlayerName() )"
<< "\nSetting up Game Loop variables..."
<< "\nDetermining Combat Order..."
<< "\nEntering Game Loop...";
pInitReport->addToReport( initString.str() );
pInitReport->addToReport( "\nStarting Combat..." ); //Final output, switching to Combat report: pDamageReport
pCombat->startGameCombat( pPlayer, pBoss, pDamageReport, pCombat->units );
delete pPlayer;
pPlayer= NULL;
delete pBoss;
pBoss = NULL;
delete pCombat;
pCombat = NULL;
delete pDamageReport;
pDamageReport = NULL;
delete pInitReport;
pInitReport = NULL;
cin.ignore( 1000, '\n' );
cin.get();
return 0;
}
示例12: init_buffer
static int init_buffer(HANDLE b)
{
/* Set console size */
COORD newSize = {W*2, H+1};
SetConsoleScreenBufferSize(b, newSize);
SMALL_RECT newWinSize;
newWinSize.Left = 0;
newWinSize.Top = 0;
newWinSize.Right = W*2-1;
newWinSize.Bottom = H;
return SetConsoleWindowInfo(b, TRUE, &newWinSize);
}
示例13: GetStdHandle
void Setting::showWindow() {
HANDLE out_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SMALL_RECT src = {0, 0, this->getWindowWidth() - 1, this->getWindowHeight() - 1};
SetConsoleWindowInfo (out_handle, true, &src);
COORD coord = {this->getWindowWidth(), this->getWindowHeight()};
SetConsoleScreenBufferSize (out_handle, coord);
SetConsoleTitle(this->windowTitle.c_str());
std::string buff;
buff.append("color");
buff.append(" ");
buff.append(this->windowColor);
system(buff.c_str());
}
示例14: ResizeConsole
/*
Have to remember where i ripped this code sometime ago.
*/
static void ResizeConsole( HANDLE hConsole, SHORT xSize, SHORT ySize ) {
CONSOLE_SCREEN_BUFFER_INFO csbi; // Hold Current Console Buffer Info
BOOL bSuccess;
SMALL_RECT srWindowRect; // Hold the New Console Size
COORD coordScreen;
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
// Get the Largest Size we can size the Console Window to
coordScreen = GetLargestConsoleWindowSize( hConsole );
// Define the New Console Window Size and Scroll Position
srWindowRect.Right = (SHORT)(min(xSize, coordScreen.X) - 1);
srWindowRect.Bottom = (SHORT)(min(ySize, coordScreen.Y) - 1);
srWindowRect.Left = srWindowRect.Top = (SHORT)0;
// Define the New Console Buffer Size
coordScreen.X = xSize;
coordScreen.Y = ySize;
// If the Current Buffer is Larger than what we want, Resize the
// Console Window First, then the Buffer
if( (DWORD)csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize)
{
bSuccess = SetConsoleWindowInfo( hConsole, TRUE, &srWindowRect );
bSuccess = SetConsoleScreenBufferSize( hConsole, coordScreen );
}
// If the Current Buffer is Smaller than what we want, Resize the
// Buffer First, then the Console Window
if( (DWORD)csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize )
{
bSuccess = SetConsoleScreenBufferSize( hConsole, coordScreen );
bSuccess = SetConsoleWindowInfo( hConsole, TRUE, &srWindowRect );
}
// If the Current Buffer *is* the Size we want, Don't do anything!
return;
}
示例15: console_set_winsize
/*
* call-seq:
* io.winsize = [rows, columns]
*
* Tries to set console size. The effect depends on the platform and
* the running environment.
*
* You must require 'io/console' to use this method.
*/
static VALUE
console_set_winsize(VALUE io, VALUE size)
{
rb_io_t *fptr;
rb_console_size_t ws;
#if defined _WIN32
HANDLE wh;
int newrow, newcol;
#endif
VALUE row, col, xpixel, ypixel;
#if defined TIOCSWINSZ
int fd;
#endif
GetOpenFile(io, fptr);
size = rb_Array(size);
rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22",
&row, &col, &xpixel, &ypixel);
#if defined TIOCSWINSZ
fd = GetWriteFD(fptr);
ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0;
#define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
SET(row);
SET(col);
SET(xpixel);
SET(ypixel);
#undef SET
if (!setwinsize(fd, &ws)) rb_sys_fail(0);
#elif defined _WIN32
wh = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr));
newrow = (SHORT)NUM2UINT(row);
newcol = (SHORT)NUM2UINT(col);
if (!getwinsize(GetReadFD(fptr), &ws)) {
rb_sys_fail("GetConsoleScreenBufferInfo");
}
if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) ||
(ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) {
if (!(SetConsoleScreenBufferSize(wh, ws.dwSize) || SET_LAST_ERROR)) {
rb_sys_fail("SetConsoleScreenBufferInfo");
}
}
ws.srWindow.Left = 0;
ws.srWindow.Top = 0;
ws.srWindow.Right = newcol;
ws.srWindow.Bottom = newrow;
if (!(SetConsoleWindowInfo(wh, FALSE, &ws.srWindow) || SET_LAST_ERROR)) {
rb_sys_fail("SetConsoleWindowInfo");
}
#endif
return io;
}