加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

几个简单的windows API

发布时间:2020-12-14 02:28:23 所属栏目:Windows 来源:网络整理
导读://将光标移动到x,y位置 void gotoxy(int x,int y) { COORD c; c.X = x; c.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c); } //设置窗口颜色 用到两个Windows API 不做详细介绍 void setColor(unsigned short ForeColor = 7,unsigned

//将光标移动到x,y位置
void gotoxy(int x,int y)
{
COORD c;
c.X = x; c.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}

//设置窗口颜色 用到两个Windows API 不做详细介绍
void setColor(unsigned short ForeColor = 7,unsigned short BackGroundColor = 0)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);//获取当前窗口句柄
SetConsoleTextAttribute(handle,ForeColor + BackGroundColor * 0x10);//设置颜色
}

//获取键盘输入

void listen_key_borad()
{
char ch;

if (_kbhit()) //kbhit 非阻塞函数 { ch = _getch(); //使用 getch 函数获取键盘输入 switch (ch) { case ‘w‘: case ‘W‘: if (this->m_direction == DOWN) break; this->m_direction = UP; break; case ‘s‘: case ‘S‘: if (this->m_direction == UP) break; this->m_direction = DOWN; break; case ‘a‘: case ‘A‘: if (this->m_direction == RIGHT) break; this->m_direction = LEFT; break; case ‘d‘: case ‘D‘: if (this->m_direction == LEFT) break; this->m_direction = RIGHT; break; case ‘+‘: if (speed >= 25) { speed -= 25; } break; case ‘-‘: if (speed < 250) { speed += 25; } break; } } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读