Re: [Dev-C++] how do you use clrscr() and gotoxy() in Dev?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jason H. <jas...@bt...> - 2001-11-12 01:39:00
|
The project option is probably disabled because you are editing a C or CPP
file, but didn't open a project for it. To enable project options you will
need to create a new project and add the file you want to it.
Also because you keep asking for a gotoxy() function and a clrscr() function
I have created them for you. There are limitations to these functions. You
have to be in a Windows console for them to work, which if you are using
Dev-C++ console mode you will be, and you have to include <windows.h>. You
may need to link the kernel32.lib (libkernel32.a), but it seems to work
without so it must be automatic, do it if you get a linker error for the
program.
Here is the code, I have made it so that you don't need to worry about
adding anything other than these two functions (and #include <windows.h>),
although I would have prefered to keep copy of the HANDLE hconsoleout as a
global, rather than regetting it for each call.
#include <windows.h>
#include <cstdlib>
#include <iostream>
inline void gotoxy(int x, int y);
inline void clrscr();
int main (int argc, char *argv[])
{
cout << "Hello";
gotoxy(25, 10);
cout << "World!";
gotoxy(50, 5);
cout << "I'm Here";
gotoxy(0,20);
system("PAUSE");
clrscr();
cout << "Hello World" << endl;
system("PAUSE");
return 0;
}
inline void gotoxy(int x, int y)
{
HANDLE hconsoleout;
hconsoleout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD XY = {x, y};
SetConsoleCursorPosition(hconsoleout, XY);
}
inline void clrscr()
{
HANDLE hconsoleout;
hconsoleout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD XY = {0, 0};
DWORD temp;
FillConsoleOutputCharacter(hconsoleout, ' ', 80*25, XY, &temp);
gotoxy(0,0); // goto topleft corner
}
If you have any problems with them just e-mail me and I'll see if I can sort
it out. Note that a normal console window is 80 by 25 in size, but can
sometimes be different, but I haven't acounted for that in clrscr(). And I
don't know what will happen if you try to use a coordinate outside that in
gotoxy(). One more thing, I'm not sure what will happen if you try these
when not in console mode, but it's probably you it will crash as I haven't
checked if the handle is valid. I'm not trying to scare you and it works
fine for me so I wouldn't worry too much.
Jason.
PS: it took me ages to find a function that would get the handle I needed.
----- Original Message -----
From: "chromatonus 712" <chr...@ho...>
To: <dev...@li...>
Sent: Sunday, November 11, 2001 9:56 PM
Subject: [Dev-C++] how do you use clrscr() and gotoxy() in Dev?
> please help...the project option in the toolbar is disabled and i don't
know
> how to use those functions even after i included conio.h in the
> headers...thanks!
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|