在CRichEdit中使用Alt + Unicode更改插入的字符 [英] Change char inserted using Alt+Unicode in CRichEdit
问题描述
我想从键盘更改使用Alt + Unicode代码插入的unicode字符。
我使用PretranslateMessage来更改直接从键盘插入的字符,它工作。但是使用Alt + Unicode代码方法它不。
以下是代码:
当启用显示/隐藏段落标记时,Microsoft Word具有此功能。
I want to change a unicode char inserted using Alt+Unicode code from the keyboard. I used PretranslateMessage for changing the chars inserted directly from the keyboard and it worked. But with the Alt+Unicode code method it does not. Here is the code: Microsoft Word has this functionality when enabling show/hide paragraph marks.
BOOL CEmphasizeEdit::PreTranslateMessage(MSG* msg)
{
if (msg->hwnd == m_hWnd)
{
if (msg->message == WM_CHAR)
{
if (TheApp.Options.m_bShowWSpaceChars)
{
if (msg->wParam == ' ') // This works in both cases Space key pressed or Alt + 3 + 2 in inserted
{
msg->wParam = '·';
}
else if (msg->wParam == (unsigned char)' ') // this does not work
{
msg->wParam = (unsigned char)'°';
}
}
}
}
return CRichEditCtrl::PreTranslateMessage(msg);
}
如果我从键盘Alt + 0 + 1 + 6 + 0插入是''(无中断空格),我想CRichEditCtrl显示'°'或另一个我指定的字符。
If I insert from the keyboard Alt + 0 + 1 + 6 + 0 which is ' '(No-Break Space), I want the CRichEditCtrl to display '°' or another char that I specify.
如何处理这个工作?
推荐答案
我必须得到光标位置发送一个追加字符串到控件,然后设置选择后插入字符。当这发生我必须跳过CRichEditCtrl :: PreTranslateMessage(msg);
I had to get the cursor position send an append string to the control and then set the selection after the inserted character. When this happens I have to skip CRichEditCtrl::PreTranslateMessage(msg);
BOOL CEmphasizeEdit::PreTranslateMessage(MSG* msg)
{
if (msg->hwnd == m_hWnd)
{
if (msg->message == WM_CHAR)
{
TCHAR text[2];
text[1] = 0x00;
BOOL found = 1;
switch (msg->wParam)
{
case 0x20: text[0] = _C('·'); break;
case 0xA0: text[0] = 0xB0; break;
}
CHARRANGE cr;
GetSel(cr);
cr.cpMax++;
cr.cpMin++;
ReplaceSel(text);
SetSel(cr);
return 1;
}
}
return CRichEditCtrl::PreTranslateMessage(msg);
}
这篇关于在CRichEdit中使用Alt + Unicode更改插入的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!