一个自己写的头文件包装-windowset.h-1.0

知识共享许可协议 版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons

windowset.h

//简单窗口设置函数
#ifndef _WINDOWSSET_
#define _WINDOWSSET_
#include<Windows.h>
#include<iostream>
#include <crtdefs.h>
#include <conio.h>
#include "draw.h"
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
//------------
void modeset(int w,int h);	//设置窗口大小
void pause(void);			//无回显暂停
void GetPos(POINT &pt);		//获得当前控制台鼠标坐标 
void color(int a);			//修改当前控制台颜色
void gto(int x,int y);		//设置当前控制台光标到x行y列
//------------
void modeset(int w,int h) {
//	设置窗口大小为 w*h
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD size = {w, h};
	SetConsoleScreenBufferSize(hOut,size);
	SMALL_RECT rc = {1,1, w, h};
	SetConsoleWindowInfo(hOut ,true ,&rc);
	Sleep(10);
	return;
}
void pause(void) {
	std::cout<<"请按任意键继续. . .";
	getch();
	std::cout<<"\r                      \r";
	return;
}
void GetPos(POINT &pt) {
	HWND hwnd=GetForegroundWindow();
	GetCursorPos(&pt);
	ScreenToClient(hwnd,&pt);
	pt.y=pt.y/16,pt.x=pt.x/8;
}
void color(int a) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gto(int x,int y) {
	COORD pos;
	pos.X=y;
	pos.Y=x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
#endif

一个实用的头文件
依赖另外一个自己编写的头文件draw.h
可以点击我的头像去我的文章里找

猜你喜欢

转载自blog.csdn.net/yuanwow/article/details/94206600