File: gc_consoleio.c

package info (click to toggle)
geekcode 1.7.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 288 kB
  • ctags: 96
  • sloc: ansic: 2,940; makefile: 41
file content (76 lines) | stat: -rw-r--r-- 2,533 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 gc_consoleio.c - Functions for Console I/O

 Geek Code Generator v1.7.3 - Generates your geek code
 Copyright (C) 1999-2003 Chris Gushue <chris@blackplasma.net>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef _WIN32

   /* Use standard ANSI codes for clearing screen */
   #include <stdio.h>

   void clearscreen()
   {
      printf("\033[2J");
   }

#else /* Win32 */

   /* Use Win32 ConsoleIO for clearing screen */
   #include <windows.h>

   void clearscreen()
   {
      COORD coordScreen = { 0, 0 };    /* here's where we'll home the
                                        cursor */
      DWORD cCharsWritten;
      HANDLE hConsole;
      CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
      DWORD dwConSize;                 /* number of character cells in
                                          the current buffer */


      /* get a handle to StdOut */
      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

      /* get the number of character cells in the current buffer */
      GetConsoleScreenBufferInfo( hConsole, &csbi );
      dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

      /* fill the entire screen with blanks */
      FillConsoleOutputCharacter( hConsole,
                                  (TCHAR) ' ',
                                  dwConSize,
                                  coordScreen,
                                  &cCharsWritten );

      /* get the current text attribute */
      GetConsoleScreenBufferInfo( hConsole, &csbi );

      /* now set the buffer's attributes accordingly */
      FillConsoleOutputAttribute( hConsole,
                                  csbi.wAttributes,
                                  dwConSize,
                                  coordScreen,
                                  &cCharsWritten );

      /* put the cursor at (0, 0) */
      SetConsoleCursorPosition( hConsole, coordScreen );
 }

#endif /* _WIN32 */