按下鼠标右键,我可以创建Dialog,这样我就可以输入新文本,更改字体和大小。当我输入新文本并选择字体(和大小)时,它会显示但字体不变。我使用工具框添加编辑控件来添加文本(按下确定时)和按钮的字体和大小。在TxtDlg.cpp中:
void CTxtDlg::OnOK()
{
m_txtEdit.GetWindowText(m_text) ;
CDialog::OnOK();
}
void CTxtDlg::OnBnClickedButton1()
{
CFontDialog dlg;
int response = dlg.DoModal(); //poziv dijaloga
dlg.GetCurrentFont(&m_lf);
}
我还在TxtDlg.h中将变量m_lf声明为LOGFONT,所以这部分应该是正确的
CString m_text;
CEdit m_txtEdit;
virtual void OnOK();
afx_msg void OnBnClickedButton1();
LOGFONT m_lf;
我猜测ProjectView.cpp部分是不正确的(对于字体),应该使用ChangeFontIndirect但不知道如何。
void CFesbView::OnRButtonDown(UINT nFlags, CPoint point)
{
CFesbDoc*pDoc= GetDocument();
CTxtDlg dlg;
int response = dlg.DoModal(); //calling dialog
if(IDOK == response)
{
if(dlg.m_text.IsEmpty())
AfxMessageBox(L"You did not enter text");
else
pDoc->m_text = dlg.m_text; // put text in document
Invalidate();
}
pDoc->m_pos = point; //point contain coordinates because text
//has to be written where clicked
//this is the incorrect part, also need to save text and font in document
CFont l_font;
LOGFONT m_lf;
if(IDC_BUTTON1==response){
l_font.CreateFontIndirect(&m_lf);
pDoc->m_lf = dlg.m_lf; }
CView::OnRButtonDown(nFlags, point);
}
这是我第一次使用MFC,所以我完全不理解