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

📄 reviewstatic.cpp

📁 一款用C++编写的网络版中国象棋对弈程序源代码
💻 CPP
字号:
// reviewstatic.cpp : implementation file
//

#include "stdafx.h"
#include "chineseqi.h"
#include "reviewstatic.h"

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

/////////////////////////////////////////////////////////////////////////////
// reviewstatic

reviewstatic::reviewstatic()
{
	mode=3;
	drawtop=0;
	drawleft=0;
	handcur=LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(HAND));
}

reviewstatic::~reviewstatic()
{
}


BEGIN_MESSAGE_MAP(reviewstatic, CStatic)
	//{{AFX_MSG_MAP(reviewstatic)
	ON_WM_ERASEBKGND()
	ON_WM_PAINT()
	//ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// reviewstatic message handlers

BOOL reviewstatic::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	return CStatic::OnEraseBkgnd(pDC);
}
void reviewstatic::draw(CString name)
{
	if (drawbmp.m_hObject)
		drawbmp.DeleteObject();
	drawbmp.m_hObject=LoadImage(AfxGetInstanceHandle(),name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
	BITMAP bm;
	drawbmp.GetObject(sizeof(BITMAP),&bm);
	width=bm.bmWidth;
	height=bm.bmHeight;
	drawbody();
}
void reviewstatic::draw(UINT nid)
{
	if (drawbmp.m_hObject)
		drawbmp.DeleteObject();
	drawbmp.LoadBitmap(nid);
	BITMAP bm;
	drawbmp.GetObject(sizeof(BITMAP),&bm);
	width=bm.bmWidth;
	height=bm.bmHeight;
	drawbody();
}
void reviewstatic::drawbody()
{
	CClientDC pDC(this);
	CRect rect;
	GetClientRect(&rect);
	pDC.FillSolidRect(&rect,GetSysColor(COLOR_BTNFACE));
	double bi;
	int bmwidth;
	int bmheight;
	if(drawbmp.m_hObject)
	{
		CDC memdc;
		int i;
		int j;
		int left;
		int top;
		memdc.CreateCompatibleDC(&pDC);
		CBitmap *old=memdc.SelectObject(&drawbmp);
		switch (mode)
		{
		case 1:
 			for(i=0;i<rect.Width();i+=width)
			{
				bmheight=height;
				bmwidth=width;
				for(j=0;j<rect.Height();j+=height)
				{	if(i+bmwidth>rect.Width()) bmwidth=rect.Width()-i;
					if(j+bmheight>rect.Height()) bmheight=rect.Height()-j;
					pDC.BitBlt(i,j,bmwidth,bmheight,&memdc,0,0,SRCCOPY);
				}
			}
			break;
		case 2:
			pDC.StretchBlt(0,0,rect.Width(),rect.Height(),&memdc,0,0,width,height,SRCCOPY);
			break;
		case 3:
		default:
			left=(rect.Width()-width)/2;
			top=(rect.Height()-height)/2;
			bmwidth=width;
			bmheight=height;
			bi=(double)height/width;
			if (top<0) 
			{
				top=0;
				bmheight=rect.Height();
				bmwidth=bmheight/bi;
				left=(rect.Width()-bmwidth)/2;
				if(left<0)
				{
					left=0;
					bmwidth=rect.Width();
					bmheight=bmwidth*bi;
					top=(rect.Height()-bmheight)/2;
				}
			}
			else if (left<0) 
			{
				left=0;
				bmwidth=rect.Width();
				bmheight=bmwidth*bi;
				top=(rect.Height()-bmheight)/2;
				if(top<0)
				{
					top=0;
					bmheight=rect.Height();
					bmwidth=bmheight/bi;
					left=(rect.Width()-bmwidth)/2;
				}
			}
			if (bmwidth>rect.Width()) bmwidth=rect.Width();
			if(bmheight>rect.Height()) bmheight=rect.Height();
			pDC.StretchBlt(left,top,bmwidth,bmheight,&memdc,0,0,width,height,SRCCOPY);
			break;
		}
	}

}
void reviewstatic::clear()
{
	if (drawbmp.m_hObject)
		drawbmp.DeleteObject();
	drawbody();
}

void reviewstatic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	drawbody();
	// Do not call CStatic::OnPaint() for painting messages
}

⌨️ 快捷键说明

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