⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screen.h

📁 自己用C编写的小游戏
💻 H
字号:
#ifndef  __BenBear_console_screen_h
#define  __BenBear_console_screen_h

#include <windows.h>

#ifndef  _CONIO_H_
enum
{
    BLACK,
    BLUE,
    GREEN,
    CYAN,
    RED,
    MAGENTA,
    BROWN,
    LIGHTGRAY,
    DARKGRAY,
    LIGHTBLUE,
    LIGHTGREEN,
    LIGHTCYAN,
    LIGHTRED,
    LIGHTMAGENTA,
    YELLOW,
    WHITE
};
#endif

int scr_window( int w, int h );
int scr_goto( int x, int y );
int scr_getx();
int scr_gety();
int scr_front( int c );
int scr_back( int c );
int scr_clrscr();

static int _front = LIGHTCYAN, _back = BLACK;
//static int _scr_x = 1, _scr_y = 1;

int scr_window( int w, int h )
{
  if( w < 1 || h < 1 )
  {
    w = 80;
    h = 25;
  }
  HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  COORD coord = { w, h };
  SetConsoleScreenBufferSize( hStdOut, coord );
  scr_goto( 1, 1 );
  return  1;
}

int scr_goto( int x, int y )
{
  COORD c;
  c.X = x - 1;
  c.Y = y - 1;
  HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  SetConsoleCursorPosition( hStdOut, c );
  return  1;
}

int scr_getx()
{
  CONSOLE_SCREEN_BUFFER_INFO info;
  HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  GetConsoleScreenBufferInfo( hStdOut, &info );
  return info.dwCursorPosition.X + 1;
}

int scr_gety()
{
  CONSOLE_SCREEN_BUFFER_INFO  info;
  HANDLE  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  GetConsoleScreenBufferInfo( hStdOut, &info );
  return  info.dwCursorPosition.Y + 1;
}

int scr_front( int c )
{
  HANDLE  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  _front = c;
  SetConsoleTextAttribute( hStdOut, c + (_back << 4) );
  return  c;
}

int scr_back( int c )
{
  HANDLE  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  _back = c;
  SetConsoleTextAttribute( hStdOut, _front + (c << 4) );
  return  c;
}

int scr_clrscr()
{
  DWORD  written;
  HANDLE  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  COORD  c = { 0, 0 };
  CONSOLE_SCREEN_BUFFER_INFO  info;
  int  length;
  GetConsoleScreenBufferInfo( hStdOut, &info );
  length = info.dwSize.X * info.dwSize.Y;
  FillConsoleOutputAttribute( hStdOut, _front + (_back << 4),
                              length, c, &written);
  FillConsoleOutputCharacter( hStdOut, ' ', length, c, &written );
  scr_goto( 1, 1 );
  return  1;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -