3

In my derived CEditEx class I use:

SetWindowText(strText);

Works fine and the control is updated.

But it does not support undo (CTRL + Z). If I manually type the change changes undo works.

Is there no way to trigger it to track undo?


Example function:

void CEditEx::Encode(const CString strTagOpen, const CString strTagClose)
{
    int iStartIndex{};
    int iEndIndex{};

    GetSel(iStartIndex, iEndIndex);
    if (iEndIndex > iStartIndex)
    {
        CString strText;
        GetWindowText(strText);

        strText.Insert(iStartIndex, strTagOpen);
        strText.Insert(iEndIndex + strTagOpen.GetLength(), strTagClose);

        SetWindowText(strText);

        SetSel(iStartIndex, iEndIndex + strTagOpen.GetLength() + strTagClose.GetLength());
    }
}
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 4
    `SetWindowText` doesn't support undo. Can you override `SetWindowText`? You can then call `edit.SetSel(0, -1); edit.ReplaceSel(strText, TRUE);` which does support undo. – Barmak Shemirani Mar 03 '23 at 18:52
  • @BarmakShemirani Thanks for the suggestion. I have updated my question with an example function in my derived `CEdit` class. I will try your idea. – Andrew Truckle Mar 03 '23 at 19:05
  • 1
    @BarmakShemirani I replaced the `SetWindowText` call with the two `SetSel` / `ReplaceSel` calls and it works OK. Thanks. – Andrew Truckle Mar 03 '23 at 19:29

0 Answers0