MFC输出不同字体大小和格式

  void CMFCTEXTOUTDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDC* pDC = GetDC();
		if (pDC == nullptr) return;
		CFont myfont, * oldFont;
		LOGFONT font1, font2, font3, font4, font5, font6;
		memset(&font1, 0, sizeof(LOGFONT));
		memset(&font2, 0, sizeof(LOGFONT));
		memset(&font3, 0, sizeof(LOGFONT));
		memset(&font4, 0, sizeof(LOGFONT));
		memset(&font5, 0, sizeof(LOGFONT));
		memset(&font6, 0, sizeof(LOGFONT));		
				   
		/*static auto i = 0;*/
		
		font1.lfWidth = 60;
		font1.lfHeight = 60;
		font1.lfUnderline = true;
		StrCpy(font1.lfFaceName, _T("黑体"));			
		myfont.CreateFontIndirectW(&font1);
		oldFont = pDC->SelectObject(&myfont);
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkMode(TRANSPARENT);
		pDC->TextOutW(100, 100, _T("平凡的世界"));
		pDC->SelectObject(oldFont);
		

		font2.lfWidth = 50;
		font2.lfHeight = 50;
		font2.lfItalic = true;
		StrCpy(font2.lfFaceName, _T("华文彩云"));
		myfont.DeleteObject();
		myfont.CreateFontIndirectW(&font2);
		oldFont = pDC->SelectObject(&myfont);
		pDC->SetTextColor(RGB(255, 0, 0));
		pDC->SetBkMode(TRANSPARENT);
		pDC->TextOutW(100, 200, _T("平凡的世界"));
		pDC->SelectObject(oldFont);
			
		

		font3.lfWidth = 40;
		font3.lfHeight = 40;			
		font3.lfItalic = true;
		StrCpyW(font3.lfFaceName, _T("华文行楷"));
		myfont.DeleteObject();
		myfont.CreateFontIndirectW(&font3);
		oldFont = pDC->SelectObject(&myfont);
		pDC->SetTextColor(RGB(200, 100, 100));
		pDC->SetBkMode(TRANSPARENT);
		pDC->TextOutW(100, 300, _T("平凡的世界"));
		pDC->SelectObject(oldFont);
		

		font4.lfWidth = 30;
		font4.lfHeight = 30;			
		font4.lfItalic = true;
		StrCpyW(font4.lfFaceName, _T("华文仿宋"));
		myfont.DeleteObject();
		myfont.CreateFontIndirectW(&font4);
		oldFont = pDC->SelectObject(&myfont);
		pDC->SetTextColor(RGB(200, 100, 100));
		pDC->SetBkMode(TRANSPARENT);
		pDC->TextOutW(100, 400, _T("平凡的世界"));
		pDC->SelectObject(oldFont);
		

		font5.lfWidth = 20;
		font5.lfHeight = 20;			
		font5.lfItalic = true;
		StrCpyW(font5.lfFaceName, _T("微软雅黑"));
		myfont.DeleteObject();   //删除一个之前的字体
		myfont.CreateFontIndirectW(&font5);  //创建一个字体
		oldFont = pDC->SelectObject(&myfont);
		pDC->SetTextColor(RGB(200, 100, 100));
		pDC->SetBkMode(TRANSPARENT);
		pDC->TextOutW(100, 500, _T("平凡的世界"));
		pDC->SelectObject(oldFont);
		

		font6.lfWidth = 10;
		font6.lfHeight = 10;			
		font6.lfItalic = true;
		font6.lfUnderline = true;
		StrCpyW(font6.lfFaceName, _T("华文隶书"));
		myfont.DeleteObject();
		myfont.CreateFontIndirectW(&font6);
		oldFont = pDC->SelectObject(&myfont);
		pDC->SetTextColor(RGB(200, 100, 100));
		pDC->SetBkMode(TRANSPARENT);
		pDC->TextOutW(100, 600, _T("平凡的世界"));
		pDC->SelectObject(oldFont);
		

		ReleaseDC(pDC);
		CDialogEx::OnPaint();
	}
}

你可能感兴趣的:(c++,MFC)