在窗口的FormShow 事件中用screen.Imes取得输入法后,窗口的每个文本框虽然取得了相应的输入法,但一旦用户改变改变输入法后,就不适用了。有什么方法使得以后的输入是用户改更后的输入法。

解决方案 »

  1.   

    能不能保存在INI中,下次再读取他
      

  2.   

    //看看VCL中Screen.Imes怎么取得的,自己照着改~~procedure TForm1.Button1Click(Sender: TObject);
    const
      KbLayoutRegkeyFmt = 'System\CurrentControlSet\Control\Keyboard Layouts\%.8x';  // do not localize
      KbLayoutRegSubkey = 'layout text'; // do not localize
    var
      TotalKbLayout, I, Bufsize: Integer;
      KbList: array[0..63] of HKL;
      qKey: HKey;
      ImeFileName: array [Byte] of Char;
      RegKey: array [0..63] of Char;
      Imes: TStringList;
    begin
      Imes := TStringList.Create;
      try
        TotalKbLayout := GetKeyboardLayoutList(64, KbList);
        for I := 0 to TotalKbLayout - 1 do
        begin
          if Imm32IsIME(KbList[I]) then
          begin
            if RegOpenKeyEx(HKEY_LOCAL_MACHINE,
              StrFmt(RegKey, KbLayoutRegKeyFmt, [KbList[I]]), 0, KEY_READ,
              qKey) = ERROR_SUCCESS then
            try
              Bufsize := SizeOf(ImeFileName);
              if RegQueryValueEx(qKey, KbLayoutRegSubKey, nil, nil,
                   @ImeFileName, @Bufsize) = ERROR_SUCCESS then
              begin
                Imes.AddObject(ImeFileName, TObject(KbList[I]));
              end;
            finally
              RegCloseKey(qKey);
            end;
          end;
        end;
        Imes.Duplicates := dupIgnore;
        Imes.Sorted := True;
        Memo1.Lines.Assign(Imes); //输出
      finally
        Imes.Free;
      end;
    end;