与中文输入相关的函数
2004-10-26 18:57
253 查看
unit Ime;
{=======================================================================
DESIGN BY : 彭国辉
DATE: 2004-10-12
SITE: http://kacarton.yeah.net/
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton@sohu.com
文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
========================================================================}
interface
uses IMM, Windows;
procedure ImmActive(hWindows: THandle; bChinese: Boolean); //打开或关闭输入法
procedure ImmEnabled(hWindows: THandle; bChinese: Boolean); //允许或禁止输入法
procedure SendDBCSString(hFocus: HWND; const Text: string); //向控件发送中文文本
implementation
//打开或关闭输入法,EX:ImeActive(0, true);
//网上可以搜索到类似的代码,不过用的是IME_THOTKEY_IME_NONIME_TOGGLE,只对繁体版中文Windows有效,用在简体中文Windows下当然不行了
procedure ImmActive(hWindows: THandle; bChinese: Boolean);
begin
if hWindows=0 then hWindows := GetFocus;
if hWindows=0 then Exit;
if ImmIsIME(GetKeyboardLayOut(0)) <> bChinese then
ImmSimulateHotKey(hWindows, IME_CHOTKEY_IME_NONIME_TOGGLE);
end;
//允许与禁止输入法,EX:ImmEnabled(Edit1.Handle, true)
//等效于把Edit1.ImeMode设为imChinese(True)、imClose(False)
procedure ImmEnabled(hWindows: THandle; bChinese: Boolean);
var
hImmc: HIMC;
begin
if hWindows=0 then hWindows := GetFocus;
if hWindows=0 then Exit;
hImmc := ImmGetContext(hWindows);
ImmSetOpenStatus(hImmc, bChinese);
end;
//向控件发送中文文本,EX:SendDBCSString(Edit1.Handle, '哗,终于可以发中文啦!')
procedure SendDBCSString(hFocus: HWND; const Text: string);
var
i: integer;
ch: byte;
begin
if hFocus = 0 then hFocus := GetFocus;
if hFocus = 0 then Exit;
i := 1;
while i <= Length(Text) do begin
ch := byte(Text[i]);
if Windows.IsDBCSLeadByte(ch) then begin
Inc(i);
SendMessage(hFocus, WM_IME_CHAR, MakeWord(byte(Text[i]), ch), 0);
end
else SendMessage(hFocus, WM_IME_CHAR, word(ch), 0);
Inc(i);
end;
end;
end.
{=======================================================================
DESIGN BY : 彭国辉
DATE: 2004-10-12
SITE: http://kacarton.yeah.net/
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton@sohu.com
文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
========================================================================}
interface
uses IMM, Windows;
procedure ImmActive(hWindows: THandle; bChinese: Boolean); //打开或关闭输入法
procedure ImmEnabled(hWindows: THandle; bChinese: Boolean); //允许或禁止输入法
procedure SendDBCSString(hFocus: HWND; const Text: string); //向控件发送中文文本
implementation
//打开或关闭输入法,EX:ImeActive(0, true);
//网上可以搜索到类似的代码,不过用的是IME_THOTKEY_IME_NONIME_TOGGLE,只对繁体版中文Windows有效,用在简体中文Windows下当然不行了
procedure ImmActive(hWindows: THandle; bChinese: Boolean);
begin
if hWindows=0 then hWindows := GetFocus;
if hWindows=0 then Exit;
if ImmIsIME(GetKeyboardLayOut(0)) <> bChinese then
ImmSimulateHotKey(hWindows, IME_CHOTKEY_IME_NONIME_TOGGLE);
end;
//允许与禁止输入法,EX:ImmEnabled(Edit1.Handle, true)
//等效于把Edit1.ImeMode设为imChinese(True)、imClose(False)
procedure ImmEnabled(hWindows: THandle; bChinese: Boolean);
var
hImmc: HIMC;
begin
if hWindows=0 then hWindows := GetFocus;
if hWindows=0 then Exit;
hImmc := ImmGetContext(hWindows);
ImmSetOpenStatus(hImmc, bChinese);
end;
//向控件发送中文文本,EX:SendDBCSString(Edit1.Handle, '哗,终于可以发中文啦!')
procedure SendDBCSString(hFocus: HWND; const Text: string);
var
i: integer;
ch: byte;
begin
if hFocus = 0 then hFocus := GetFocus;
if hFocus = 0 then Exit;
i := 1;
while i <= Length(Text) do begin
ch := byte(Text[i]);
if Windows.IsDBCSLeadByte(ch) then begin
Inc(i);
SendMessage(hFocus, WM_IME_CHAR, MakeWord(byte(Text[i]), ch), 0);
end
else SendMessage(hFocus, WM_IME_CHAR, word(ch), 0);
Inc(i);
end;
end;
end.
相关文章推荐
- HALCON视觉算子相关函数中文说明System(2)
- C语言第六回合:输入输出相关出函数大集合
- 输入m个学生,每个学生有4门课,在主调函数中输入学生的相关信息,编写三个函数: (1)求第一门课的平均分; (2)找出有两门课以上不及格的学生,并输出他们的学号和全部成绩,要求用指针函数实现:fl
- 郁闷中,做java的中文输入相关
- C++中与输入相关的istream类成员函数简介
- [导入]判断输入是否为中文的函数
- 判断输入是否为中文的函数
- 设计函数,输入为一个字符串,里边包含中文、英文、数字等字符,编码为GBK。中文字符的编码规则假定为:双字节组成,高字节大于0x80,低字节任意。
- 处理中文字符相关的函数
- 写一个函数, 2个参数, 1个字符串, 1个字节数,返回截取的字符串,要 求字符串中的中文不能出现乱码: 如 ( “ 我ABC”, 4) 应该截为 “ 我AB”,输入( “ 我 ABC汉DEF”, 6
- C++的输入cin函数的相关用法1
- JavaScript 判断输入是否为中文的函数
- 输入函数相关博客学习总结
- 输入相关函数
- WinAPI: 输入光标相关的函数[2]
- xdebug中文手册之相关函数
- WinAPI: 输入光标相关的函数[3]
- 判断输入是否为中文的函数
- STL中流相关的输入输出符和get函数彻底总结:cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- 纯汇编NASM源码/显示相关函数/10H中断/纯汇编显示汉字/显示中文