var
  HIC                : HIMC;
  Buffer             : pchar;
  BufferLen          : DWORD;
begin
  Result := '';
  HIC := ImmGetContext(Form1.handle);
  if hIC = 0 then Exit;
  BufferLen := ImmGetCompositionString(hIC, GCS_RESULTSTR, nil, 0);
  if BufferLen <= 0 then Exit;
  GetMem(Buffer, BufferLen +1);
  try
    if ImmGetCompositionString(HIC, GCS_RESULTSTR, Buffer, BufferLen) > 0 then
     begin
      Result := StrLCopy(Buffer, Buffer, BufferLen);
     end;
  finally
    FreeMem(Buffer, BufferLen +1);
    ImmReleaseContext(Form1.handle, HIC);
  end;
end;它可以得到中文,但是如果不键入新的字时,总反会上次的结果,能不能只得到一次结果?

解决方案 »

  1.   

    unit Unit3;interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,imm;
    type
      TForm3 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        procedure FormDestroy(Sender: TObject);
        procedure FormShow(Sender: TObject);  private
        FDefEditProc: TWndMethod;
        procedure EditWndProc(var Message: TMessage);
      public
      end;var
      Form3: TForm3;implementation
    {$R *.dfm}uses unit2;procedure TForm3.EditWndProc(var Message: TMessage);
    begin
        if  Message.Msg = WM_IME_COMPOSITION then
            Edit2.Text:=form2.GetIME;      //这里加入你的function
        if  Message.Msg = WM_KEYDOWN  then
            Edit2.Clear;                   //及时清空.
        FDefEditProc(Message);
    end;
    procedure TForm3.FormDestroy(Sender: TObject);
    begin
       Edit1.WindowProc := FDefEditProc;
    end;procedure TForm3.FormShow(Sender: TObject);
    begin
      FDefEditProc := Edit1.WindowProc;
      Edit1.WindowProc := EditWndProc;
    end;end.
      

  2.   

    我的意思是窗体上没有任何控件,通过imm得到中文输入
      

  3.   

    要得到系统有哪些输法不用这么麻烦吧!不知道下面的代码可不可以呢?
    var
      ImeList:TStrings;
    begin
      ImeList:=TStringLlist.create;
      ImeList.Assign(screen.Imes);//ImeList中就有你系统中所有的输入法呢!
    end;
      

  4.   

    楼上的,楼主所说的何你说的取得输入法不是一回事情.可以参考
    http://www.csdn.net/Develop/Article/15/15556.shtm
      

  5.   

    to laihecongxi(兴哥) 你给的连接打不开啊,
      

  6.   

    procedure T****.WMImeComposition(var Message: TMessage);
    var
      IMEContext: HIMC;
      P: PChar;
      Size: Integer;
    begin  NewString:='';
      if (Message.LParam and GCS_RESULTSTR) <> 0 then
      begin
        IMEContext := ImmGetContext(Handle);
        try
          Size := ImmGetCompositionString(IMEContext, GCS_RESULTSTR, nil, 0);
          Inc(Size, 1);  //加2还是加1
          GetMem(P,Size);
          try
            ImmGetCompositionString(IMEContext, GCS_RESULTSTR, P, Size);
            P[Size] := #0;
            NewString:=P;
          finally
            FreeMem(P);
          end;
        finally
          ImmReleaseContext(Handle, IMEContext);
        end;
        Message.Result := 0;
      end
      else inherited;
    end;
    newstring 就是了
      

  7.   

    to leaya11(lee) 还是不行啊,你怎么调用这个过程的啊