8月4号 easyx学习笔记

2022/8/4 23:26:02

本文主要是介绍8月4号 easyx学习笔记,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#include<stdio.h>
#include<graphics.h>
#include<conio.h>//使用_getch()
#include<mmsystem.h>//包含多媒体设备接口头文件
#pragma comment(lib,"winmm.lib")//加载静态库
//int main()
//{
// //创建一个窗口,设置窗口大小
// initgraph(800, 800,SHOWCONSOLE);
// //initgraph(680, 480,SHOWCONSOLE|NOCLOSE|NOMINIMIZE);
//
//
// //setbkcolor(WHITE);//设置背景颜色
// //cleardevice();//清屏
// //setlinestyle(PS_SOLID,1);
// //setfillcolor(YELLOW);//设置填充颜色
// //setlinecolor(BLUE);//设置线条颜色
// //circle(50, 50, 50);
// //fillcircle(50, 150, 50);
// //solidcircle(50, 250, 50);
// ////设置文字颜色
// //settextcolor(RED);
// ////设置文字样式 大小,字体
// //settextstyle(20, 0, "楷体");
// ////设置背景模式 TRANSPARENT透明的
// //setbkmode(TRANSPARENT);
// //settextcolor(RGB(0, 128, 99));//设置文字颜色
// ////绘制文字(字符串的三种解决方案)L TEXT() 项目、属性、字符集、多字节字符集
// //outtextxy(50, 50, "你好,easyx");
//
// ////文字居中
// //fillrectangle(200, 50, 500, 150);
// //char array[] = "文字居中";
// //int width = 300/2-textwidth(array)/2;
// //int height = 100 / 2 - textheight(array) / 2;
// //outtextxy(200+width, 50+height, array);
//
// //输出图片
// IMAGE img;//定义一个(变量)对象
// loadimage(&img,"./1.jpg",800,800);
// putimage(0,0 , &img);
// getchar();
// //关闭窗口
// closegraph();
// return 0;
//}
void button(int x, int y, int w, int h, const char* text) {
setbkmode(TRANSPARENT);
setfillcolor(BROWN);
fillroundrect(x, y, x + w, y + h,10,10);
settextstyle(30, 0, "楷体");
int tx = x + (w - textwidth(text))/2;
int ty = y + (y - textheight(text))/2;
outtextxy(tx, ty, text);
}
void BGM() {
int a, b;
//打开音乐,播放音乐,alias取别名 repeat重复播放
/*mciSendString("open ./music2.mp3", 0, 0, 0);
mciSendString("play ./music2.mp3", 0, 0, 0);*/
a=mciSendString("open ./music3(V0).mp3 alias BGM ", 0, 0, 0);
b=mciSendString("play BGM ", 0, 0, 0);
printf("%d %d", a, b);
if (0) {
mciSendString("close BGM", 0, 0, 0);//关闭音乐
}
}void change() {
//获取窗口句柄
HWND hnd = GetHWnd();
//设置窗口标题
SetWindowText(hnd, "C语言easyx");
//弹出窗口,提示用户操作
//MessageBox(NULL,"Hello World!","Hello",MB_OKCANCEL);
int isok=MessageBox(hnd,"Hello World!","Hello",MB_OKCANCEL);
printf("%d\n", isok);
if (isok == IDOK) {
printf("你点击了OK\n");
}
else if (isok == IDCANCEL) {
printf("你点击了取消\n");
}
}
int main()
{
initgraph(800, 800, EW_SHOWCONSOLE);
// BGM();
// button(200, 50, 200, 50, "按钮");
change();
ExMessage msg;
int x = 0, y = 0;
while(true)
{
BeginBatchDraw();//开始批量绘图
cleardevice();
button(200, 50, 200, 50, "按钮");
setfillcolor(BROWN);
fillcircle(x,y,20);
EndBatchDraw();//结束批量绘图
//键盘操作
if (GetAsyncKeyState(VK_UP)) {
printf("上键\n");
y -= 1;
}
if (GetAsyncKeyState(VK_DOWN)) {
printf("下键\n");
y += 1;
}
if (GetAsyncKeyState(VK_LEFT)) {
printf("左键\n");
x -= 1;
}
if (GetAsyncKeyState(VK_RIGHT)) {
printf("右键\n");
x += 1;
}
/*if (_kbhit()) {//判断有没有键盘按下
char key = _getch();
switch (key)
{
case 72:
case 'w':
printf("上键\n");
y -= 5;
break;
case 80:
case 's':
printf("下键\n");
y += 5;
break;
case 75:
case 'a':
printf("左键\n");
x -= 5;
break;
case 77:
case 'd':
printf("右键\n");
x += 5;
break;
}
}*/
//鼠标消息
if (peekmessage(&msg, EM_MOUSE)) {
switch (msg.message)
{
case WM_LBUTTONDOWN:
if (msg.x >= 200 && msg.x <= 400 && msg.y >= 50 && msg.y <= 100) {
printf("按钮被点击了一下\n");
}
break;
default:
break;
}
}
}
getchar();
closegraph();
return 0;
}

搜索

复制



这篇关于8月4号 easyx学习笔记的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程