零基础学习C语言可视化编程
1.图形化窗口
1.1 图形窗口基本框架
第1步 安装插件
第2步 基本框架
#include
#include
int main()
{
//(width,height)
initgraph(640, 450)
closegraph();
return 0;
}
1.2 坐标系统
2.文字输出
2.1 字符串输出
#include
#include
int main()
{
//(width,height)
initgraph(640, 450);
//outextxy(x,y,"字符串")
outtextxy(100, 100, "莫影最帅");
getchar();
closegraph();
return 0;
}
2.2 实数类输出
error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include
#include
int main()
{
//(width,height)
initgraph(640, 450);
//outextxy(x,y,"字符串")
//转换:实数类转换为字符串
char str[20] = "";
int i_number = 1;
//printf
sprintf(str, "%d", i_number);
outtextxy(100, 100, str);
getchar();
closegraph();
return 0;
}
3.绘图函数--->五子棋
#include
#include
/*
贴图:int float double FILE
IMAGE
1.定义一个照片变量
IMAGE MM;
2.加载资源到变量
loadimage(&MM,"图片路径");
3.贴图
putimage(int x,int y,&MM);
*/
int main()
{
initgraph(600, 450);
IMAGE MM;
//函数调用
loadimage(&MM, "美女.jpg");
putimage(0, 0, &MM);
getchar();
closegraph();
return 0;
}
#include
#include
int main()
{
initgraph(1023, 548);
IMAGE background;
loadimage(&background, "gamebackground.jpg");
putimage(0, 0, &background);
setlinecolor(BLACK);
for (int i = 10; i <= 530; i += 20)
{
line(10, i, 530, i);
line(i,10, i, 530);
}
//加粗
setlinestyle(PS_SOLID, 4);
rectangle(10, 10, 530, 530);
getchar();
closegraph();
return 0;
}
4.贴图函数--->学生管理系统
#include
#include
int main()
{
initgraph(600, 400);
IMAGE background;
IMAGE menu;
loadimage(&background, "bkimage.jpg",600,400);
loadimage(&menu, "image.jpg",200,50);
putimage(0, 0, &background);
for (int i = 0; i < 4; i++)
{
putimage(200, 80 + i * 50, &menu);
}
settextcolor(BLACK);
setbkmode(TRANSPARENT);
settextstyle(25, 0, "黑体");
outtextxy(100, 20, "莫影老师的后宫管理系统 v1.0版本");
outtextxy(250, 95, "xxxx");
outtextxy(250, 145, "xxxxx");
outtextxy(250, 195, "xxxxx");
outtextxy(250, 245, "xxxxx");
getchar();
closegraph();
return 0;
}
5.鼠标操作--->鼠标位置
MOUSEMSG 种类
#define _CRT_SECURE_NO_WARNINGS
#include
#include
/*
鼠标:
定义鼠标变量:
MOUSEMSG m;
初始化鼠标消息变量
m=GetMouseMsg();
分类处理消息
if_else
switch(m.uMsg)
{
case WM_LBUTTONDOWN:
break;
case WM_RBUTTONDOWN:
break;
case WM_MOUSEMOVE:
break;
}
*/
int main()
{
initgraph(600, 450);
while (1)
{
MOUSEMSG m = GetMouseMsg();
switch (m.uMsg)
{
case WM_LBUTTONDOWN:
circle(m.x, m.y, 4);
break;
case WM_RBUTTONDOWN:
rectangle(m.x - 4, m.y -4, m.x + 4, m.y + 4);
break;
case WM_MOUSEMOVE:
char str[20] = "";
sprintf(str, "(%d,%d)", m.x, m.y);
outtextxy(0,0,str);
break;
}
}
closegraph();
return 0;
}
大学习惯:三个抄,抄作业,抄考试,抄毕业
缺少思维,思考,弯路走的太少.没有培养自己的编程思维
视频教程