📄 format.cpp
字号:
// Format.cpp : implementation file
//
#include "stdafx.h"
#include "Dialog.h"
#include "Format.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Format dialog
Format::Format(CWnd* pParent /*=NULL*/)
: CDialog(Format::IDD, pParent)
{
//{{AFX_DATA_INIT(Format)
m_bold = FALSE;
m_italic = FALSE;
m_color = -1;
m_underline = FALSE;
//}}AFX_DATA_INIT
}
void Format::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Format)
DDX_Check(pDX, IDC_BOLD, m_bold);
DDX_Check(pDX, IDC_ITALIC, m_italic);
DDX_Radio(pDX, IDC_RED, m_color);
DDX_Check(pDX, IDC_UNDERLINE, m_underline);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Format, CDialog)
//{{AFX_MSG_MAP(Format)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BOLD, OnBold)
ON_BN_CLICKED(IDC_ITALIC, OnItalic)
ON_BN_CLICKED(IDC_UNDERLINE, OnUnderline)
ON_BN_CLICKED(IDC_RED, OnRed)
ON_BN_CLICKED(IDC_BLUE, OnBlue)
ON_BN_CLICKED(IDC_GREEN, OnGreen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Format message handlers
BOOL Format::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//保存预览区域坐标
GetDlgItem(IDC_SAMPLE)->GetWindowRect(&m_RectSample);
ScreenToClient(&m_RectSample);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Format::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
int x,y; //示例文本输出位置
CFont font,tempfont;
LOGFONT lf;
//根据用户的选择,设定字体
tempfont.CreateStockObject(SYSTEM_FIXED_FONT);
tempfont.GetObject(sizeof(LOGFONT),&lf);
if(m_italic)
lf.lfItalic=1;
if(m_bold)
lf.lfWeight=FW_BOLD;
if(m_underline)
lf.lfUnderline=1;
//根据用户的选择,设定字体颜色
switch(m_color)
{
case 1:
dc.SetTextColor(RGB(255,0,0));
break;
case 2:
dc.SetTextColor(RGB(0,0,255));
break;
case 3:
dc.SetTextColor(RGB(0,255,0));
}
font.CreateFontIndirect(&lf);
dc.SelectObject(&font);
x=m_RectSample.left +35;
y=m_RectSample.top+35;
dc.SetBkMode(TRANSPARENT);
dc.TextOut(x,y,"xmnUHmn");
// Do not call CDialog::OnPaint() for painting messages
}
void Format::OnBold()
{
// TODO: Add your control notification handler code here
m_bold=!m_bold; //用户是否选择加粗
//刷新预览区域,显示效果
InvalidateRect(&m_RectSample);
UpdateWindow();
}
void Format::OnItalic()
{
// TODO: Add your control notification handler code here
m_italic=!m_italic;
InvalidateRect(&m_RectSample);
UpdateWindow();
}
void Format::OnUnderline()
{
// TODO: Add your control notification handler code here
m_underline=!m_underline;
InvalidateRect(&m_RectSample);
UpdateWindow();
}
void Format::OnRed()
{
// TODO: Add your control notification handler code here
if(IsDlgButtonChecked(IDC_RED))
{
m_color=1;
InvalidateRect(&m_RectSample);
UpdateWindow();
}
}
void Format::OnBlue()
{
// TODO: Add your control notification handler code here
if(IsDlgButtonChecked(IDC_BLUE))
{
m_color=2;
InvalidateRect(&m_RectSample);
UpdateWindow();
}
}
void Format::OnGreen()
{
// TODO: Add your control notification handler code here
if(IsDlgButtonChecked(IDC_GREEN))
{
m_color=3;
InvalidateRect(&m_RectSample);
UpdateWindow();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -