第一次执行很正常,第二次就Assertion Failure,我的代码:
LOGFONT lf;定义在Doc类头文件中, CFont ft;定义在View头文件中
--------------------
void CNotePadDoc::OnMenuFont() 
{
// TODO: Add your command handler code here

POSITION pos = GetFirstViewPosition();
CNotePadView* pView = (CNotePadView*)GetNextView(pos); CDC* dc = pView->GetDC();
dc->GetCurrentFont()->GetLogFont(&lf);
CFontDialog dlgFont(&lf);
if (dlgFont.DoModal() == IDOK) 



dlgFont.GetCurrentFont(&lf); 

pView->ft.CreateFontIndirect(&lf)

pView->SetFont(&pView->ft,TRUE);




}
---------------------
另外,字体颜色该怎么设置???

解决方案 »

  1.   

    发现是Create了Font以后,没有Delete掉,改正如下:
    -------------
    void CNotePadDoc::OnMenuFont() 
    {
    // TODO: Add your command handler code here
    LOGFONT lf;
    CFont ft;
    POSITION pos = GetFirstViewPosition();
    CNotePadView* pView = (CNotePadView*)GetNextView(pos);
    memset(&lf, 0, sizeof(LOGFONT)); 
    CFontDialog dlgFont(&lf);
    if (dlgFont.DoModal() == IDOK) 

    dlgFont.GetCurrentFont(&lf); 

    ft.CreateFontIndirect(&lf);

    //pView->SetFont(&ft,TRUE);
    pView->GetEditCtrl().SetFont(&ft,TRUE);
    ft.DeleteObject();

    }
    -------------------
    现在不出错了,可是字体没有改变,只有光标大小变了~
    望不吝赐教!!!