2016-09-19 95 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

雖然代碼只有答案可以解決原來的問題,但如果你給出了一些評論/解釋,如你的行爲和原因,它可以幫助他人閱讀你的答案。 –