If you are creating a generic console app. one solution can be as follows. Try to imagine the console as a grid that holds CHARs. When you normally fire up a console in windows it is usually set at about 80x25. Thats 80 CHAR's x, and 25 CHAR's y. Now lets say that your prog, excepts the coordinates 20,15. This means that we have to move the cursor 20 spaces x, and 15 spaces y. How do we do this? Well, we can use API calls to perform this.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
//GLOBALS.
CONSOLE_SCREEN_BUFFER_INFO con_info;
HANDLE hconsole = NULL;
BOOL bCallGraphics = FALSE;
void Set_Console() { //Init. our console.
COORD console_size = {80,25};
hconsole = CreateFile("CONOUT$",GENERIC_WRITE
| GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0L);
SetConsoleScreenBufferSize(hconsole,console_size);
GetConsoleScreenBufferInfo(hconsole,&con_info);
bCallGraphics = TRUE;
}
void Set_Cursor(int x,int y) { //Set cursor to x,y coords.
COORD cursor_xy;
if(!bCallGraphics)
Set_Console();
cursor_xy.X = x;
cursor_xy.Y = y;
SetConsoleCursorPosition(hconsole,cursor_xy);
}
Now if 20,15 were passed to Set_Cursor(x,y), then the cursor would then be moved to those coordinates. Now call your square drawing function to draw your square. ->
eeee //<- The first "e" is at 20,31 respectivley.
eeee
eeee
I hope this will get you off on the right foot.
mlg400@blazemail.com