在捕获tab按键消息时修改执行,获取光标位置,在该位置按Tab时输出两个空格,当前位置后移两位出错
if ((VK_TAB == pMsg->wParam) && (WM_KEYDOWN == pMsg->message) && (pMsg->hwnd == GetSafeHwnd()))
{
CString strContent;//视图内容
long lBegin = 0;
long lEnd = 0;
GetRichEditCtrl().GetSel(lBegin, lEnd); //当前光标位置
GetRichEditCtrl().GetWindowText(strContent);
if (lBegin != lEnd)
{
strContent = strContent.Left(lBegin) + strContent.Mid(lEnd);
}
strContent.Insert(lBegin, " ");
GetRichEditCtrl().SetWindowText(strContent);
GetRichEditCtrl().SetSel(lBegin + 2, lBegin + 2);
return TRUE;
}
执行结果:
在6前面回车,然后再按Tab就变成下图情况了