我找了一些有用的控制台功能,组合在了一起。
成了:
// <cgame> -*- C++ -*-
//No Copyright.
// This is a C++ Library header.
#ifndef game6
#define game6
#include<windows.h>
#include<iostream>
#include<fstream>
namespace game6
{
/* DO NOT EDIT ! */
#define gFILE_VERSION "1.0.1.0"
#define gFILE_DESCRIPTION "Developed using the Dev-C++ IDE"
#define gLEGAL_COPYRIGHT "None"
#define gORIGINAL_FILENAME "cgame"
#define gPRODUCT_VERSION "1.0.1.0"
void hidew(){ShowWindow(GetConsoleWindow(),SW_HIDE);}
void seenw(){ShowWindow(GetConsoleWindow(),SW_SHOW);}
void goxy(int x, int y){SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),{x,y});}
void hidecur(){
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void movewin(){
RECT rect;
HWND hwnd = GetForegroundWindow();
GetWindowRect(hwnd, &rect);
MoveWindow(GetForegroundWindow(),0,0,0,0,1);
}
void wintop(std::string n)//标题
{
std::string t = "title ";
t += n;
system(&t[0]);
}
void color(int a,int b){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a+b*0x10);}
void top()//将置顶与不置顶来回更换
{
HWND hWnd = ::GetForegroundWindow();
if (::GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)::SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
else::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
void wsize(short h,short l)//windows size
{
std::string n="mode con cols=",t="";
while(l>0)
{
t+=char(l%10+'0');
l/=10;
}
for(int i=t.size()-1;i>=0;i--)n+=t[i];
n+=" lines=",t="";
while(h>0)
{
t=t+char(h%10+'0');
h/=10;
}
for(int i=t.size()-1;i>=0;i--)n+=t[i];
system(&n[0]);
return;
}
void nomode()//移除快速编辑模式
{
DWORD mode;
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),&mode);
mode&=~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),mode);
return;
}
void hcur()//隐藏光标
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible=FALSE;
cursor.dwSize=sizeof(cursor);
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor);
}
void movecur(long long h, long long l){SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),{l-1,h-1});}
void out(int n, std::string name)//参考饼干369
{
std::ofstream cd(&name[0]);
cd << n;
cd.close();
return;
}
void out(long long n, std::string name)
{
std::ofstream cd(&name[0]);
cd << n;
cd.close();
return;
}
void out(bool n, std::string name)
{
std::ofstream cd(&name[0]);
cd << n;
cd.close();
return;
}
void out(char n, std::string name)
{
std::ofstream cd(&name[0]);
cd << n;
cd.close();
return;
}
void out(std::string n, std::string name)
{
std::ofstream cd(&name[0]);
cd << n;
cd.close();
return;
}
void in(int& n, std::string name)
{
std::ifstream cd(&name[0]);
cd >> n;
cd.close();
return;
}
void in(long long& n, std::string name)
{
std::ifstream cd(&name[0]);
cd >> n;
cd.close();
return;
}
void in(bool& n, std::string name)
{
std::ifstream cd(&name[0]);
cd >> n;
cd.close();
return;
}
void in(char& n, std::string name)
{
std::ifstream cd(&name[0]);
cd >> n;
cd.close();
return;
}
void in(std::string& n, std::string name)//参考饼干369
{
std::ifstream cd(&name[0]);
cd >> n;
cd.close();
return;
}
struct hl//行列
{
long long h, l;
};
hl where(bool x = 1, bool n = 1)//鼠标位置
{
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h = GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
hl hl;
POINT p;
if (x)
{
GetCursorPos(&p);
ScreenToClient(h, &p);
}
else
{
GetCursorPos(&p);
}
if (n)
{
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
p.x /= consoleCurrentFont.dwFontSize.X;
p.y /= consoleCurrentFont.dwFontSize.Y;
}
hl.h = p.y + 1;
hl.l = p.x + 1;
return hl;
}
}
#endif
(部分来自饼干369)
该代码定义了一个C++库,包含了一系列控制台功能,如隐藏/显示控制台,设置光标位置,改变窗口大小,窗口置顶,颜色设定,以及文件的输入输出操作。此外,还提供了获取鼠标位置的功能。

被折叠的 条评论
为什么被折叠?



