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來行   希望大家可以用我的程序找到你的伴侶
那我就很開心了。
祝大家好運吧!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM