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

📄 nstatic.cpp

📁 你用过<<中华诗词6000>>吗?那个是VF编写的,而我是用VC++编烈写的!搜索速度明显比作者原版更快了,还包含了重要的诗词数据库,代码注释详尽.
💻 CPP
字号:
// NStatic.cpp : 实现文件
//

#include "stdafx.h"
#include "NStatic.h"
#include ".\nstatic.h"


// CNStatic

IMPLEMENT_DYNAMIC(CNStatic, CStatic)
CNStatic::CNStatic()
{
	m_bkc =  0xBFBFBF;
	m_txtc = 0x000000;
	m_bit = NULL;
	m_font = NULL;
	m_px = 10;
	m_tx = 25;


}

CNStatic::~CNStatic()
{
	delete m_bit;
}


BEGIN_MESSAGE_MAP(CNStatic, CStatic)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()



// CNStatic 消息处理程序

void CNStatic::SetText(CString str, BOOL Redraw)
{
	m_str = str;
	if (Redraw)
	{
		RedrawWindow();
	}
}

void CNStatic::SetBKColor(COLORREF crColor)
{
	m_bkc = crColor;
	RedrawWindow();
}

void CNStatic::SetTextColor(COLORREF crColor)
{
	m_txtc = crColor;
	RedrawWindow();
}

void CNStatic::SetBitmapID(UINT nID)
{
	if (nID !=0)
	{
		if (m_bit)
		{
			delete m_bit;
			m_bit = NULL;
		}
		m_bit = new CBitmap;
		m_bit->LoadBitmap(nID);
	}
}


BOOL CNStatic::OnEraseBkgnd(CDC* pDC)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	
	CDC memdc,memdcb;
	BITMAP bit;
	CBitmap bitp;
	int cx, cy;

	if (pDC == NULL || m_bit == NULL)
		return 1;

	CRect rect;
	GetWindowRect(&rect);
	ScreenToClient(&rect);
	
	cx = rect.right - rect.left;
	cy = rect.bottom - rect.top;

	bitp.CreateCompatibleBitmap(pDC, cx, cy);
	memdc.CreateCompatibleDC(pDC);
	memdc.SelectObject(&bitp);

	m_bit->GetBitmap(&bit);
	memdcb.CreateCompatibleDC(pDC);
	memdcb.SelectObject(m_bit);


	CBrush br(m_bkc);
	CPen pen(PS_SOLID , 1, m_bkc);
	memdc.SelectObject(&pen);
	memdc.SelectObject(&br);
	memdc.SetBkMode(TRANSPARENT);
	memdc.SetTextColor(m_txtc);
	if (m_font)
	{
		memdc.SelectObject(m_font);
	}

	memdc.FillRect(&rect, &br);

	int ty, py;
	LOGFONT lfn;
	CRect tre = rect;

	py = (rect.bottom - bit.bmHeight) / 2;
	
	py +=2;
	tre.left += m_tx;
	tre.top +=3;
	memdc.DrawTextEx(m_str, &tre,DT_LEFT|DT_VCENTER|DT_INTERNAL, NULL);
	memdc.TransparentBlt(m_px, py, bit.bmWidth, bit.bmHeight,
		&memdcb, 0, 0, bit.bmWidth, bit.bmHeight, 0xff00ff);

	memdc.Draw3dRect(&rect, 0x979797, 0xFFFFFF);
	
	pDC->BitBlt(0, 0, cx, cy, &memdc, 0, 0, SRCCOPY);
	
	ReleaseDC(pDC);
	pDC = NULL;

	return 1;//CStatic::OnEraseBkgnd(pDC);
}

void CNStatic::SetFont(CFont*  pFont)
{
	if (pFont)
	{
		if (m_font)
		{
			m_font->DeleteObject();
			delete m_font;
			m_font = NULL;
		}

		m_font = new CFont;
		LOGFONT pLogFont;
		pFont->GetLogFont(&pLogFont);
		m_font->CreateFontIndirect(&pLogFont);
		CStatic::SetFont(m_font);
	}
}

⌨️ 快捷键说明

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