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

📄 controlsex.cpp

📁 这些源代码
💻 CPP
字号:
// ControlsEx.cpp : implementation file
//

#include "stdafx.h"
#include "ControlsEx.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEditEx

CEditEx::CEditEx(COLORREF fore, COLORREF back)
{
	m_clrText = fore;
	m_clrBkgnd = back;
	m_brBkgnd.CreateSolidBrush (m_clrBkgnd);
}

CEditEx::~CEditEx()
{
}


BEGIN_MESSAGE_MAP(CEditEx, CEdit)
	//{{AFX_MSG_MAP(CEditEx)
	ON_WM_CTLCOLOR_REFLECT()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEditEx message handlers

BOOL CEditEx::Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID )
{
	return (CEditEx::Create (dwStyle, rect, pParentWnd, nID));
}

void CEditEx::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
	CEdit::OnCreate (lpCreateStruct);
}

HBRUSH CEditEx::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a non-NULL brush if the parent's handler should not be called
    pDC->SetTextColor( m_clrText );    // text
    pDC->SetBkColor( m_clrBkgnd );    // text bkgnd
    return m_brBkgnd;                // ctl bkgnd	return NULL;
}

void CEditEx::SetBackColor (COLORREF cr)
{

	m_clrBkgnd = cr;
	m_brBkgnd.DeleteObject ();
	m_brBkgnd.CreateSolidBrush (m_clrBkgnd);
	Invalidate ();
}

void CEditEx::SetCharColor (COLORREF cr)
{
	m_clrText = cr;
}

COLORREF CEditEx::GetCharColor ()
{
	return (m_clrText);
}

COLORREF CEditEx::GetBackColor ()
{
	return (m_clrBkgnd);
}

/////////////////////////////////////////////////////////////////////////////
// CStaticEx

CStaticEx::CStaticEx(COLORREF fore, COLORREF back)
{
	m_clrText = fore;
	m_clrBkgnd = back;
	m_brBkgnd.CreateSolidBrush (m_clrBkgnd);
	m_Font = NULL;
	m_FontFace = "Times New Roman";
	m_PointSize = 0;
	m_SetWidth = 0;
}

CStaticEx::~CStaticEx()
{
	if (m_Font != NULL)
		delete m_Font;
}


BEGIN_MESSAGE_MAP(CStaticEx, CStatic)
	//{{AFX_MSG_MAP(CStaticEx)
	ON_WM_CTLCOLOR_REFLECT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStaticEx message handlers

HBRUSH CStaticEx::CtlColor(CDC* pDC, UINT nCtlColor) 
{
// TODO: Change any attributes of the DC here
	
// TODO: Return a non-NULL brush if the parent's handler should not be called
    pDC->SetTextColor( m_clrText );    // text
    pDC->SetBkColor( m_clrBkgnd );    // text bkgnd
    return m_brBkgnd;                // ctl bkgnd	return NULL;
}

void CStaticEx::SetBackColor (COLORREF cr)
{

	m_clrBkgnd = cr;
	m_brBkgnd.DeleteObject ();
	m_brBkgnd.CreateSolidBrush (m_clrBkgnd);
	Invalidate();
}

void CStaticEx::SetCharColor (COLORREF cr)
{
	m_clrText = cr;
}

COLORREF CStaticEx::GetCharColor ()
{
	return (m_clrText);
}

COLORREF CStaticEx::GetBackColor ()
{
	return (m_clrBkgnd);
}


void CStaticEx::SetFont (CFont *cfont, BOOL redraw)
{
	CStatic::SetFont (cfont, redraw);
}

void CStaticEx::SetFont (CString & strFont)
{
LOGFONT	lf;
CFont	*font;

	if (m_Font != NULL)
		delete m_Font;
	m_Font = new CFont;
	if (m_Font == NULL)
		return;
	font = GetFont ();
	if (font == NULL)
	{
		return;
	}
	if (!font->GetLogFont (&lf))
	{
		lf.lfEscapement = 0;
		lf.lfOrientation = 0;
		lf.lfWeight = 400;
		lf.lfItalic = 0;
		lf.lfUnderline = 0;
		lf.lfStrikeOut = 0;
		lf.lfCharSet = DEFAULT_CHARSET;
		lf.lfOutPrecision = 3;
		lf.lfClipPrecision = 2;
		lf.lfQuality = 1;
		lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	}
	strcpy (lf.lfFaceName, (LPCSTR) strFont);
	lf.lfHeight = m_PointSize;
	lf.lfWidth = m_SetWidth;
	m_Font->CreateFontIndirect (&lf);
	SetFont (m_Font);
	m_FontFace = strFont;
}

int CStaticEx::SetSetWidth (float newSetWidth)
{
	return (SetTypeParam (parmSetWidth, newSetWidth));
}

int CStaticEx::SetPointSize (float newPointSize)
{
	return (SetTypeParam (parmPointSize, newPointSize));
}

int CStaticEx::SetTypeParam (int parm, float newParam)
{
LOGFONT	lf;
CFont	*font;
int		OldParm;
int		iNewParam;

	if (m_Font != NULL)
		delete m_Font;
	m_Font = new CFont;
	if (m_Font == NULL)
		return (0);
	font = GetFont ();
	if (font == NULL)
	{
		return (0);
	}
	if (!font->GetLogFont (&lf))
	{
		lf.lfEscapement = 0;
		lf.lfOrientation = 0;
		lf.lfWeight = 400;
		lf.lfItalic = 0;
		lf.lfUnderline = 0;
		lf.lfStrikeOut = 0;
		lf.lfCharSet = DEFAULT_CHARSET;
		lf.lfOutPrecision = 3;
		lf.lfClipPrecision = 2;
		lf.lfQuality = 1;
		lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	}
	strcpy (lf.lfFaceName, (LPCSTR) m_FontFace);
	lf.lfHeight = m_PointSize;
	lf.lfWidth = m_SetWidth;
	iNewParam = (int) (newParam * 1000.0);
	switch (parm)
	{
		case parmPointSize:
			OldParm = lf.lfHeight;
			lf.lfHeight = -MulDiv(iNewParam, GetDeviceCaps(this->GetDC()->m_hDC, LOGPIXELSY), 72);
			lf.lfHeight /= 1000;
			lf.lfWidth = 0;
			m_PointSize = lf.lfHeight;
			m_SetWidth = lf.lfWidth;
			break;
		case parmSetWidth:
			OldParm = lf.lfWidth;
			lf.lfWidth = MulDiv(iNewParam, GetDeviceCaps(this->GetDC()->m_hDC, LOGPIXELSX), 72);
			lf.lfWidth /= 1;
			m_SetWidth = lf.lfWidth;
			break;
		default:
			OldParm = 0;
			break;
	}
	strcpy (lf.lfFaceName, (LPCSTR) m_FontFace); 
	m_Font->CreateFontIndirect (&lf);
	SetFont (m_Font);
	return (OldParm);
}

⌨️ 快捷键说明

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