VC中文網-VC-MFC編程論壇

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

查看: 491|回復: 0
打印 上一主題 下一主題

C語言打造表白程序——教你做一個浪漫的程序員

[復制鏈接]

34

主題

35

帖子

113

金幣

連長

Rank: 7Rank: 7Rank: 7

積分
135

社區QQ達人新兵愛心論壇帥哥

跳轉到指定樓層
樓主
發表于 2020-2-3 22:42:08 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

這個程序的知識點如下: MFC GDI API

1.

Microsoft Foundation Classes

Graphics Device Interface

Application Programming Interface

MFC 是微軟公司的基礎類庫,封裝了大量的Windows API函數,能夠快速的開發一些桌面應用程序, GDI是圖形設備接口,程序員專門用來坐圖形繪制功能的。 基本上要做軟件 這些東西都是缺一不可的

在學習中有迷茫不知如何學習的朋友小編推薦一個學c/c++的學習裙 六四三;三九二;二二零;無論你是大牛還是小白,是想轉行還是想入行都可以來了解一起進步一起學習!內有開發工具,很多干貨和技術資料分享

C語言打造表白程序——教你怎樣做一個浪漫的程序員,程序員都是這么追女朋友的,隨便寫個程序就能搞定,嗨呀!

接下來我就分享下我寫的這個程序的源代碼 ,供參考!

希望大家能寫出自己的程序去追女朋友,如果我有寫的不好的地方往大神指出,我改進。



廢話不多說 直接上代碼:

// MFCApplication2Dlg.cpp : 實現文件

//

#include "stdafx.h"

#include "MFCApplication2.h"

#include "MFCApplication2Dlg.h"

#include "afxdialogex.h"

#include "mmsystem.h"

#include "Resource.h"

#pragma comment(lib,"winmm.lib")

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

// 用于應用程序“關于”菜單項的 CAboutDlg 對話框

class CAboutDlg : public CDialogEx

{

public:

CAboutDlg();

// 對話框數據

enum { IDD = IDD_ABOUTBOX };

protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

// 實現

protected:

DECLARE_MESSAGE_MAP()

};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)

{

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialogEx::DoDataExchange(pDX);

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)

END_MESSAGE_MAP()

// CMFCApplication2Dlg 對話框

CMFCApplication2Dlg::CMFCApplication2Dlg(CWnd* pParent /*=NULL*/)

: CDialogEx(CMFCApplication2Dlg::IDD, pParent)

{

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CMFCApplication2Dlg::DoDataExchange(CDataExchange* pDX)

{

CDialogEx::DoDataExchange(pDX);

}

BEGIN_MESSAGE_MAP(CMFCApplication2Dlg, CDialogEx)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTTON_TEST, &CMFCApplication2Dlg::OnBnClickedButtonTest)

END_MESSAGE_MAP()

// CMFCApplication2Dlg 消息處理程序

BOOL CMFCApplication2Dlg::OnInitDialog()

{

CDialogEx::OnInitDialog();

// 將“關于...”菜單項添加到系統菜單中。

// IDM_ABOUTBOX 必須在系統命令范圍內。

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

BOOL bNameValid;

CString strAboutMenu;

bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);

ASSERT(bNameValid);

if (!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}

}

// 設置此對話框的圖標。 當應用程序主窗口不是對話框時,框架將自動

// 執行此操作

SetIcon(m_hIcon, TRUE);// 設置大圖標

SetIcon(m_hIcon, FALSE);// 設置小圖標

// TODO: 在此添加額外的初始化代碼

return TRUE; // 除非將焦點設置到控件,否則返回 TRUE

}

void CMFCApplication2Dlg::OnSysCommand(UINT nID, LPARAM lParam)

{

if ((nID & 0xFFF0) == IDM_ABOUTBOX)

{

CAboutDlg dlgAbout;

dlgAbout.DoModal();

}

else

{

CDialogEx::OnSysCommand(nID, lParam);

}

}

// 如果向對話框添加最小化按鈕,則需要下面的代碼

// 來繪制該圖標。 對于使用文檔/視圖模型的 MFC 應用程序,

// 這將由框架自動完成。

void CMFCApplication2Dlg::OnPaint()

