如果是处理输入法的话要处理输入法消息,给你写个例子.
例如,我要一个Form,在输入法输入结束后Caption就显示输入法输入的字符串
(注意,本例子焦点控件要是你的Form而不是Form上的其他控件)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
private
procedure WMIMECOMPOSITION(var Message: TMessage); message WM_IME_COMPOSITION;
public
end;
var
Form1: TForm1;
implementation
uses
imm;
{$R *.dfm}
procedure TForm1.WMIMECOMPOSITION(var Message: TMessage);
var
himc :Cardinal;
dwSize : DWORD;
Buf : String;
begin
if (Message.LParam and GCS_RESULTSTR) = GCS_RESULTSTR then //如果是输入结果
begin
himc := ImmGetContext(getactivewindow());
dwSize := ImmGetCompositionString(himc, GCS_RESULTSTR, nil, 0);
SetLength(Buf, dwSize);
ImmGetCompositionString(himc, gcs_resultstr, PChar(buf), dwsize);
ImmReleaseContext(GetActiveWindow, himc);
Caption := Buf;
end;
Inherited;
end;
end.