📄 jnsedit.cpp
字号:
// JnSEdit.cpp : implementation file
//
#include "stdafx.h"
#include "Prog.h"
#include "JnSEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// JnSEdit
JnSEdit::JnSEdit()
{
::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(m_lf),&m_lf);
m_font.CreateFontIndirect(&m_lf);
_bNumber=FALSE;
m_crTextColor = ::GetSysColor( COLOR_WINDOWTEXT );
m_crBkColor = ::GetSysColor( COLOR_WINDOW);
CreateBrushType();
bRead=TRUE;
}
JnSEdit::~JnSEdit()
{
m_font.DeleteObject();
}
BEGIN_MESSAGE_MAP(JnSEdit, CEdit)
//{{AFX_MSG_MAP(JnSEdit)
ON_WM_CHAR()
ON_WM_KEYDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// JnSEdit message handlers
JnSEdit& JnSEdit::SetFontName(const CString& strFont)
{
strcpy(m_lf.lfFaceName,strFont);
ReconstructFont();
RedrawWindow();
return *this;
}
JnSEdit& JnSEdit::SetFontSize(int nSize)
{
nSize=-theApp.jns.DoubleToInt(nSize*1.333);
m_lf.lfHeight = nSize;
ReconstructFont();
RedrawWindow();
return *this;
}
JnSEdit& JnSEdit::SetFontBold(BOOL bBold)
{
m_lf.lfWeight = bBold ? FW_BOLD : FW_NORMAL;
ReconstructFont();
RedrawWindow();
return *this;
}
JnSEdit& JnSEdit::SetFontUnderline(BOOL bSet)
{
m_lf.lfUnderline = bSet;
ReconstructFont();
RedrawWindow();
return *this;
}
JnSEdit& JnSEdit::SetFontItalic(BOOL bSet)
{
m_lf.lfItalic = bSet;
ReconstructFont();
RedrawWindow();
return *this;
}
void JnSEdit::ReconstructFont()
{
m_font.DeleteObject();
BOOL bCreated = m_font.CreateFontIndirect(&m_lf);
ASSERT(bCreated);
SetFont(&m_font);
}
int JnSEdit::GetFontSize()
{
return -theApp.jns.DoubleToInt(m_lf.lfHeight/1.333);
}
//判断当前字体是否是斜体字
BOOL JnSEdit::GetFontI()
{
return m_lf.lfItalic;
}
//判断当前字体是否是下划线字
BOOL JnSEdit::GetFontU()
{
return m_lf.lfUnderline;
}
//判断当前字体是否是粗体字
BOOL JnSEdit::GetFontB()
{
if(m_lf.lfWeight==FW_BOLD)
return TRUE;
else
return FALSE;
}
//返回当前所使用的字体名称
CString JnSEdit::GetFontName()
{
return CString(m_lf.lfFaceName);
}
void JnSEdit::SetFontLog(LOGFONT& plf, int nType)
{
CString str;
m_lf.lfCharSet=plf.lfCharSet;
m_lf.lfClipPrecision=plf.lfClipPrecision;
m_lf.lfEscapement=plf.lfEscapement;
str=CString(plf.lfFaceName);
strcpy(m_lf.lfFaceName,str);
switch(nType)
{
case 1:
m_lf.lfHeight=theApp.jns.DoubleToInt(plf.lfHeight);
break;
case 2:
m_lf.lfHeight=theApp.jns.DoubleToInt(plf.lfHeight/15.3);
break;
default:
break;
}
m_lf.lfItalic=plf.lfItalic;
m_lf.lfOrientation=plf.lfOrientation;
m_lf.lfOutPrecision=plf.lfOutPrecision;
m_lf.lfPitchAndFamily=plf.lfPitchAndFamily;
m_lf.lfQuality=plf.lfQuality;
m_lf.lfStrikeOut=plf.lfStrikeOut;
m_lf.lfUnderline=plf.lfUnderline;
m_lf.lfWeight=plf.lfWeight;
m_lf.lfWidth=plf.lfWidth;
ReconstructFont();
RedrawWindow();
}
void JnSEdit::GetFontLog(LOGFONT& plf)
{
CString str;
plf.lfCharSet=m_lf.lfCharSet;
plf.lfClipPrecision=m_lf.lfClipPrecision;
plf.lfEscapement=m_lf.lfEscapement;
str=CString(m_lf.lfFaceName);
strcpy(plf.lfFaceName,str);
plf.lfHeight=theApp.jns.DoubleToInt(m_lf.lfHeight);
plf.lfItalic=m_lf.lfItalic;
plf.lfOrientation=m_lf.lfOrientation;
plf.lfOutPrecision=m_lf.lfOutPrecision;
plf.lfPitchAndFamily=m_lf.lfPitchAndFamily;
plf.lfQuality=m_lf.lfQuality;
plf.lfStrikeOut=m_lf.lfStrikeOut;
plf.lfUnderline=m_lf.lfUnderline;
plf.lfWeight=m_lf.lfWeight;
plf.lfWidth=m_lf.lfWidth;
}
void JnSEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(!bRead)
return;
if(_bNumber)
{
if(nChar==8 || nChar==46 || (nChar>47 && nChar<58 ))
{
if(nChar==46 && _nWei<1)
{
return;
}
CString str;
CString _str;
int n;
int n1,n2;
int i;
GetWindowText(str);
_str=str;
n=str.Find(".");
GetSel(n1,n2);
if(nChar==46)
{
if(n>-1)
return;
else
{
str=str.Left(n2);
_str=_str.Left(n2+_nWei);
for(i=0;i<n2;i++)
_str.Delete(0);
str+=".";
str+=_str;
SetWindowText(str);
n2++;
SetSel(n2,n2);
return;
}
}
else
{
if(n>-1 && nChar!=8)
{
if(n2>n)
{
for(int i=0;i<=n;i++)
str.Delete(0);
if(str.GetLength()>=_nWei)
return;
}
}
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
else
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
void JnSEdit::SetNumber(BOOL bNumber, int nWei)
{
if(nWei<-1)
AfxMessageBox("编辑控件属性设置失误!");
_bNumber=bNumber;
_nWei=nWei;
}
void JnSEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(!bRead)
return;
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
void JnSEdit::SetBkColor(COLORREF color)
{
_ASSERT(::IsWindow(m_hWnd));
m_crBkColor = color;
m_brBkGround.DeleteObject();
CreateBrushType();
Invalidate();
}
void JnSEdit::SetTextColor(COLORREF color)
{
_ASSERT(::IsWindow(m_hWnd));
m_crTextColor = color;
Invalidate();
}
BOOL JnSEdit::CreateBrushType()
{
return m_brBkGround.CreateSolidBrush( m_crBkColor );
}
HBRUSH JnSEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetTextColor( m_crTextColor );
pDC->SetBkColor( m_crBkColor );
return (HBRUSH)m_brBkGround;
}
void JnSEdit::SetRead(BOOL bSet)
{
bRead=bSet;
}
void JnSEdit::OnRButtonDown(UINT nFlags, CPoint point)
{
if(!bRead)
return;
CEdit::OnRButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -