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

📄 3dtextbutton.cpp

📁 VC编写的彩票分析软件源码
💻 CPP
字号:
// 3DTextButton.cpp : implementation file
//

#include "stdafx.h"
#include "3DTextButton.h"
#include "yilufa.h"

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

/////////////////////////////////////////////////////////////////////////////
// C3DTextButton

C3DTextButton::C3DTextButton()
{
	m_ColorR=255;
	m_ColorG=0;
	m_ColorB=255;
}

C3DTextButton::~C3DTextButton()
{
}


BEGIN_MESSAGE_MAP(C3DTextButton, CButton)
	//{{AFX_MSG_MAP(C3DTextButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// C3DTextButton message handlers

void C3DTextButton::Draw(CDC *pDC, const CRect &rect, UINT state)
{
		//数据定义区
	CFont font;
	CFont tryfont;
	CFont* pFont=GetFont();
	CFont* pFontOld;
	//CBitmap bitmap,*pOldBitmap;
	CSize textSizeClient;
	CRect rectClient;
	//CDC mdc;
	LOGFONT logfont;
	COLORREF textCol;
	COLORREF oldTextColor;
	
	int minx;
	int miny;
	int oldBkMode;
	int cx;
	int cy;
	int s;
	int l;
	///////////////////////////////////

	///////////
	m_pDC=pDC;
	m_Rect=▭
	m_State=state;
	//GetWindowText(text);
	//mdc.CreateCompatibleDC(pDC);
	//bitmap.LoadBitmap(IDB_BTN);
	//mdc.SelectObject(&bitmap);
	l=text.GetLength();
	rectClient=rect;
	///////////////////////////////////
	//绘出按钮背景
    pDC->FillSolidRect(rect.left,rect.top,rect.Width(),rect.Height(),RGB(0,0,0));
	pDC->FillSolidRect(rect.left+1,rect.top+1,rect.Width()-3,rect.Height()-2,RGB(100,200,120));
	//::StretchBlt(pDC->GetSafeHdc(),rect.left,rect.top,rect.Width(),rect.Height(),mdc.GetSafeHdc(),0,0,80,20,SRCCOPY);
	
	//确定所选字体的有效高度和宽度
	pFont->GetObject(sizeof(LOGFONT),&logfont);
	if(logfont.lfHeight==0) logfont.lfHeight=20;
	logfont.lfWidth=0;
	logfont.lfWeight=1000;
	logfont.lfEscapement=logfont.lfOrientation=0;
	VERIFY(tryfont.CreateFontIndirect(&logfont));
	pFontOld=pDC->SelectObject(&tryfont);
	//根据控件大小调整字体高度
	textSizeClient=pDC->GetTextExtent(text,l);
	if(rectClient.Width()*textSizeClient.cy>rectClient.Height()*textSizeClient.cx)
	{
		logfont.lfHeight=::MulDiv(logfont.lfHeight,rectClient.Height(),textSizeClient.cy);
	}
	else
	{
		logfont.lfHeight=::MulDiv(logfont.lfHeight,rect.Width(),textSizeClient.cx);
	}
	//创建并协调字体
	font.CreateFontIndirect(&logfont);
	pDC->SelectObject(&font);
	textSizeClient=pDC->GetTextExtent(text,l);
	//确定文本与控件的距离
	minx=rectClient.left+(rectClient.Width()-textSizeClient.cx)/2;
	miny=rectClient.top+(rectClient.Height()-textSizeClient.cy)/2;
	oldBkMode=pDC->SetBkMode(TRANSPARENT);
	textCol=::GetSysColor(COLOR_BTNTEXT);
	oldTextColor=pDC->SetTextColor(textCol);
	cx=minx;
	cy=miny;
	s=(state&ODS_SELECTED?-1:+1);
	cx+=2;
	cy+=2;
	//实现3D效果
	pDC->SetTextColor(::GetSysColor(COLOR_3DDKSHADOW));
	pDC->TextOut(cx-s*2,cy+s*2,text);
	pDC->TextOut(cx+s*2,cy-s*2,text);
	pDC->TextOut(cx+s*2,cy+s*2,text);
	pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
	pDC->TextOut(cx-s*2,cy+s*2,text);
	pDC->TextOut(cx-s*2,cy-s*2,text);
	pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
	pDC->TextOut(cx-s*1,cy+s*1,text);
	pDC->TextOut(cx+s*1,cy-s*1,text);
	pDC->TextOut(cx+s*1,cy+s*1,text);
	pDC->SetTextColor(::GetSysColor(COLOR_3DLIGHT));
	pDC->TextOut(cx,cy-s*1,text);
	pDC->TextOut(cx-s*1,cy,text);
	pDC->TextOut(cx-s*1,cy-s*1,text);
	pDC->SetTextColor(textCol);
	//输出标题
	pDC->SetTextColor(RGB(200+s*55,55-s*55,0));
	pDC->TextOut(cx-s,cy-s,text);
	//恢复设备描述表
	pDC->SelectObject(pFontOld);
	pDC->SetTextColor(oldTextColor);
	pDC->SetBkMode(oldBkMode);
	////////
	//释放内存
	font.DeleteObject();
	tryfont.DeleteObject();
	pFont->DeleteObject();
	pFontOld->DeleteObject();
	//bitmap.DeleteObject();
	//pOldBitmap->DeleteObject();
	DeleteObject(&textSizeClient);
	DeleteObject(&rectClient);
	//mdc.DeleteDC();
	DeleteObject(&logfont);
	DeleteObject(&textCol);
	DeleteObject(&oldTextColor);
	//
	DeleteObject(&minx);
	DeleteObject(&miny);
	DeleteObject(&oldBkMode);
	DeleteObject(&cx);
	DeleteObject(&cy);
	DeleteObject(&s);
	DeleteObject(&l);
	//





	
}

void C3DTextButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
	ASSERT_VALID(pDC);
	CRect rectClient=lpDrawItemStruct->rcItem;
	Draw(pDC,rectClient,lpDrawItemStruct->itemState);
}

void C3DTextButton::DrawAgin()
{
	m_ColorR--;
	m_ColorG++;
	m_ColorB-=2;
	if(m_ColorR==0) m_ColorR=255;
	if(m_ColorG==255) m_ColorG=0;
	if(m_ColorB==0) m_ColorB=255;
	CPaintDC dc(this);
	CRect rc;
	GetClientRect(&rc);
	Draw(&dc,&rc,0);
	Invalidate(true);

}

⌨️ 快捷键说明

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