?? common.cpp
字號:
#include "Common.h"
void ClearBuffer(int x,int y,int w,int h,int color)
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD rd;
DWORD n;
WORD cs[2] = { color, color };
for(int i=x;i<w+x;i++)
{
for(int j=y;j<h+y;j++)
{
rd.X = i;rd.Y = j;
WriteConsoleOutputCharacterA(hOut," ",1,rd,&n);
WriteConsoleOutputAttribute(hOut, cs, 1, rd, &n );
}
}
DeleteObject(hOut);
}
void SetConsoleInfo()
{
// 設(shè)置控制臺(tái)的標(biāo)題
SetConsoleTitleA("俄羅斯方塊");
// 獲取控制臺(tái)的句柄
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor = {1,false};
// 設(shè)置控制臺(tái)光標(biāo)的屬性
SetConsoleCursorInfo(hOut,&cursor);
SMALL_RECT rect = {0,0,WIDTH-1,HEIGHT-1};
// 設(shè)置窗口大小
SetConsoleWindowInfo(hOut,TRUE,&rect);
COORD rd = {WIDTH,HEIGHT};
// 設(shè)置控制臺(tái)緩沖區(qū)大小
SetConsoleScreenBufferSize(hOut,rd);
DeleteObject(hOut);
}
//x,y為文本輸出坐標(biāo),color為文本顏色,str為文本字符串
void DrawText( short x, short y, WORD color,const char* str )//設(shè)置輸出文本函數(shù)
{
HANDLE hStd = GetStdHandle(STD_OUTPUT_HANDLE); // 獲得輸出句柄
DWORD n;
COORD pos = {x,y}; // 文本輸出坐標(biāo)
WORD cs[2] = { color, color }; // 顏色
for( const char* p=str;*p!=0; )
{
if( *p > 0 ) //輸出單字節(jié)字符
{
WriteConsoleOutputCharacterA(hStd, p, 1, pos, &n );
WriteConsoleOutputAttribute(hStd, cs, 1, pos, &n );
++p,++pos.X;
}
else //輸出雙字節(jié)字符
{
WriteConsoleOutputCharacterA(hStd, p, 2, pos, &n );
WriteConsoleOutputAttribute(hStd, cs, 2, pos, &n );
p+=2,pos.X+=2;
}
}
DeleteObject(hStd);
}
// x y左上的坐標(biāo) 框內(nèi)寬w(單字節(jié)) 框內(nèi)高h(yuǎn)
void DrawFrame(int x,int y,int w,int h,int color)
{
for(int i=y-1;i<y+h;i++)
{
DrawText(x,i,color,"┃");
DrawText(x+w+2,i,color,"┃");
}
for(int i=x+2;i<=x+w;i+=2)
{
DrawText(i,y,color,"━");
DrawText(i,y+h,color,"━");
}
DrawText(x,y,color,"┏");
DrawText(x+w+2,y,color,"┓");
DrawText(x,y+h,color,"┗");
DrawText(x+w+2,y+h,color,"┛");
}
void readbufchar(int x,int y,char* c,WORD* cs)//讀取窗口緩沖區(qū)的<x,y>的字符
{
DWORD l=2;
COORD pos = {x,y};
HANDLE hStd = GetStdHandle(STD_OUTPUT_HANDLE);// 獲得輸出句柄
ReadConsoleOutputCharacterA(hStd,c,l,pos,&l);
if(cs)
{
ReadConsoleOutputAttribute(hStd,cs,l,pos,&l);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -