BOOL CFtDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
/*
// CBrush b1(RGB(0,255,255));
CBrush b1;
b1.CreateSolidBrush(RGB(0,255,255));
CBrush*pBrh = dc.SelectObject(&b1);
CRect rect(240,100,340,160);
CPoint pt1(340,20),pt2(300,200);
dc.Chord(rect, pt1, pt2);
CBrush b2;
b2.CreateHatchBrush(HS_DIAGCROSS,RGB(255,0,255));
dc.SelectObject(&b2);
CPoint ps[] = {CPoint(340,20),CPoint(220,90),CPoint(400,100)};
dc.Polygon(ps,sizeof(ps)/sizeof(ps[0]));
// CPen p4(PS_NULL,666,RGB(235,111,222));
// dc.SelectObject(&p4);
////CBrush b2(HS_DIAGCROSS,RGB(255,0,255));
dc.Ellipse(240,170,340,230);
CBitmap bmp;
bmp.LoadBitmap(IDB_WOLF);
// CBrush b3(&bmp);
CBrush b3;
b3.CreatePatternBrush(&bmp);
dc.SelectObject(&b3);
dc.RoundRect(0,0,200,280,20,20);
CBrush b4;
// LOGBRUSH lb = {BS_HOLLOW};
// b4.CreateBrushIndirect(&lb);
// b4.CreateSysColorBrush(COLOR_HIGHLIGHT);
// dc.SelectObject(&b4);
dc.SelectStockObject(WHITE_BRUSH);
dc.SelectStockObject(NULL_PEN );
CPoint ps2[] = {CPoint(145,10),CPoint(240,10),CPoint(260,80),CPoint(110,80)};
CPen p1(PS_SOLID,4,RGB(255,0,0));
// dc.SelectObject(p1);
dc.Polygon(ps2,sizeof(ps2)/sizeof(ps2[0]));
*/
void CFtDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CFont * pFont = GetFont();
Normal(&dc,pFont);
Height(&dc,pFont);
Weight(&dc,pFont);
Width(&dc,pFont);
Others(&dc,pFont);
Escape(&dc,pFont);
CreateFont(&dc);
SetColors(&dc);
dc.TextOut(10,10,"使用缺省字体输出!");
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFtDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFtDlg::Normal(CDC *pDC, CFont *pFont)
{
pFont = pDC ->SelectObject(pFont);
pDC ->TextOut(10,30,"使用对话框字体输出!");
pDC ->SelectObject(pFont);//恢复进入函数前字体
}
void CFtDlg::Height(CDC *pDC, CFont *pFont)
{
LOGFONT lf;
pFont ->GetLogFont( &lf);//-12 400 134 宋体
lf.lfHeight *= 2;
CFont font;
font.CreateFontIndirect(&lf);
pFont = pDC ->SelectObject(&font);
pDC ->TextOut(10,50,"测试字体高度(大小)加倍");
pDC ->SelectObject(pFont);//恢复进入函数前字体
}
void CFtDlg::Weight(CDC *pDC, CFont *pFont)
{
LOGFONT lf;
pFont ->GetLogFont( &lf);//-12 400 134 宋体
lf.lfWeight = 700;
CFont font;
font.CreateFontIndirect(&lf);
pFont = pDC ->SelectObject(&font);
pDC ->TextOut(10,80,"测试粗体字");
pDC ->SelectObject(pFont);//恢复进入函数前字体
}
void CFtDlg::Width(CDC *pDC, CFont *pFont)
{
LOGFONT lf;
pFont ->GetLogFont( &lf);//-12 400 134 宋体
lf.lfWidth = lf.lfHeight;
CFont font;
font.CreateFontIndirect(&lf);
pFont = pDC ->SelectObject(&font);
pDC ->TextOut(10,100,"测试字体宽度");
pDC ->SelectObject(pFont);//恢复进入函数前字体
}
void CFtDlg::Others(CDC *pDC, CFont *pFont)
{
LOGFONT lf;
pFont ->GetLogFont( &lf);//-12 400 134 宋体
lf.lfItalic = TRUE;
lf.lfUnderline = TRUE;
lf.lfStrikeOut = TRUE;
lf.lfHeight *= 2;
CFont font;
font.CreateFontIndirect(&lf);
pFont = pDC ->SelectObject(&font);
pDC ->TextOut(10,120,"测试斜体,下划线和删除线");
pDC ->SelectObject(pFont);//恢复进入函数前字体
}
void CFtDlg::Escape(CDC *pDC, CFont *pFont)
{
LOGFONT lf;
pFont ->GetLogFont( &lf);//-12 400 134 宋体
lf.lfHeight *= 2;
lf.lfEscapement=200;
CFont font;
font.CreateFontIndirect(&lf);
pFont = pDC ->SelectObject(&font);
pDC ->TextOut(10,180,"测试字符串的倾斜度");
pDC ->SelectObject(pFont);//恢复进入函数前字体
}
void CFtDlg::CreateFont(CDC* pDC)
{
CFont ft1;
ft1.CreatePointFont(120,"楷体_GB2312");//与实际字体相差10倍
CFont *pFont = pDC ->SelectObject(&ft1);
pDC ->TextOut(10,220,"简单字体创建的方法!");
LOGFONT lf = {24};
strcpy(lf.lfFaceName,"黑体");
lf.lfCharSet=GB2312_CHARSET;
lf.lfItalic= TRUE;
lf.lfStrikeOut=TRUE;
CFont ft2;
ft2.CreateFontIndirect(&lf);
pDC ->SelectObject(&ft2);
pDC ->TextOut(10,240,"完整字体创建的方法!");
HFONT hFont = ft1;
CFont* p = CFont::FromHandle(hFont);
pDC ->SelectObject(pFont);
}
void CFtDlg::SetColors(CDC *pDC)
{
COLORREF clBack = pDC ->SetBkColor(RGB(0,0,255));
pDC ->TextOut(200,200,"文字背景颜色");
int nMode = pDC ->SetBkMode(TRANSPARENT );
COLORREF clText = pDC ->SetTextColor(RGB(255,0,0));
pDC ->TextOut(10,200,"文字颜色");
pDC ->SetBkMode(nMode);
pDC ->SetBkColor(clBack);
pDC ->SetTextColor(clText);
}//