Hello!

I've used the code in this thred to generate an image on the Console. It works fine but the problem is that I don't know how to clear the screen in dev-cpp. I've imported some libraries (conio & winbgim) from this site and clrscr() works but it only deletes text characters and doesn't delete the graphics part.
Altough I've imported the graphics library from that site and correctly linked it in dev-cpp, the cleardevice() function does not work, it does not delete the picture from the screen and the program does not give me any errors.
I'm looking for a function which can delete the picture on the screen in dev-cpp.

Thanks in advance,
gh0sst

Member Avatar for iamthwee

Have you tried system("cls") ?

tried it now but it doesn't seem to work.
it seems to do the same thing that clrscr() does (deletes the characters on the screen and puts the cursor in (1,1) position).
i need for all the graphics to be deleted ( the picture ).

thx for the reply,
gh0sst

look in the drawing functions in graphics.h. There is probably a function that will fill a rectangle with some desired color -- just make the size of that rectangle the size of the screen.

Note: This isn't my code, but something I found in one of the WinAPI tutorials on a forum.

#include <windows.h>
#include <cstdio>
#include <iostream>
#include <cstdlib>


//This will clear the console.
void ClearConsole()
{
     //Get the handle to the current output buffer...
     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
     //This is used to reset the carat/cursor to the top left.
     COORD coord = {0, 0};
     //A return value... indicating how many chars were written
     //   not used but we need to capture this since it will be
     //   written anyway (passing NULL causes an access violation).
     DWORD count;
     //This is a structure containing all of the console info
     // it is used here to find the size of the console.
     CONSOLE_SCREEN_BUFFER_INFO csbi;
     //Here we will set the current color
     if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
     {
          //This fills the buffer with a given character (in this case 32=space).
          FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
          FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
          //This will set our cursor position for the next print statement.
          SetConsoleCursorPosition(hStdOut, coord);
     }
     return;
}

Note: This isn't my code, but something I found in one of the WinAPI tutorials on a forum.

That's nice code for console programs. Doesn't help the OP though to clear a graphics screen as he has already stated (several times too)

Maybe this will do ... RedrawWindow(hConsoleWnd, 0, 0, RDW_INVALIDATE); hConsoleWnd is the console's window handle.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.