📄 richeditctrlgs.cpp
字号:
// RichEditGS.cpp : implementation file
//
#include "stdafx.h"
#include "RichEditCtrlGS.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRichEditCtrlGS
CRichEditCtrlGS::CRichEditCtrlGS()
{
}
CRichEditCtrlGS::~CRichEditCtrlGS()
{
}
BEGIN_MESSAGE_MAP(CRichEditCtrlGS, CRichEditCtrl)
//{{AFX_MSG_MAP(CRichEditCtrlGS)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// Character and Font Attributes
int CRichEditCtrlGS::IsBold(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD;
DWORD dwSelMask = GetSelectionCharFormat(cf);
bool bConsistent = false; // BOLD inconsistent over the whole Selection
if( dwSelMask & CFM_BOLD )// BOLD consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( cf.dwEffects & CFE_BOLD )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsItalic(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_ITALIC;
DWORD dwSelMask = GetSelectionCharFormat(cf);
bool bConsistent = false; // ITALIC inconsistent over the whole Selection
if( dwSelMask & CFM_ITALIC )// ITALIC consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( cf.dwEffects & CFE_ITALIC )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsUnderlined(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_UNDERLINE;
DWORD dwSelMask = GetSelectionCharFormat(cf);
bool bConsistent = false; // UNDERLINE inconsistent over the whole Selection
if( dwSelMask & CFM_UNDERLINE )// UNDERLINE consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( cf.dwEffects & CFE_UNDERLINE )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsStrikeout(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_STRIKEOUT;
DWORD dwSelMask = GetSelectionCharFormat(cf);
bool bConsistent = false; // STRIKEOUT inconsistent over the whole Selection
if( dwSelMask & CFM_STRIKEOUT )// STRIKEOUT consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( cf.dwEffects & CFE_STRIKEOUT )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsProtected(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_PROTECTED;
DWORD dwSelMask = GetSelectionCharFormat(cf);
bool bConsistent = false; // PROTECTED inconsistent over the whole Selection
if( dwSelMask & CFM_PROTECTED )// PROTECTED consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( cf.dwEffects & CFE_PROTECTED )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsLinked(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_LINK;
DWORD dwSelMask = GetSelectionCharFormat(cf);
bool bConsistent = false; // PROTECTED inconsistent over the whole Selection
if( dwSelMask & CFM_LINK )// PROTECTED consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( cf.dwEffects & CFE_LINK )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
void CRichEditCtrlGS::SetBold(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// If selection is all the same toggle BOLD style
// turn it on otherwise over the whole selection
if( (cf.dwMask & CFM_BOLD) & (dwSelMask & CFM_BOLD) )
{ cf.dwEffects ^= CFE_BOLD;
}
else
{ cf.dwEffects |= CFE_BOLD;
}
cf.dwMask = CFM_BOLD;
SetSelectionCharFormat(cf);
}
void CRichEditCtrlGS::SetItalic(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_ITALIC;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// If selection is all the same toggle ITALIC style
// turn it on otherwise over the whole selection
if( (cf.dwMask & CFM_ITALIC) & (dwSelMask & CFM_ITALIC) )
{ cf.dwEffects ^= CFE_ITALIC;
}
else
{ cf.dwEffects |= CFE_ITALIC;
}
cf.dwMask = CFM_ITALIC;
SetSelectionCharFormat(cf);
}
void CRichEditCtrlGS::SetUnderlined(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_UNDERLINE;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// If selection is all the same toggle UNDERLINE style
// turn it on otherwise over the whole selection
if( (cf.dwMask & CFM_UNDERLINE) & (dwSelMask & CFM_UNDERLINE) )
{ cf.dwEffects ^= CFE_UNDERLINE;
}
else
{ cf.dwEffects |= CFE_UNDERLINE;
}
cf.dwMask = CFM_UNDERLINE;
SetSelectionCharFormat(cf);
}
void CRichEditCtrlGS::SetStrikeout(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_STRIKEOUT;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// If selection is all the same toggle STRIKEOUT style
// turn it on otherwise over the whole selection
if( (cf.dwMask & CFM_STRIKEOUT) & (dwSelMask & CFM_STRIKEOUT) )
{ cf.dwEffects ^= CFE_STRIKEOUT;
}
else
{ cf.dwEffects |= CFE_STRIKEOUT;
}
cf.dwMask = CFM_STRIKEOUT;
SetSelectionCharFormat(cf);
}
void CRichEditCtrlGS::SetProtected(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_PROTECTED;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// If selection is all the same toggle PROTECTED style
// turn it on otherwise over the whole selection
if( (cf.dwMask & CFM_PROTECTED) & (dwSelMask & CFM_PROTECTED) )
{ cf.dwEffects ^= CFE_PROTECTED;
}
else
{ cf.dwEffects |= CFE_PROTECTED;
}
cf.dwMask = CFM_PROTECTED;
SetSelectionCharFormat(cf);
}
void CRichEditCtrlGS::SetLink(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_LINK;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// If selection is all the same toggle PROTECTED style
// turn it on otherwise over the whole selection
if( (cf.dwMask & CFM_LINK) & (dwSelMask & CFM_LINK) )
{ cf.dwEffects ^= CFE_LINK;
}
else
{ cf.dwEffects |= CFE_LINK;
}
cf.dwMask = CFM_LINK;
SetSelectionCharFormat(cf);
}
int CRichEditCtrlGS::GetFontSize(void)
{ CHARFORMAT cf;
int nPointSize = 0;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_SIZE;
DWORD dwSelMask = GetSelectionCharFormat(cf);
// return only the font size it is the same over the whole selection
if( (cf.dwMask & CFM_SIZE) & (dwSelMask & CFM_SIZE) )
{ nPointSize = cf.yHeight/20;// convert from twips to points
}
return nPointSize;
}
void CRichEditCtrlGS::SetFontSize(int nPointSize)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_SIZE;
GetSelectionCharFormat(cf);
nPointSize *= 20; // convert from points to twips
cf.yHeight = nPointSize;
cf.dwMask = CFM_SIZE;
SetSelectionCharFormat(cf);
}
CString CRichEditCtrlGS::GetFontName(void)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_FACE;
DWORD dwSelMask = GetSelectionCharFormat(cf);
CString strName =_T("");
// return only the font name it is the same over the whole selection
if( (cf.dwMask & CFM_FACE) & (dwSelMask & CFM_FACE) )
{ strName = cf.szFaceName;
}
return strName;
}
void CRichEditCtrlGS::SetFontName(const CString strFontName)
{
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_FACE;
GetSelectionCharFormat(cf);
CString strName = strFontName.Left(31);
int i;
for (i = 0; i <= strName.GetLength()-1; i++)
cf.szFaceName[i] = strName[i];
cf.szFaceName[i]='\0';
cf.dwMask = CFM_FACE;
SetSelectionCharFormat(cf);
}
void CRichEditCtrlGS::SetColour(COLORREF color)
{ CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
GetSelectionCharFormat(cf);
cf.crTextColor = color;
if( cf.dwEffects & CFE_AUTOCOLOR )
{ cf.dwEffects ^= CFE_AUTOCOLOR;
}
SetSelectionCharFormat(cf);
}
// Paragraph Attributes
int CRichEditCtrlGS::IsRight()
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT | PFA_RIGHT;
DWORD dwSelMask = GetParaFormat(pf);
bool bConsistent = false; // RIGHT alignment inconsistent over the whole Selection
if( dwSelMask & PFA_RIGHT )// RIGHT alignment consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( (pf.wAlignment & 0xFF) == PFA_RIGHT )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsLeft(void)
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT;
DWORD dwSelMask = GetParaFormat(pf);
bool bConsistent = false; // LEFT alignment inconsistent over the whole Selection
if( dwSelMask & PFA_LEFT )// LEFT alignment consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( (pf.wAlignment & 0xFF) == PFA_LEFT )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsCentered(void)
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT;
DWORD dwSelMask = GetParaFormat(pf);
bool bConsistent = false; // CENTER alignment inconsistent over the whole Selection
if( (dwSelMask & PFA_CENTER) == PFA_CENTER)// CENTER alignment consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( (pf.wAlignment & 0xFF) == PFA_CENTER )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsJustified(void)
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT;
DWORD dwSelMask = GetParaFormat(pf);
bool bConsistent = false; // JUSTIFIED alignment inconsistent over the whole Selection
if( dwSelMask & PFA_JUSTIFY )// JUSTIFIED alignment consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( (pf.wAlignment & 0xFF) == PFA_JUSTIFY )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
int CRichEditCtrlGS::IsBulleted(void)
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT | PFM_NUMBERING;
DWORD dwSelMask = GetParaFormat(pf);
bool bConsistent = false; // Paragraph NUMBERING inconsistent over the whole Selection
if( dwSelMask & PFM_NUMBERING )// Paragraph NUMBERING consistent over the whole Selection?
{ bConsistent = true;
}
if( !bConsistent )
{ return (-1); // Set Button to indeterminate
}
if( pf.wNumbering & PFN_BULLET )
{ return(1); // Set Button to checked
}
return 0; // Set Button to unchecked
}
void CRichEditCtrlGS::SetRight(void)
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT;
pf.wAlignment = PFA_RIGHT;
SetParaFormat(pf); // Set the paragraph.
}
void CRichEditCtrlGS::SetLeft(void)
{ PARAFORMAT pf;
pf.cbSize = sizeof(PARAFORMAT);
pf.dwMask = PFM_ALIGNMENT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -