一:前言
sb是鼠标的意思,可不是某些……
二:定义某些常量
const int sb_z=VK_LBUTTON,sb_y=VK_RBUTTON;
三:移动光标
移动光标是在编译框里面把光标移动到某些地方,这种方法可以是制作游戏时不闪屏
代码:
void ydgb(int x,int y) {
COORD pos={y-1,x-1};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
}
引用的时候只要:ydgb();里面加上你要移动的坐标(先行后列)
四:鼠标位置
使用这个函数前要先定义hl的结构体,如下:
struct hl{
int h;
int l;
};
然后剩下的代码:
hl sbwz(){
hl hl;
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
HWND h=GetForegroundWindow();
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
hl.h=p.x/consoleCurrentFont.dwFontSize.X;
hl.l=p.y/consoleCurrentFont.dwFontSize.Y;
return hl;
}
五:隐藏光标
代码:
void ycgb(){
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut,&cciCursor)) {
cciCursor.bVisible=FALSE;
SetConsoleCursorInfo(hStdOut,&cciCursor);
}
return;
}
六:移除编辑
移除快速编辑模式,对于win10用户
void ycgb(){
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut,&cciCursor)) {
cciCursor.bVisible=FALSE;
SetConsoleCursorInfo(hStdOut,&cciCursor);
}
return;
}
七:代码整合
#include<bits/stdc++.h>//输入输出用的
#include<ctime>//计算时间用的 colok()
#include<conio.h>//_getch()用的
#include<fstream>//存档用的
#include<windows.h>//SLeep等函数
using namespace std;
namespace _game_sb
{
const int sb_z=VK_LBUTTON,sb_y=VK_RBUTTON;
struct hl{
int h;
int l;
};
void ycgb(){
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut,&cciCursor)) {
cciCursor.bVisible=FALSE;
SetConsoleCursorInfo(hStdOut,&cciCursor);
}
return;
}
void ycbj(){
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode &=~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin, mode);
return;
}
void ydgb(int x,int y) {
COORD pos={y-1,x-1};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
}
hl sbwz(){
hl hl;
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
HWND h=GetForegroundWindow();
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
hl.h=p.x/consoleCurrentFont.dwFontSize.X;
hl.l=p.y/consoleCurrentFont.dwFontSize.Y;
return hl;
}
}
using namespace _game_sb;
int main()
{
return 0;
}