Advertisement

Anyone know how to use clrscr() in VC++ 6?

Started by May 17, 2001 09:30 AM
13 comments, last by Big_Bad_Bill 23 years, 8 months ago
btw, I''m also working on a text based dos game to could you send me your icq # on here or give me a way to get in touch? I would love to get together and talk code and see how your implementing your game and maybe we can learn something from one another 8)

Armed.
VC++ don''t have those conio.h functions that you found in TC++. But to emulate those function, you could use the Windows Console functions, here are some functions to start with:

GetStdHandle()
SetConsoleCursorPosition()
ReadConsole()
WriteConsole()

Search these function in MSDN and learn them. They are one of the first few functions that I learnt when migrating from TC++ to VC++. Remember though, you need to include windows.h


Happy coding.

"after many years of singularity, i'm still searching on the event horizon"
Advertisement
To add onto what people have said about the Win32 Console API, this is how you clear the Console''s text:
  bool Clear(void) {  HANDLE hconsole = GetStdHandle (STD_OUTPUT_HANDLE);  // get the number of character cells in the current buffer  CONSOLE_SCREEN_BUFFER_INFO csbi;  if(!GetConsoleScreenBufferInfo (hconsole, &csbi))    return false;  COORD coordScreen = { 0, 0 };    // here''s where we''ll home the cursor  DWORD cCharsWritten;             // number of chars written by console output routines  DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;  // fill the entire screen with blanks  return (FillConsoleOutputCharacter (hconsole, '' '', dwConSize, coordScreen, &cCharsWritten)              &&          FillConsoleOutputAttribute (hconsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten) &&          SetConsoleCursorPosition   (hconsole, coordScreen));}  


Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
quote:
Original post by Armed and Hammered

btw, I''m also working on a text based dos game to could you send me your icq # on here or give me a way to get in touch? I would love to get together and talk code and see how your implementing your game and maybe we can learn something from one another 8)

Armed.


Well, I don''t have an ICQ # but I do have MSN Messenger, if you have that, just add stuffnotherstuff@hotmail.com to it. Also, I''m just making this game text-based right now, for a couple reasons. One is that I wanted to see if the algorithms I worked out worked, the second is that it is meant to be implemented as a graphical game (I''m making a minesweeper clone) but I don''t know a whole lot about graphics yet and I figured I could modify my existing code as I learned more about graphics. That also brings about another question for anyone. In CodeWarrior, to get random numbers, we used time.h and srand(clock()). In VC++ I''m using windows.h and srand(GetTickCount()), I tried what we used in CW but it didn''t create random numbers. Is there some other function to use to create random numbers because I noticed it takes a while to compile the code with windows.h included

Bill

Are you seeding the random number generator more than once (srand)? Only call it once if you are. Also, clock won''t produce as random of numbers when used as the seed as time(NULL). This is because clock is based off of when your program started, and time returns the time elapsed in seconds since 00:00:00 GMT, January 1, 1970.

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/

This topic is closed to new replies.

Advertisement