{

if (IsIconic())

{

CPaintDC dc(this); // 用于繪制的設備上下文

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// 使圖標在工作區矩形中居中

int cxIcon = GetSystemMetrics(SM_CXICON);

int cyIcon = GetSystemMetrics(SM_CYICON);

CRect rect;

GetClientRect(&rect);

int x = (rect.Width() - cxIcon + 1) / 2;

int y = (rect.Height() - cyIcon + 1) / 2;

// 繪制圖標

dc.DrawIcon(x, y, m_hIcon);

}

else

{

CDialogEx::OnPaint();

}

}

//當用戶拖動最小化窗口時系統調用此函數取得光標

//顯示。

HCURSOR CMFCApplication2Dlg::OnQueryDragIcon()

{

return static_cast<HCURSOR>(m_hIcon);

}

BOOL g_bStop = FALSE;

BOOL PaintFlower(int x, int y)

{

// 獲取桌面的繪圖設備并創建兼容設備

HWND hDesk = ::GetDesktopWindow();

HDC hDC = ::GetDC(hDesk);

HDC hMD = ::CreateCompatibleDC(hDC);

HDC hBuf = ::CreateCompatibleDC(hDC);

// 獲取桌面寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

// 加載位圖資源

HBITMAP tempbmp, oldtempbmp, bmp, oldbmp;

tempbmp = ::CreateCompatibleBitmap(hDC, dwWidth, dwHeight);

bmp = (HBITMAP)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_FLOWERS), IMAGE_BITMAP, 0, 0, NULL);

// 選中資源

oldtempbmp = (HBITMAP)::SelectObject(hMD, tempbmp);

oldbmp = (HBITMAP)::SelectObject(hBuf, bmp);

// 復制一遍桌面

::BitBlt(hMD, 0, 0, dwWidth, dwHeight, hDC, 0, 0, SRCCOPY);

// 使用雙緩沖的,繪制透明位圖

// 先 and 再 or

::BitBlt(hMD, x, y, 100, 100, hBuf, 0, 0, SRCAND);

::BitBlt(hMD, x, y, 100, 100, hBuf, 0, 100, SRCPAINT);

// 繪制到桌面

::BitBlt(hDC, 0, 0, dwWidth, dwHeight, hMD, 0, 0, SRCCOPY);

::SelectObject(hBuf, oldbmp);

::SelectObject(hMD, oldtempbmp);

// 釋放內存

::DeleteObject(tempbmp);

::DeleteDC(hBuf);

::DeleteDC(hMD);

::ReleaseDC(hDesk, hDC);

return TRUE;

}

int CMFCApplication2Dlg::ShowMyFlower0(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

srand((unsigned int)time(NULL));

// 獲取桌面屏幕的寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

DWORD m = dwWidth / 30, n = dwHeight / 30;

DWORD x = 0, y = 0;

DWORD i = 0;

// 繪制網格的點 599 朵

i = 999;

do

{

if (g_bStop)

{

return 0;

}

x = rand() % m;

y = rand() % n;

PaintFlower(30 * x, 30 * y);

i--;

Sleep(50);

} while (0 <= i);

return 0;

}

int CMFCApplication2Dlg::ShowMyFlower1(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

// 獲取桌面屏幕的寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

DWORD m = dwWidth / 30, n = dwHeight / 30;

DWORD x = 0, y = 0;

DWORD i = 0;

// 隨機 400 朵

i = 999;

do

{

if (g_bStop)

{

return 0;

}

x = rand() % m;

y = rand() % n;

PaintFlower(30 * x, 30 * y);

i--;

Sleep(50);

} while (0 <= i);

return 0;

}

//畫x軸方向的花

int CMFCApplication2Dlg::ShowMyFlower2(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

/*Sleep(500);*/

// 獲取桌面屏幕的寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

DWORD i = 0;

// 順時針顯示

while (TRUE)

{

for (i = 0; i < dwWidth - 50; i = i + 60)

{

PaintFlower(i, 0);

Sleep(300);

}

for (i = 0; i < dwHeight - 50; i = i + 60)

{

PaintFlower(dwWidth - 100, i);

Sleep(300);

}

}

/*

for(i = dwWidth - 100; i >= 50; i = i - 60)

{

PaintFlower(i, dwHeight - 100);

Sleep(300);

}

for(i = dwHeight - 100; i >= 50 ; i = i - 60)

{

PaintFlower(0, i);

Sleep(300);

}

*/

return 0;

}

