Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An urgent question abuot VC++ console mode

Status
Not open for further replies.

cheraghchi

Programmer
May 28, 2001
3
CZ
Hi everybody...

I'm looking for the source code of a (object-oriented) console text editor written in Visual C++. Anybody can help me? Or just tell me how can I move the cursor to a desired position in the console mode? (In order to write a console text editor myself)

Thanks and hope to see an answer
M.CH

 
#define WIN32_LEAN_AND_MEAN
#include <iostream>
#include <windows.h>

HANDLE SetConsole( int iX=80,int iY=25 );
void SetCursorPos( HANDLE hCon,int x,int y );

int main()
{
HANDLE hConsole=NULL;
int xPos,yPos;

hConsole=SetConsole();

std::cout << &quot;Enter the X pos of cursor:&quot;;
std::cin >> xPos;
std::cout << &quot;Enter the Y pos of cursor:&quot;;
std::cin >> yPos;

SetCursorPos( hConsole,xPos,yPos );
std::cout << &quot;The cursor is now at &quot; <<
xPos << &quot;,&quot; << yPos << &quot;.&quot; <<
std::endl;

return 0;
}

HANDLE SetConsole( int x,int y )
{
CONSOLE_SCREEN_BUFFER_INFO conInfo;
HANDLE hConsole;
COORD consoleSize={ x,y };
hConsole=CreateFile( &quot;CONOUT$&quot;,GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0L );

SetConsoleScreenBufferSize( hConsole,consoleSize );
GetConsoleScreenBufferInfo( hConsole,&conInfo );

return hConsole;
}

void SetCursorPos( HANDLE hCon,int x,int y )
{
COORD cursor_xy;
cursor_xy.X=x;
cursor_xy.Y=y;
SetConsoleCursorPosition( hCon,cursor_xy );
} Mike L.G.
mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top