在duilib开发中,小伙伴会因为CEditUI的各种问题,而转为使用CRichEditUI来代替。但是CRichEditUI控件却不支持文字变化通知事件,下面通过简单几行代码让RichEdit支持文字变化事件。
在UIRichEdith.cpp文件中搜索::OnTxNotify,然后使用以下代码替换此函数:
void CRichEditUI::OnTxNotify(DWORD iNotify, void *pv)
{
switch(iNotify)
{
case EN_CHANGE:
{
GetManager()->SendNotify(this, DUI_MSGTYPE_TEXTCHANGED);
break;
}
case EN_DROPFILES:
case EN_MSGFILTER:
case EN_OLEOPFAILED:
case EN_PROTECTED:
case EN_SAVECLIPBOARD:
case EN_SELCHANGE:
case EN_STOPNOUNDO:
case EN_LINK:
case EN_OBJECTPOSITIONS:
case EN_DRAGDROPDONE:
{
if(pv)
{
LONG nId = GetWindowLong(this->GetManager()->GetPaintWindow(), GWL_ID);
NMHDR *phdr = (NMHDR *)pv;
phdr->hwndFrom = this->GetManager()->GetPaintWindow();
phdr->idFrom = nId;
phdr->code = iNotify;
if(SendMessage(this->GetManager()->GetPaintWindow(), WM_NOTIFY, (WPARAM) nId, (LPARAM) pv))
{
}
}
}
break;
}
}
好了,需要的小伙伴赶紧试试吧!
duilib开源项目圈QQ群:261675375
最新代码托管地址:https://github.com/qdtroy/DuiLib_Ultimate