2016-09-19 89 views
0

我想在我的mfc应用程序中创建重做/撤消功能,但是当我试图撤消CLine对象时 - 它无法正常工作。我做错了什么?对不起我的英语不好!“重做/撤消”功能的问题(mfc,C++)

enter image description here

void CKonokhovDoc::OnEditUndo() 
{ 
// TODO: Add your command handler code here 
int Index = (int)m_LineArray.GetUpperBound(); 
int Index2 = (int)m_LineArray_redo.GetUpperBound(); 
if (Index>-1){ 
    redoLine = m_LineArray.GetAt(Index); 
    m_LineArray_redo.SetAt(Index2+1,redoLine); 
    m_LineArray.RemoveAt(Index); 
} 
UpdateAllViews(0); 
SetModifiedFlag(); 
} 


void CKonokhovDoc::OnUpdateEditUndo(CCmdUI *pCmdUI) 
{ 
// TODO: Add your command update UI handler code here 
pCmdUI->Enable((int)m_LineArray.GetSize()); 

} 


void CKonokhovDoc::OnEditRedo() 
{ 
// TODO: Add your command handler code here 
int Index = (int)m_LineArray.GetUpperBound(); 
int Index2 = (int)m_LineArray_redo.GetUpperBound(); 
m_LineArray.SetAt(Index+1, m_LineArray_redo.GetAt(Index2)); 
m_LineArray_redo.RemoveAt(Index2); 
//redoLine = NULL; 
UpdateAllViews(0); 
SetModifiedFlag(); 
} 
+0

能否请您发布的代码作为文本? – Rakete1111

+0

@ Rakete1111是的,已经..! –

+0

谢谢!特别是它在哪里崩溃?当你撤消?或重做? – Rakete1111

回答

0

此代码工作正常

void CLab1_LeshikDoc::OnEditUndo() 
{ 
    int Index = (int)m_LineArray.GetUpperBound(); 
    int Index2 = (int)m_LineArray_redo.GetUpperBound(); 
    if (Index>-1) { 
     m_LineArray_redo.Add(m_LineArray.GetAt(Index)); 
     m_LineArray.RemoveAt(Index); 
    } 
    UpdateAllViews(0); 
    SetModifiedFlag(); 
} 


void CLab1_LeshikDoc::OnUpdateEditUndo(CCmdUI *pCmdUI) 
{ 
    pCmdUI->Enable((int)m_LineArray.GetSize()); 
} 

void CLab1_LeshikDoc::OnRedo() 
{ 
    int Index2 = (int)m_LineArray_redo.GetUpperBound(); 
      m_LineArray.Add(m_LineArray_redo.GetAt(Index2)); 
      m_LineArray_redo.RemoveAt(Index2); 
    UpdateAllViews(0); 
    SetModifiedFlag(); 
} 

void CLab1_LeshikDoc::OnUpdateRedo(CCmdUI *pCmdUI) 
{ 
    pCmdUI->Enable((int)m_LineArray.GetSize()); 
} 
+0

虽然代码只有答案可以解决原来的问题,但如果你给出了一些评论/解释,如你的行为和原因,它可以帮助他人阅读你的答案。 –