mybutton.cpp

来自「一个用vc做的挖金子的游戏」· C++ 代码 · 共 92 行

CPP
92
字号
#include "stdafx.h"
#include "mybutton.h"

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

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

	framenow=1;
	return 1;
}

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

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

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

void MYBUTTON::Show(int x,int y,int iFrame)
{
	HBRUSH hback;
	//当前坐标
	xpos=x;
	ypos=y;

	SelectObject(hdcdest,hf);
	GetTextExtentPoint32(hdcdest,ptext,strlen(ptext),&size);
	width=size.cx+10;
	height=size.cy+10;
	//画背景矩形
	hback=(HBRUSH)CreateSolidBrush(color[iFrame]);
	SelectObject(hdcdest,hback);
	Rectangle(hdcdest,xpos,ypos,xpos+width,ypos+height);
	//按钮文字	
	SetTextColor(hdcdest,color[iFrame+2]);
	SetBkColor(hdcdest,color[iFrame]);
	TextOut(hdcdest,xpos+5,ypos+5,ptext,strlen(ptext));	
}

void MYBUTTON::Show(int x,int y)
{
	HBRUSH hback;
	//当前坐标
	xpos=x;
	ypos=y;

	SelectObject(hdcdest,hf);
	GetTextExtentPoint32(hdcdest,ptext,strlen(ptext),&size);
	width=size.cx+10;
	height=size.cy+10;
	//画背景矩形
	hback=(HBRUSH)CreateSolidBrush(color[framenow]);
	SelectObject(hdcdest,hback);
	Rectangle(hdcdest,xpos,ypos,xpos+width,ypos+height);
	//按钮文字	
	SetTextColor(hdcdest,color[framenow+2]);
	SetBkColor(hdcdest,color[framenow]);
	TextOut(hdcdest,xpos+5,ypos+5,ptext,strlen(ptext));	
}

void MYBUTTON::Init(char *p,COLORREF cback1,COLORREF cback2,
		COLORREF ctext1,COLORREF ctext2,HFONT h)
{
	strcpy(ptext,p);
	color[0]=cback1;
	color[1]=cback2;
	color[2]=ctext1;
	color[3]=ctext2;	
	hf=h;
}

⌨️ 快捷键说明

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