Advertisement

Some Windows Console Questions

Started by August 19, 2000 06:04 PM
3 comments, last by reaptide 24 years, 4 months ago
Hello everyone, I''m having to do a bit of console programming in Windows 98 and have a few questions about it. 1) How do I clear the screen. 2) How can I force the program to run fullscreen. 3) How many characters wide and high is the screen (I should probably just get off my ass and count). 4) How can I eliminate the "Press Any Key to Continue" when the program finishes. I''m coding in MSVC++ just for your info, and appriciate any help. Thanks, Reaptide
I can at least answer the 1st and 4th

Here is what I found in MSDN :
/* Standard error macro for reporting API errors */ #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \    on line %d\n", __FILE__, GetLastError(), api, __LINE__);} void cls( 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 */    /* get the number of character cells in the current buffer */    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );    PERR( bSuccess, "GetConsoleScreenBufferInfo" );    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;    /* fill the entire screen with blanks */    bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) '' '',       dwConSize, coordScreen, &cCharsWritten );    PERR( bSuccess, "FillConsoleOutputCharacter" );    /* get the current text attribute */    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );    PERR( bSuccess, "ConsoleScreenBufferInfo" );    /* now set the buffer''s attributes accordingly */    bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,       dwConSize, coordScreen, &cCharsWritten );    PERR( bSuccess, "FillConsoleOutputAttribute" );    /* put the cursor at (0, 0) */    bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );    PERR( bSuccess, "SetConsoleCursorPosition" );    return; } 


I don''t think you can get rid of the "press any key to continue" (unless there is an option somewhere in VC++ than I don''t know of), but it will only appear if you run your app from within VC++. If you build it and run it from the command line or explorer or whatever, it won''t appear.
Advertisement
1) The function clrscr() from conio.h was eliminated from VC++ so you can''t do it that way, however read the msdn you''ll probrably find something there.

2)alt-enter makes your program run in full screen

3)I think the screen is about 80 chars across, and i don''t know how many down. Just write a simple ''for'' loop that counts across and then down, thats probably as good a way as any other.

4)The press any key to continue is added not to your program, but by the window. This is only when you choose execute from VC, not when you actually run it from VC. Its just a debug thing.

Good luck!
-=[ Lucas ]=-
1) system("cls");
2) No clue, sorry
3) Varies
4) Press key to continue is not said when its opened in a dos and you execute your program from there.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
(1)
Uhm...do a loop like so
for(int i=0;i<=80;i++
{
cout << "/n"
}
That`ll be the same as pressing enter 80 times in DOS
(2)Alt-enter, i guess..
(3)You`re right, you should get up and count ! It varies i thik actually.
(4)Its a debug feature.
If I want it in release mode, i use conio.h and kbhit()
or stdio and getc*(). Whichever one i feel like at the moment
~V''lion


I came, I saw, I got programmers block.
~V''lion
~V'lionBugle4d

This topic is closed to new replies.

Advertisement