学习MFC,用到垂直显示内容,在网上查找了一些方法,做一下总结。
在View类的头文件中增加CString m_strLeft;
在View类中增加WM_PAINT消息的函数OnPaint(),设置输出字体,设置颜色
CPaintDC dc(this); // device context for painting// TODO: 在此处添加消息处理程序代码// 不为绘图消息调用 CFormView::OnPaint()CFont *font = GetFont();LOGFONT lf;font->GetLogFont(&lf);lf.lfHeight = 20; //字体大小lf.lfWeight = 700; //400为标准字体,700为粗体lf.lfEscapement = 900; //垂直显示lf.lfOrientation = 600;lf.lfQuality = PROOF_QUALITY;lf.lfUnderline = false;CString str = "Arial Bold";strcpy(lf.lfFaceName, "Arial Bold");CFont SlantFont;SlantFont.CreateFontIndirect(&lf);CFont *fontOld = dc.SelectObject(&SlantFont);dc.SetTextColor(RGB(255, 0, 0));dc.SetTextAlign(TA_BASELINE);dc.TextOut(100, 300, m_strLeft);dc.SelectObject(fontOld);
增加两个按钮,设置显示的内容并刷新:
m_strLeft = "aaaa"; //显示内容CRect rc(20, 200, 100 + 30, 300 + 100);InvalidateRect(&rc);UpdateWindow(); //刷新
m_strLeft = ""; //值为""时清除,否则修改CRect rc(20, 200, 100 + 30, 300 + 100);InvalidateRect(&rc);UpdateWindow();