Andrew Truckle
Andrew Truckle

Reputation: 19087

Using Undo with CEdit and SetWindowText

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());
    }
}

Upvotes: 3

Views: 105

Answers (0)

Related Questions