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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing a square-Beginner

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i am a a beginner with c++ programing and i need help desingning a program using simple programiing to design a program that accepts as input cordinates of a square and drawit on the screend.

also the aquare has to be drawn using alphabets...like "e" then the sqaure is drawn using e's..

Please help coz I am new at programming and need genuine help...

hansen
 
The problem is too ambiguous and answer deppend on what are you using, DOS, Windows, what do you want to do. Simple do draw a squaer in windows is to egt the display DC and draw it. But the shape will be instant, ie will be removed very fast. John Fill
1c.bmp


ivfmd@mail.md
 
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(&quot;CONOUT$&quot;,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 &quot;e&quot; is at 20,31 respectivley.
eeee
eeee

I hope this will get you off on the right foot.


mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top