快到圣诞节啦,男票女票都有了嘛?没有的话,有没有喜欢的女孩子或者男孩子啊?今天就给你们分享一个圣诞节的表白程序,希望你们喜欢咯,效果是这样的:
圣诞节快到了,让我们用C语言制作一个圣诞表白程序
具体代码如下咯:
// GreetingCardDemoDlg.cpp : 实现文件//#include "stdafx.h"#include "GreetingCardDemo.h"#include "GreetingCardDemoDlg.h"#include "afxdialogex.h"#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()// CGreetingCardDemoDlg 对话框CGreetingCardDemoDlg::CGreetingCardDemoDlg(CWnd* pParent /*=NULL*/): CDialogEx(CGreetingCardDemoDlg::IDD, pParent){m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CGreetingCardDemoDlg::DoDataExchange(CDataExchange* pDX){CDialogEx::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CGreetingCardDemoDlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()//ON_BN_CLICKED(IDC_BTN_DRAW, &CGreetingCardDemoDlg::OnBnClickedBtnDraw)ON_WM_TIMER()END_MESSAGE_MAP()// CGreetingCardDemoDlg 消息处理程序BOOL CGreetingCardDemoDlg::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);// 设置小图标//1. 是不是方法没有被调用//2. 是不是里面的系统方法有问题m_pFont = new CFont;m_pFont->CreateFontW(80,0, 0, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS,L"Arial");SetTimer(1, 100, nullptr);return TRUE; // 除非将焦点设置到控件,否则返回 TRUE}void CGreetingCardDemoDlg::OnSysCommand(UINT nID, LPARAM lParam){if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialogEx::OnSysCommand(nID, lParam);}}void CGreetingCardDemoDlg::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{Draw();CDialogEx::OnPaint();}}//当用户拖动最小化窗口时系统调用此函数取得光标//显示。HCURSOR CGreetingCardDemoDlg::OnQueryDragIcon(){return static_cast<HCURSOR>(m_hIcon);}void CGreetingCardDemoDlg::Draw(){//1.日期CClientDC clientDC(this);//获取设备//2.天气CDC memDC;memDC.CreateCompatibleDC(&clientDC);//memDC.CreateCompatibleDC(NULL);//如果我们要画一张画//我们是不是需要知道这张画得画多大//我们绘画得纸有多大,我们就能画多大//我们的窗口有多大就能画多大//3.获取大小CRect clientRect;//四边形的大小GetClientRect(&clientRect);//我们要将一副画画上去//1. 要有图片我们使用搜索引擎 使用QQ截图//2. 我们要将图片显示在我们的窗口上//1. 图片加载到我们的软件当中//2. 显示//我要画成什么样子CBitmap drawBmp;drawBmp.LoadBitmapW(IDB_BITMAP_CARD);BITMAP bitMap;drawBmp.GetBitmap(&bitMap);memDC.SelectObject(&drawBmp);clientDC.BitBlt(clientRect.left, clientRect.top, bitMap.bmWidth, clientRect.Height(),&memDC, 0, 0, SRCCOPY);memDC.DeleteDC();}void CGreetingCardDemoDlg::DrawText(){//坐标 1.0版本static int nX = 0;static int nY = 0;static int nColor = 255;CClientDC clientDC(this);CRect clientRect;GetClientRect(&clientRect);CFont *pOldFont = clientDC.SelectObject(m_pFont);//clientDC.SetBkMode(TRANSPARENT);clientDC.SetTextColor(RGB(nColor, 0, 0));//nColor -= 10;if (0 >= nColor)nColor = 255;Draw();clientDC.TextOutW(clientRect.left , clientRect.top + nY, L"我 love you * 莉莉");nX += 10;nY += 10;if (nX >= clientRect.Width()){nX = 0;nY = 0;}if (nY >= clientRect.Height()){nY = 0;}clientDC.SelectObject(pOldFont);}void CGreetingCardDemoDlg::OnTimer(UINT_PTR nIDEvent){DrawText();CDialogEx::OnTimer(nIDEvent);}
这些就是全部代码辣,里面的句子你们可以自己改成想对对方说的话,这些都是可以自己改哒,代码只是参考,要学的是编程思路,希望你们能学好C/C++,能为自己所用咯!!
如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!
新闻热点
疑难解答
图片精选