c/c++ 表白小程序

1.开发工具: vs  vc(任选一个)

2.准备材料 :

  a.一首音乐 (注意:音乐要求重命名为  “x”  )

  b.20张图片(注意: 图片要求重命名为  “1”  "2"   ”3“   ......"19"   "20")

3.重要的一项  :  将Unicode字符集   更改为   多字节字符集     (重中之重 千万注意)

4.先看效果程序本来是图片循环转动的,截图效果就这个样子大家凑合看着

 本来程序是图片循环转动的,但是截图出来就是这副鸟样子了,大家凑合先看着。

等下把程序自己做出来 慢慢体会程序呀的浪漫。

5.  话不多说咱们直接上代码

#include "graphics.h" //c++图形界面库
#include "stdio.h"
#include "time.h"
#include "mmsystem.h"
#pragma comment(lib,"winmm.lib")
//点
struct Point{
 int x;//x坐标
 int y;//y坐标
};
//1.定义 int x; //设x变量           IMAGE  img;
IMAGE imgBig[20];
IMAGE imgSmall[20];
//加载图片
void InitImg(){
 char buf[128] = { 0 };//字符数组
 //循环20次
 for (int i = 0; i < 20; i++){//0-19 1-20
  sprintf(buf, "images\\%d.jpg", i + 1);//格式转换
  //2.加载 scanf("%d", &x);//加载的是整数  loadimage()
  loadimage(&imgBig[i], buf, 300, 200);
  loadimage(&imgSmall[i], buf, 30, 30);
 }
}
void InitWindow(){
 //1920*1080  获取 Get 设置Set
 //使用api来获取当前窗口的宽 高
 //创建一个窗口 宽 高 单位px  像素
 initgraph(GetSystemMetrics(SM_CXSCREEN),
  GetSystemMetrics(SM_CYSCREEN));
 //获取当前窗口句柄
 HWND hwnd = GetHWnd();
 //设置窗口风格 减去窗口标题
 SetWindowLong(hwnd, GWL_STYLE,
  GetWindowLong(hwnd, GWL_STYLE) - WS_CAPTION);
 //设置窗口的起始点  默认风格
 SetWindowPos(hwnd, HWND_TOPMOST, 450, 150, GetSystemMetrics(SM_CXSCREEN),
  GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW);
 //拿到我背面的窗口风格
 LONG WindowLong = GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED;
 //设置窗口风格
 SetWindowLong(hwnd, GWL_EXSTYLE, WindowLong);
 //把黑色的背景设置为透明
 SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
}

int main(){
 //创建一个窗口
 //2个参数 宽 高
 //initgraph(800,800);//单位px 像素
 InitWindow();
 //open 打开这首歌
 mciSendString("open x.mp3", 0, 0, 0);
 //play 播放音乐
 mciSendString("play x.mp3", 0, 0, 0);
 //创建结构体数组
 Point arr[46] = {
  { 395, 268 },
  { 406, 222 },
  { 416, 193 },
  { 441, 162 },
  { 468, 133 },
  { 500, 117 },
  { 537, 105 },
  { 577, 107 },
  { 617, 120 },
  { 649, 146 },
  { 666, 173 },
  { 680, 211 },
  { 683, 247 },
  { 680, 293 },
  { 675, 338 },
  { 660, 385 },
  { 640, 440 },
  { 616, 484 },
  { 588, 529 },
  { 557, 573 },
  { 530, 610 },
  { 493, 645 },
  { 460, 675 },
  { 422, 696 },
  { 381, 676 },
  { 350, 654 },
  { 320, 626 },
  { 292, 606 },
  { 257, 570 },
  { 230, 540 },
  { 200, 500 },
  { 180, 470 },
  { 160, 430 },
  { 140, 390 },
  { 126, 342 },
  { 117, 293 },
  { 120, 250 },
  { 133, 203 },
  { 160, 170 },
  { 200, 140 },
  { 240, 130 },
  { 280, 135 },
  { 312, 146 },
  { 340, 170 },
  { 360, 195 },
  { 375, 230 }
 };
 char buff[46][50] = {
  "一封信",
  "两年未都",
  "没动笔",
  "三个字",
  "过了",
  "几个四季",
  "你是有",
  "多想逃避",
  "来不及",
  "问问你",
  "我已经",
  "错过",
  "相爱",
  "的日期",
  "那天你",
  "消失在",
  "人海里",
  "你的背影",
  "沉默的",
  "让人恐惧",
  "你说的",
  "那些问题",
  "我回答得",
  "很坚定",
  "偏偏",
  "那个时候",
  "我最想你",
  "我不曾",
  "爱过你",
  "我自己",
  "骗自己",
  "已经给你",
  "写了信",
  "又被我",
  "丢进海里",
  "我不曾",
  "爱过你",
  "我自己",
  "骗自己",
  "明明觉得",
  "自己",
  "很冷静",
  "却还",
  "掉入",
  "我自己",
  "的陷阱"
 };
 //通过时间做随机数的种子
 srand((unsigned)time(NULL));
 //如何在窗口显示文字 
 //编程  和计算机做交互 显示
 //printf
 InitImg();
 //for (int i = 0; i < 20; i++)
 //{
 // //3.显示 printf("%d\n", x);//显示整数    putimage()
 // putimage(0, 0, &img[i]);//图片在窗口显示的位置
 // Sleep(1000);//格式化输出
 //}
 //out输出 text文本 xy位置
 //在窗口对应的位置输出文本
 //outtextxy(0,0,"Hello,World!");
 //简单的绘图
 for (int i = 0; i < 46; i++){
  //设置颜色
  settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
  //i 0-45
  //outtextxy(arr[i].x, arr[i].y,buff[i]);
  putimage(arr[i].x, arr[i].y, &imgSmall[i % 20]);
  Sleep(80);
 }
 /*MOUSEMSG m;
 while (1){
 m = GetMouseMsg();
 if (m.uMsg == WM_LBUTTONDOWN){
 printf("X:%d,Y:%d\n", m.x, m.y);
 }
 }*/
 int add = 0;
 while (1){
  //清除设备
  cleardevice();
  for (int i = 0; i < 46; i++){
   //设置颜色
   //settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
   //i 0-45
   //outtextxy(arr[i].x, arr[i].y, buff[(i+add)%46]);
   putimage(arr[i].x, arr[i].y, &imgSmall[(i + add) % 20]);
  }
  //ctrl +k  ctrl+c 注释  20张  0-19 rand%20  0-19
  //ctrl +k  ctrl+u 取消注释
  putimage(257, 308, &imgBig[add % 20]);
  add++;
  Sleep(1000);
 }
 //然文字动
 system("pause");//暂停
 return 0;
}
 
 
6.代码说多也多  说不多他也就200来行   希望大家可以用我的程序找到你的伴侣
那我就很开心了。
祝大家好运吧!

猜你喜欢

转载自www.cnblogs.com/wangleiiot/p/10392373.html