int CMFCApplication2Dlg::ShowMyFlower3(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

//Sleep(1000);

// 獲取桌面屏幕的寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

DWORD i = 0;

while (TRUE)

{

for (i = dwWidth - 100; i >= 50; i = i - 60)

{

PaintFlower(i, dwHeight - 100);

Sleep(300);

}

for (i = dwHeight - 100; i >= 50; i = i - 60)

{

PaintFlower(0, i);

Sleep(300);

}

}

return 0;

}

int CMFCApplication2Dlg::ShowMyFlower4(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

//Sleep(12000);

HWND hDesk = ::GetDesktopWindow();

HDC hDC = ::GetDC(hDesk);

HDC hMD = ::CreateCompatibleDC(hDC);

HDC hBuf = ::CreateCompatibleDC(hDC);

// 獲取桌面寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

// 計算繪制的位置

int x = (dwWidth - 400) / 2;

int y = 110;

// 加載位圖資源

HBITMAP tempbmp, oldtempbmp, bmp, oldbmp;

tempbmp = ::CreateCompatibleBitmap(hDC, dwWidth, dwHeight);

//GetModuleHandle是獲取一個應用程序或動態鏈接庫的模塊句柄

bmp = (HBITMAP)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_520), IMAGE_BITMAP, 0, 0, NULL);

// 選中資源

oldtempbmp = (HBITMAP)::SelectObject(hMD, tempbmp);

oldbmp = (HBITMAP)::SelectObject(hBuf, bmp);

DWORD i = 0, j = 0;

while (TRUE)

{

for (i = 0; i < 4; i++)

{

// 復制一遍桌面

::BitBlt(hMD, 0, 0, dwWidth, dwHeight, hDC, 0, 0, SRCCOPY);

// 使用雙緩沖的,繪制透明位圖

// 先 and 再 or

::BitBlt(hMD, x, y, 400, 150, hBuf, 0, 0, SRCAND);

::BitBlt(hMD, x, y, 400, 150, hBuf, 0, 150 * (1 + i), SRCPAINT);

// 繪制到桌面

::BitBlt(hDC, 0, 0, dwWidth, dwHeight, hMD, 0, 0, SRCCOPY);

Sleep(300);

}

for (j = 2; j > 0; j--)

{

// 復制一遍桌面

::BitBlt(hMD, 0, 0, dwWidth, dwHeight, hDC, 0, 0, SRCCOPY);

// 使用雙緩沖的,繪制透明位圖

// 先 and 再 or

::BitBlt(hMD, x, y, 400, 150, hBuf, 0, 0, SRCAND);

::BitBlt(hMD, x, y, 400, 150, hBuf, 0, 150 * (1 + j), SRCPAINT);

// 繪制到桌面

::BitBlt(hDC, 0, 0, dwWidth, dwHeight, hMD, 0, 0, SRCCOPY);

Sleep(300);

}

}

::SelectObject(hBuf, oldbmp);

::SelectObject(hMD, oldtempbmp);

// 釋放內存

::DeleteObject(tempbmp);

::DeleteDC(hBuf);

::DeleteDC(hMD);

::ReleaseDC(hDesk, hDC);

return 0;

}

int CMFCApplication2Dlg::ShowMyFlower5(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

//Sleep(15000);

HWND hDesk = ::GetDesktopWindow();

HDC hDC = ::GetDC(hDesk);

HDC hMD = ::CreateCompatibleDC(hDC);

HDC hBuf = ::CreateCompatibleDC(hDC);

HDC hBuf2 = ::CreateCompatibleDC(hDC);

// 獲取桌面寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

// 計算繪制的位置

int x = (dwWidth - 700) / 2;

int y = 260;

// 加載位圖資源

HBITMAP tempbmp, oldtempbmp, bmp, oldbmp, bmp2, oldbmp2;

tempbmp = ::CreateCompatibleBitmap(hDC, dwWidth, dwHeight);

bmp = (HBITMAP)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LOVE), IMAGE_BITMAP, 0, 0, NULL);

