editex.cpp
来自「24点游戏,用c++实现」· C++ 代码 · 共 150 行
CPP
150 行
// EditEx.cpp : implementation file
//
#include "stdafx.h"
#include "24Dian.h"
#include "EditEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEditEx
CEditEx::CEditEx()
{
m_clrFont=RGB(255,30,0);
m_brush.CreateSolidBrush(RGB(255,255,255));
if(!m_bmpBK.LoadFromFile("BK\\bk.bmp"))
{
AfxMessageBox("Can not load \"bk.bmp\"!");
}
/* 屏幕dc初始化*/
HDC screenDC;
int colorBits, xRes, yRes;
screenDC = CreateDC("DISPLAY", NULL, NULL,NULL);
/* 检索设备 */
colorBits = GetDeviceCaps(screenDC, BITSPIXEL);
xRes = GetDeviceCaps(screenDC, HORZRES);
yRes = GetDeviceCaps(screenDC, VERTRES);
/* 清除 */
DeleteDC(screenDC);
int nResponse = IDOK;
if(xRes==1024 && yRes==768)
{
m_logFont.lfHeight=40;
}
else
{
m_logFont.lfHeight = 25;
}
m_logFont.lfWidth=0;
m_logFont.lfWeight=FW_NORMAL;
m_logFont.lfEscapement=0;
m_logFont.lfOrientation=0;
m_logFont.lfItalic=FALSE;
m_logFont.lfStrikeOut=FALSE;
m_logFont.lfUnderline=FALSE;
m_logFont.lfCharSet=ANSI_CHARSET;
m_logFont.lfQuality=DEFAULT_QUALITY;
m_logFont.lfOutPrecision=OUT_CHARACTER_PRECIS;
m_logFont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
m_logFont.lfPitchAndFamily=DEFAULT_PITCH | FF_SWISS;
// char name[32]="Times New Roman";Fixedsys
strcpy(m_logFont.lfFaceName,"宋体");
}
CEditEx::~CEditEx()
{
}
BEGIN_MESSAGE_MAP(CEditEx, CEdit)
//{{AFX_MSG_MAP(CEditEx)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_ERASEBKGND()
ON_WM_GETDLGCODE()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEditEx message handlers
BOOL CEditEx::Create(DWORD dwStyle, CRect &rect, CWnd *pParentWnd, UINT nID)
{
//WS_VISIBLE|ES_AUTOHSCROLL |ES_AUTOVSCROLL |ES_MULTILINE|ES_LEFT| WS_CHILD | WS_BORDER|WS_TABSTOP
if(!CEdit::Create(dwStyle, rect, pParentWnd, nID))
{
TRACE0("Failed to create text edit wnd!\n");
return -1;
}
m_font.CreateFontIndirect(&m_logFont);
CEdit::SetFont(&m_font,FALSE);
return 1;
}
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->SetBkMode(TRANSPARENT); //设置背景透明,这样,输出字符的时候就
//是所谓的空心字,而不是有白的底色
pDC->SetTextColor(m_clrFont);
// return HBRUSH(GetStockObject(HOLLOW_BRUSH));
return (HBRUSH)m_brush.GetSafeHandle();
// return NULL;
}
void CEditEx::SetColor(COLORREF color)
{
m_clrFont=color;
}
void CEditEx::SetFont(LOGFONT logFont)
{
m_font.DeleteObject();
m_font.CreateFontIndirect(&logFont);
CEdit::SetFont(&m_font,FALSE);
}
BOOL CEditEx::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
// only paint the rect that needs repainting
/* CRect rect;
GetClientRect(rect);
m_bmpBK.DrawTile(*pDC,&rect);
return TRUE;*/
return CEdit::OnEraseBkgnd(pDC);
}
UINT CEditEx::OnGetDlgCode()
{
// TODO: Add your message handler code here and/or call default
// RedrawWindow(NULL, NULL,RDW_INVALIDATE | RDW_ERASE );
return CEdit::OnGetDlgCode();
}
void CEditEx::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
RedrawWindow(NULL, NULL,RDW_INVALIDATE | RDW_ERASE );
CEdit::OnVScroll(nSBCode, nPos, pScrollBar);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?