在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例C/C++语言基础 → 生日快乐小程序源码(可任意修改)

生日快乐小程序源码(可任意修改)

C/C++语言基础

下载此实例
  • 开发语言:C/C++
  • 实例大小:22.35M
  • 下载次数:49
  • 浏览次数:3207
  • 发布时间:2019-10-31
  • 实例类别:C/C++语言基础
  • 发 布 人:robot666
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 小程序 程序 修改 源码

实例介绍

【实例简介】本资源是关于生日快乐的一个程序的源代码,是送给好友,女友的最佳的生日礼物。其中对图片的处理采用的是透视化处理,对一些对图片处理比较感兴趣的人来说是相当有用!!


背景图片在自动交替显示,文字可随意修改,带生日快乐 背景音乐,非常不错

【实例截图】

from clipboard


from clipboard


from clipboard



【核心代码】

// BirthdayDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Birthday.h"
#include "BirthdayDlg.h"
#include "mmsystem.h"
#include "FrontDraw.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define NCLIP1 6
#define NCLIP2 0
#define ST 1
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBirthdayDlg dialog

CBirthdayDlg::CBirthdayDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBirthdayDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBirthdayDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	IsSetTimer=false;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBirthdayDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBirthdayDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBirthdayDlg, CDialog)
	//{{AFX_MSG_MAP(CBirthdayDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBirthdayDlg message handlers

