开发者

Can a CRichEditCtrl know when someone sets its text?

When typing into a CRichEditCtrl, EN_CHANGE messages are generated. However MSDN says:

Rich Edit: Supported in Microsoft Rich Edit 1.0 and later. To receive EN_CHANGE notifications, specify ENM_CHANGE in the mask sent with the EM_SETEVENTMASK message. For information about the compatibility of rich edit versions with the various system versions, see About Rich Edit Controls.

The EN_CHANGE notification is not sent when the ES_MULTILINE style is used and the text is sent through WM_SETTEXT.

I have several dialogs using a multi-line rich开发者_运维知识库 edit control, actually my custom CMyRichEdit class. That class automatically performs analysis when the text changes, but in the important case where the dialog is initially populated, no notification is seen.

The point is to avoid having to change our code-base more than absolutely necessary - the new control is being dropped in to replace existing ones. Chasing down every instance where getDlgItem(IDC_EDIT)->SetWindowText is used, or where DDX_Text(pDX, IDC_EDIT, m_strEdit) automatically links a string contents with the control, would mean a lot of trawling through code and re-testing everything altered.

Is there an easy way? Can MyRichEdit catch its own WM_SETTEXT messages?


ON_MESSAGE(WM_SETTEXT, OnSetText)

// fires every time someone calls SetWindowText
LRESULT MyRichEditCtrl::OnSetText(WPARAM wParam, LPARAM lParam)
{
    return CWnd::Default();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