bmp2 = (HBITMAP)::LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_LOVE2), IMAGE_BITMAP, 0, 0, NULL);

// 選中資源

oldtempbmp = (HBITMAP)::SelectObject(hMD, tempbmp);

oldbmp = (HBITMAP)::SelectObject(hBuf, bmp);

oldbmp2 = (HBITMAP)::SelectObject(hBuf2, bmp2);

while (TRUE)

{

// 復制一遍桌面

::BitBlt(hMD, 0, 0, dwWidth, dwHeight, hDC, 0, 0, SRCCOPY);

// 使用雙緩沖的,繪制位圖

::BitBlt(hMD, x, y, 700, 450, hBuf, 0, 0, SRCAND);

::BitBlt(hMD, x, y, 700, 450, hBuf2, 0, 0, SRCPAINT);

// 繪制到桌面

::BitBlt(hDC, 0, 0, dwWidth, dwHeight, hMD, 0, 0, SRCCOPY);

Sleep(300);

}

::SelectObject(hBuf, oldbmp);

::SelectObject(hBuf, oldbmp2);

::SelectObject(hMD, oldtempbmp);

// 釋放內存

::DeleteObject(tempbmp);

::DeleteDC(hBuf);

::DeleteDC(hMD);

::ReleaseDC(hDesk, hDC);

return 0;

}

int CMFCApplication2Dlg::ShowMyFlower6(LPVOID lpVoid)

{

CMFCApplication2Dlg *pThis = (CMFCApplication2Dlg *)lpVoid;

//Sleep(15000);

srand((unsigned int)time(NULL));

// 獲取桌面屏幕的寬和高

DWORD dwWidth = ::GetSystemMetrics(SM_CXSCREEN);

DWORD dwHeight = ::GetSystemMetrics(SM_CYSCREEN);

//DWORD m = dwWidth/100, n = dwHeight/100;

DWORD x = 0, y = 0;

while (TRUE)

{

x = rand() % dwWidth;

y = rand() % dwHeight;

PaintFlower(x, y);

Sleep(300);

}

return 0;

}

void CMFCApplication2Dlg::OnBnClickedButtonTest()

{

// TODO: 在此添加控件通知處理程序代碼

// 播放音樂

mciSendString(L"open res\\一生所愛.mp3 alias music", 0, 0, 0);

mciSendString(L"play music repeat", 0, 0, 0);

// 窗口最小化到任務欄

::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);

// 停頓

//Sleep(1000);

//// 創建多線程

//// 第一部分 --> 999朵花迅速霸屏

HANDLE hThread0 = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower0, this, 0, NULL);

HANDLE hThread1 = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower1, this, 0, NULL);

::WaitForSingleObject(hThread0, 10000);

g_bStop = TRUE;

Sleep(500); //切換圖像

::CloseHandle(hThread0);

::CloseHandle(hThread1);

// 刷新桌面

HWND hDesktop = ::FindWindow(L"", L"");

hDesktop = ::FindWindowEx(hDesktop, 0, L"", L"");

hDesktop = ::FindWindowEx(hDesktop, 0, L"", L"");

::InvalidateRect(hDesktop, NULL, TRUE);

::SendMessage(hDesktop, WM_PAINT, 0, 0);

::SetCapture(hDesktop);

Sleep(1000);

/*第二部分 --> 顯示花邊*/

::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower2, this, 0, NULL);

::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower3, this, 0, NULL);

/* 第三部分 --> 顯示520和賀卡*/

::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower4, this, 0, NULL);

::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower5, this, 0, NULL);

//// 第三部分 --> 隨機出現的玫瑰

::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ShowMyFlower6, this, 0, NULL);

}


C VC C++ MFC 匯編 函數 腳本 輔助 多開 注入 內存 插件 破解 基址 窗口 大漠 綁定 編程 交流 論壇 實例 源碼
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

VC中文網 - 豫ICP備14012807號|小黑屋|聯系客服|金幣沖值|VC中文網

GMT+8, 2020-8-30 12:09 , Processed in 0.132816 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表
分分彩最安全的倍投法