BOOL CBirthdayDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

    CRgn m_rgn;
	CRect rec;
	GetClientRect(&rec);
	m_rgn.CreateEllipticRgn(rec.left,rec.top,rec.Width(),rec.Height());
    
 //	SetWindowRgn((HRGN)m_rgn,TRUE);

    PlaySound(MAKEINTRESOURCE(IDR_WAVE1),AfxGetResourceHandle(),SND_ASYNC|SND_RESOURCE|SND_NODEFAULT|SND_LOOP);

	m_distance = 30;
	m_bkbmpID=0;
    CString pArrCredit[NCLIP1] = { "祝:"
        ,"薛XX"
        ,"绝对菜鸟"     
        ,"佛剑分说"
        ,"三位Dota大神"
		,"生日快乐!"
        };
	bkbmpID[0]=IDB_BKBITMAP1;
    bkbmpID[1]=IDB_BKBITMAP2;
    bkbmpID[2]=IDB_BKBITMAP3;
    m_ftbitmap.LoadBitmap(IDB_BITMAP1);
	m_bkbitmap.LoadBitmap(bkbmpID[m_bkbmpID]);
	// Add "About..." menu item to system menu.
    CRect rect;
	GetClientRect(&rect);
	m_bkrec.left = int(rect.Width()*32/585);
	m_bkrec.top  = int(rect.Height()*56/392);
	m_bkrec.right = int(rect.Width()*555/585);
	m_bkrec.bottom = int(rect.Height()*335/392);
    SetCredits(pArrCredit);
	SetTimer(1,5,NULL);

	SetTimer(2,5000,NULL);
	IsSetTimer = true;
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CBirthdayDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CBirthdayDlg::OnPaint() 
{
    CPaintDC pdc(this);
	DrawDlg(&pdc);

	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CBirthdayDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CBirthdayDlg::DrawDlg(CDC *pDC)
{


    CRect rec;
	GetClientRect(&rec);

//	BITMAP bmp;
//	m_bitmap1.GetBitmap(&bmp);
//    pDC->SetStretchBltMode(HALFTONE);
//	pDC->StretchBlt(0,0,rec.Width(),rec.Height(),&cmpdc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);



	BITMAP bkbmp,ftbmp;
	m_bkbitmap.GetBitmap(&bkbmp);
	m_ftbitmap.GetBitmap(&ftbmp);
    CDC memDC;
	memDC.CreateCompatibleDC( pDC );
 
	CBitmap bitmap;
	bitmap.CreateCompatibleBitmap( pDC, ftbmp.bmWidth, ftbmp.bmHeight );
	CBitmap* pOldMemDCBitmap = memDC.SelectObject( &bitmap );
		
	CDC tempDC;
	tempDC.CreateCompatibleDC(pDC);
	CBitmap* pOldTempDCBitmap = tempDC.SelectObject( &m_ftbitmap);

	memDC.BitBlt( 0, 0, ftbmp.bmWidth, ftbmp.bmHeight , &tempDC, 
                      0,0, SRCCOPY );
	CDC maskDC;
	maskDC.CreateCompatibleDC(pDC);
	CBitmap maskBitmap;

	// Create monochrome bitmap for the mask
	maskBitmap.CreateBitmap( ftbmp.bmWidth, ftbmp.bmHeight , 1, 1, NULL );
	CBitmap* pOldMaskDCBitmap = maskDC.SelectObject( &maskBitmap );
    memDC.SetBkColor( RGB(192,192,192));

	// Create the mask from the memory DC
	maskDC.BitBlt( 0, 0,ftbmp.bmWidth, ftbmp.bmHeight , &memDC, 0, 0, SRCCOPY );

	tempDC.SelectObject(pOldTempDCBitmap);
	pOldTempDCBitmap = tempDC.SelectObject( &m_bkbitmap );

	CDC imageDC;
	CBitmap bmpImage;
	imageDC.CreateCompatibleDC( pDC );
	bmpImage.CreateCompatibleBitmap( pDC, rec.Width(), rec.Height() );
	CBitmap* pOldImageDCBitmap = imageDC.SelectObject( &bmpImage );

	// Get x and y offset
	// Draw bitmap in tiled manner to imageDC
	imageDC.SetStretchBltMode(HALFTONE);

	imageDC.StretchBlt( m_bkrec.left,m_bkrec.top,m_bkrec.Width(),m_bkrec.Height(), &tempDC, 0, 0, bkbmp.bmWidth,bkbmp.bmHeight,SRCCOPY );
 	imageDC.SetStretchBltMode(HALFTONE);
	imageDC.SetBkColor(RGB(255,255,255));
	imageDC.SetTextColor(RGB(0,0,0));

	AddFront(imageDC);

	// Set the background in memDC to black. Using SRCPAINT with black and any other
	// color results in the other color, thus making black the transparent color
	memDC.SetBkColor(RGB(0,0,0));
	memDC.SetTextColor(RGB(255,255,255));
	memDC.BitBlt(0, 0, ftbmp.bmWidth, ftbmp.bmHeight , &maskDC, 0, 0, SRCAND);
    
	// Set the foreground to black. See comment above.

	imageDC.StretchBlt(0,0, rec.Width(), rec.Height() , &maskDC, 0, 0,ftbmp.bmWidth,ftbmp.bmHeight, SRCAND);

	// Combine the foreground with the background
    imageDC.StretchBlt(0,0, rec.Width(),rec.Height(), &memDC, 0, 0, ftbmp.bmWidth, ftbmp.bmHeight,SRCPAINT);

	// Draw the final image to the screen   
	pDC->BitBlt( 0, 0, rec.Width(),rec.Height(),&imageDC, 0, 0, SRCCOPY );

	imageDC.SelectObject(pOldImageDCBitmap);
	maskDC.SelectObject(pOldMaskDCBitmap);
	tempDC.SelectObject(pOldTempDCBitmap);
	memDC.SelectObject(pOldMemDCBitmap);

}



void CBirthdayDlg::AddFront(CDC &dc)
{
	
    FrontDraw* p = pFD;
	int h;
	CFont* pOldFont;
	COLORREF OldColor;
	CRect r(m_bkrec);
	dc.SetBkMode(TRANSPARENT);
	while(p!=NULL)
	{
		if(!p->IsText)
		{
			if (m_mbitmap.m_hObject)
			{
				m_mbitmap.DeleteObject();
			}
			m_mbitmap.LoadBitmap(p->bmpID);
            h= p->m_rec.top;
			while((h>=m_bkrec.top-200) && (h<=m_bkrec.bottom))
			{
				BITMAP mbmp;
      
				m_mbitmap.GetBitmap(&mbmp);
				CDC memDC;
				memDC.CreateCompatibleDC(&dc );

				CBitmap bitmap;
				bitmap.CreateCompatibleBitmap( &dc, mbmp.bmWidth, mbmp.bmHeight );
				CBitmap* pOldMemDCBitmap = memDC.SelectObject( &bitmap );
					
				CDC tempDC;
				tempDC.CreateCompatibleDC(&dc);
				CBitmap* pOldTempDCBitmap = tempDC.SelectObject( &m_mbitmap);

				memDC.BitBlt( 0, 0, mbmp.bmWidth, mbmp.bmHeight , &tempDC, 
								  0,0, SRCCOPY );
				CDC maskDC;
				maskDC.CreateCompatibleDC(&dc);
				CBitmap maskBitmap;

				// Create monochrome bitmap for the mask
				maskBitmap.CreateBitmap( mbmp.bmWidth, mbmp.bmHeight , 1, 1, NULL );
				CBitmap* pOldMaskDCBitmap = maskDC.SelectObject( &maskBitmap );
				memDC.SetBkColor( RGB(192,192,192));

				// Create the mask from the memory DC
				maskDC.BitBlt( 0, 0,mbmp.bmWidth, mbmp.bmHeight , &memDC, 0, 0, SRCCOPY );

				// Set the background in memDC to black. Using SRCPAINT with black and any other
				// color results in the other color, thus making black the transparent color
				memDC.SetBkColor(RGB(0,0,0));
				memDC.SetTextColor(RGB(255,255,255));
				memDC.BitBlt(0, 0, mbmp.bmWidth, mbmp.bmHeight , &maskDC, 0, 0, SRCAND);

				// Set the foreground to black. See comment above.
				dc.StretchBlt(p->m_rec.left,h, p->m_rec.Width(), p->m_rec.Height() , &maskDC, 0, 0,mbmp.bmWidth,mbmp.bmHeight, SRCAND);

				// Combine the foreground with the background
				dc.StretchBlt(p->m_rec.left,h, p->m_rec.Width(),p->m_rec.Height(), &memDC, 0, 0, mbmp.bmWidth, mbmp.bmHeight,SRCPAINT);
				// Draw the final image to the screen   

				maskDC.SelectObject(pOldMaskDCBitmap);
				tempDC.SelectObject(pOldTempDCBitmap);
				memDC.SelectObject(pOldMemDCBitmap);
				h =NCLIP1*m_distance 480;
			}

		}
		else
		{
			h = p->m_height;

			if (p->m_font.m_hObject)
			   p->m_font.DeleteObject();
			pOldFont = dc.SelectObject(&(p->m_font));
			OldColor = dc.SetTextColor(p->TextColor);

			while((h>=m_bkrec.top-20) && (h<=m_bkrec.bottom))
			{
				r.top = h;
				dc.DrawText(p->m_str,p->m_str.GetLength(),&r,DT_TOP|DT_CENTER|DT_NOPREFIX | DT_SINGLELINE);
				h =NCLIP1*m_distance 480;
			}
			dc.SetTextColor(OldColor);
			dc.SelectObject(pOldFont);
		}
		p = p->next;
	}

}

void CBirthdayDlg::SetCredits(CString *pstr)
{
	CString *p;
	FrontDraw* q,*temp;
    CRect rect;
	GetClientRect(&rect);
	p=pstr;
	pFD = NULL;
	int Height = m_bkrec.bottom;
	q=new FrontDraw;
	q->IsText = false;
	q->m_rec.left = rect.left   (rect.Width()-200)/2;
	q->m_rec.right = q->m_rec.left   200;
	q->m_rec.top = Height;
	q->m_rec.bottom = Height 200;
	q->bmpID = IDB_FTBITMAP2;
	q->next = pFD;
	pFD = q;
	Height  = 250;
	for (int i=0; i<NCLIP1; i  )
	{
       q= new FrontDraw;
	   q->m_str=*p;
	   q->TextColor=RGB(0,0,255);
       q->m_font.CreateFont(15,8,0,0,0,0,0,0,0,0,0,0,0,"楷体");
	   q->m_height = Height;
       q->next = pFD;
	   pFD = q;
	   Height  =m_distance;
	   p = p 1;
	}
    q=new FrontDraw;
	q->IsText = false;
	q->m_rec.left = rect.left   (rect.Width()-150)/2;
	q->m_rec.right = q->m_rec.left   150;
	q->m_rec.top = Height;
	q->m_rec.bottom = Height 200;
	q->bmpID = IDB_FTBITMAP3;
	q->next = pFD;
	pFD = q;
}

void CBirthdayDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	FrontDraw* p = pFD;
    if (nIDEvent ==1)
	{
	 while(p!=NULL)
	 {
		  
       if (!p->IsText)
	   {
		   p->m_rec.top -=ST;
		   p->m_rec.bottom -=ST;
	       if (p->m_rec.top<m_bkrec.top-200)
		   {
             p->m_rec.top  =NCLIP1*m_distance 480;
			 p->m_rec.bottom  =NCLIP1*m_distance 480;
		   }
	   }
	   else
	   {
		   p->m_height -=ST;
		   if (p->m_height<m_bkrec.top-10)
		   {

			   p->m_height  =NCLIP1*m_distance 480;
		   }
	   }
	   p = p->next;
	 }
	}
	if (nIDEvent==2)
	{
		m_bkbmpID = (m_bkbmpID 1)%3;
		if(m_bkbitmap.m_hObject)
		{
			m_bkbitmap.DeleteObject();
		}
		m_bkbitmap.LoadBitmap(bkbmpID[m_bkbmpID]);
	}
	CClientDC dc(this);
	//Invalidate();
//	OnPaint();
	DrawDlg(&dc);
//	CDialog::OnTimer(nIDEvent);

}

void CBirthdayDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	if (IsSetTimer)
	{
		KillTimer(1);
		KillTimer(2);
	}
	// TODO: Add your message handler code here
	
}

实例下载地址

生日快乐小程序源码(可任意修改)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警