⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dzsframe.cpp

📁 利用vc++(Win32 Application)开发的程序
💻 CPP
字号:
// dzsFrame.cpp : implementation file
//

#include "stdafx.h"
#include "dzs.h"
#include "dzsFrame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

struct snow
{
	int x;
	int y;
	BOOL exist;
};

/////////////////////////////////////////////////////////////////////////////
// dzsFrame

IMPLEMENT_DYNCREATE(dzsFrame, CFrameWnd)

int i,count;
snow drop[50];
dzsFrame::dzsFrame()
{
	Create(NULL,"星星雨");
	CClientDC dc(this);
	int width = dc.GetDeviceCaps(HORZRES);
	int height = dc.GetDeviceCaps(VERTRES);
	GetWindowRect( &rect );
	width = ( width - ( rect.right - rect.left ))/2 ;
	height = (height - (rect.bottom - rect.top ))/2 ;
	MoveWindow( width , height , (rect.right - rect.left ) , (rect.bottom - rect.top ) ,true);
	GetClientRect(&rect);
	mdc = new CDC;
	mdc1 = new CDC;
	mdc->CreateCompatibleDC(&dc); 
	mdc1->CreateCompatibleDC(&dc);
	bgbmp = new CBitmap;
	snow = new CBitmap;
	mask = new CBitmap;
	temp = new CBitmap;
	bgbmp->m_hObject = (HBITMAP)::LoadImage(NULL,"bground.bmp",IMAGE_BITMAP,rect.right,rect.bottom,LR_LOADFROMFILE); 
	snow->m_hObject = (HBITMAP)::LoadImage(NULL,"snow.bmp",IMAGE_BITMAP,20,20,LR_LOADFROMFILE); 
	mask->m_hObject = (HBITMAP)::LoadImage(NULL,"mask.bmp",IMAGE_BITMAP,20,20,LR_LOADFROMFILE); 
	temp->CreateCompatibleBitmap(&dc,rect.right,rect.bottom);
	mdc->SelectObject(temp);
}

dzsFrame::~dzsFrame()
{
	delete bgbmp;
	delete snow;
	delete mask;
	delete temp;
	delete mdc;
	delete mdc1;
}


BEGIN_MESSAGE_MAP(dzsFrame, CFrameWnd)
	//{{AFX_MSG_MAP(dzsFrame)
	ON_WM_TIMER()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// dzsFrame message handlers

void dzsFrame::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(count<50)
	{
		drop[count].x = rand()%rect.right;
		drop[count].y = 0;
		drop[count].exist = true;
		count++;
	}
	CClientDC dc(this);
	mdc1->SelectObject(bgbmp);
	mdc->BitBlt(0,0,rect.right,rect.bottom,mdc1,0,0,SRCCOPY);
	for(i=0;i<50;i++)
	{
		if(drop[i].exist)
		{
			mdc1->SelectObject(mask);
			mdc->BitBlt(drop[i].x,drop[i].y,20,20,mdc1,0,0,SRCAND);
			mdc1->SelectObject(snow);
			mdc->BitBlt(drop[i].x,drop[i].y,20,20,mdc1,0,0,SRCPAINT);
			if(rand()%2==0)
				drop[i].x+=2;
			else 
				drop[i].x-=2;
			drop[i].y+=8;
			if(drop[i].y > rect.bottom)
			{
				drop[i].x = rand()%rect.right;
				drop[i].y = 0;
			}
		}
	}

	dc.BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);

	
	CFrameWnd::OnTimer(nIDEvent);
}

int dzsFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	SetTimer(1,0,NULL);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -