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

📄 bitmaptool.cpp

📁 一个用vc做的挖金子的游戏
💻 CPP
字号:
#include "stdafx.h"
#include "bitmaptool.h"

MYBITMAP::~MYBITMAP()
{
	DeleteObject(hBm);
}

void MYBITMAP::Init(HINSTANCE hInstance,int iResource,int row,int col)
{
	BITMAP bm;
	inum=row;
	jnum=col;

	hBm=LoadBitmap(hInstance,MAKEINTRESOURCE(iResource));
	GetObject(hBm,sizeof(BITMAP),&bm);

	width=bm.bmWidth/inum;
	height=bm.bmHeight/jnum;
}

void MYBITMAP::SetDC(HDC hdest,HDC hsrc)
{
	hdcdest=hdest;
	hdcsrc=hsrc;
}

void MYBITMAP::Show(int x,int y,int iFrame)
{
	xpos=x;
	ypos=y;
	SelectObject(hdcsrc,hBm);
	BitBlt(hdcdest,xpos,ypos,width,height,hdcsrc,iFrame*width,0,SRCCOPY);	
}

void MYBITMAP::ShowCenter(int y,int iFrame)
{
	xpos=(screenwidth-width)/2;
	ypos=y;

	SelectObject(hdcsrc,hBm);
	BitBlt(hdcdest,xpos,ypos,width,height,hdcsrc,iFrame*width,0,SRCCOPY);	
}
void MYBITMAP::ShowCenter(int y)
{
	xpos=(screenwidth-width)/2;
	ypos=y;

	SelectObject(hdcsrc,hBm);
	BitBlt(hdcdest,xpos,ypos,width,height,hdcsrc,framenow*width,0,SRCCOPY);	
}

void MYBITMAP::ShowLoop(int left,int top,int right,int bottom,int iframe)
{
	int i,j;

	SelectObject(hdcsrc,hBm);
	for(j=top;j<bottom;j+=height)
	{
		for(i=left;i<right;i+=width)
		{
			BitBlt(hdcdest,i,j,width,height,hdcsrc,iframe*width,0,SRCCOPY);	
		}
	}
}

void MYBITMAP::ShowNoBack(int x,int y,int iFrame)
{
	xpos=x;
	ypos=y;
	SelectObject(hdcsrc,hBm);
	BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,iFrame*width,height/2,SRCAND);	
	BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,iFrame*width,0,SRCPAINT);		
}


void MYBITMAP::ShowNoBackLoop(int x,int y,int iFrame,int iNum)
{
	int i;
	xpos=x;
	ypos=y;
	SelectObject(hdcsrc,hBm);
	for(i=0;i<iNum;i++)
	{
		BitBlt(hdcdest,xpos+i*width,ypos,width,height/2,hdcsrc,iFrame*width,height/2,SRCAND);	
		BitBlt(hdcdest,xpos+i*width,ypos,width,height/2,hdcsrc,iFrame*width,0,SRCPAINT);		
	}
}


int MYBITMAP::MouseOut(int x,int y)
{
	if(x<xpos || x>(xpos+width) || y<ypos || y>(ypos+height))
		framenow=0;

	return 1;
}
int MYBITMAP::MouseOver(int x,int y)
{
	if(x<xpos || x>(xpos+width) || y<ypos || y>(ypos+height))
		return 0;

	framenow=1;
	return 1;
}

int MYBITMAP::DetectMouseMove(int x,int y)
{
	MouseOver(x,y);
	MouseOut(x,y);
	return 0;
}


int MYBITMAP::DetectMouseUp(int x,int y)
{
	if(x<xpos || x>(xpos+width) || y<ypos || y>(ypos+height))
		return 0;
	return 1;
}

void MYBITMAP::ShowAni()
{
	if(!iStartAni)
		return;

	SelectObject(hdcsrc,hBm);
	BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,framenow*width,height/2,SRCAND);	
	BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,framenow*width,0,SRCPAINT);		
	framenow++;
	//播放结束
	if(framenow>=inum)
		iStartAni=0;
}
void MYBITMAP::SetAni(int x,int y)
{
	xpos=x;
	ypos=y;
	framenow=0;
	iStartAni=1;
}

⌨️ 快捷键说明

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