欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用VC++ 显示一首诗歌

程序员文章站 2022-04-27 08:11:12
...

新建一个单文档工程;

 

在OnDraw函数加入如下代码;

void CShgView::OnDraw(CDC* pDC)
{
	CShgDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	CString strshg[5];          //字义输出诗歌

	strshg[0] = "八阵图";
	strshg[1] = "功盖三分国";
	strshg[2] = "名成八阵图";
	strshg[3] = "江流石不转";
	strshg[4] = "遗恨失吞吴";

	//创建两个字体对象
	CFont *OldFont, NewFont;

	LOGFONT MyFont = {
        30,
        10,
        0,
        0,
        0,
        1,
        1,
        0,
        ANSI_CHARSET,
        OUT_DEFAULT_PRECIS,
        CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY,
        DEFAULT_PITCH,
        "黑体"
        };
		
	NewFont.CreatePointFont(200, "宋体", NULL);
	OldFont = pDC->SelectObject(&NewFont);
    pDC->TextOut(150, 100, strshg[0]);
	
	pDC->SelectObject(OldFont);
    NewFont.DeleteObject();
	
	pDC->SelectStockObject(ANSI_FIXED_FONT);
	pDC->TextOut(100, 160, strshg[1]);
	pDC->TextOut(220, 160, strshg[2]);
	pDC->TextOut(100, 200, strshg[3]);
	pDC->TextOut(220, 200, strshg[4]);	
}

 

运行程序;效果如下;

使用VC++ 显示一首诗歌

 

参阅:

https://www.cnblogs.com/KmXlOf/p/5348019.html

https://blog.csdn.net/lgs790709/article/details/78890472