| | |
Clear the Screen using WinApi functions
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Many of the code samples on the internet are written in Turbo C. The clrscr() function litters these samples, and even to this day people want to wipe your screen. You can use system("CLS"), but that uses a DOS command. DOS commands are with us only at the whim of William the Mighty. Here is the Windows version of clearing the console screen with WinApi functions, in the hope that these functions will stay around a little longer.
// test of the official Windows Console clear the screen function // tested with Pelles C vegaseat 26mar2005 #include <stdio.h> void clrscr(void); #include <windows.h> void clrscr(void) { COORD coordScreen = { 0, 0 }; // upper left corner DWORD cCharsWritten; DWORD dwConSize; HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(hCon, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; // fill with spaces FillConsoleOutputCharacter(hCon, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); GetConsoleScreenBufferInfo(hCon, &csbi); FillConsoleOutputAttribute(hCon, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); // cursor to upper left corner SetConsoleCursorPosition(hCon, coordScreen); } int main(void) { int k; for(k = 0; k < 25; k++) { printf("Test........\n"); } printf("Press Enter..."); getchar(); clrscr(); getchar(); // wait return 0; }
Similar Threads
- Clear Screen (Assembly)
- Clear screen... ? (Java)
- clear screen (C++)
- How do i clear my screen in C++ (C++)
- Clear screen (C++)
| Thread Tools | Search this Thread |
* ansi api append array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() directory dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez grade graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches initialization intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi



