开发者

How to locate prompt in console application?

Is there a way to place the prompt programm开发者_开发百科aticaly in a console application? I'm using Visual Studio 2008.

Thanks


Do you mean moving the blinking thingy? If so I think SetConsoleCursorPosition is what you want. Console Functions reference page http://msdn.microsoft.com/en-us/libr...73(VS.85).aspx


Assuming you're talking about the output position, you can control it at two levels.

At the highest level, you can use control characters such as carriage return, line feed and backspace. Check out your nearest ASCII table.

At a lower level, you can use the Windows API console functions.

Those functions are in turn divided into two levels, and depending on what you want to control (e.g. response to Ctrl C) you may have to delve down to the very lowest level.

A more portable alternative to is to use some portable "terminal" library such as ncurses.

Cheers & hth.,


Found on the .NET

#include <windows.h>
#include <stdio.h>

void Locate ( int row, int col )
{ if ( row < 0 || row > 24 ) return;
  if ( col < 0 || col > 79 ) return;
  COORD c = { (SHORT)col, (SHORT)row };
  SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), c ); }

void main ( )
{ int row;
  int col;
  printf ( "Row (0-24): " ); scanf ( "%d", &row );
  printf ( "Col (0-79): " ); scanf ( "%d", &col );
  Locate ( row, col );
  printf ( "This text is starting at row %d, column %d\n", row, col ); }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