TSF输入法列表获取

TSF:
Microsoft Windows 文本服务框架(TSF) 是一个包含在Windows XP 及其后继版本操作系统的系统服务。TSF为高级文本输入的通信以及自然语言技术提供了一个简单的可扩展的框架。
以上引自百度百科

引用Winapi.MsCTF单元,如果没有去高版本XE里面搜一搜,或者百度一下。


procedure TForm1.btnSTFClick(Sender: TObject);
var
  profiles: PPTfInputProcessorProfiles;
  Iprofiles: ITfInputProcessorProfiles;
  plangid: Word;
  enumerator: IEnumTfLanguageProfiles;
  langProfile: TF_LANGUAGEPROFILE;
  FetchedItems: Cardinal;
  pbstrProfile: WideString;
  pfEnable: Integer;
begin
  if not IsMSCTFAvailable() then
    Exit;

  if (TF_CreateInputProcessorProfiles(profiles) = (S_OK) then
  begin
    Iprofiles := ITfInputProcessorProfiles(profiles^);
    Iprofiles.GetCurrentLanguage(plangid);
    Memo1.Lines.Add(IntToStr(plangid));

    if plangid > -1 then
    begin
      Iprofiles.EnumLanguageProfiles(plangid, enumerator);

      if Assigned(enumerator) then
      begin
        enumerator.Next(1, langProfile, FetchedItems);
        while FetchedItems > 0 do
        begin
          //          Memo1.Lines.Add(langProfile.clsid.ToString());
          //          Memo1.Lines.Add(langProfile.langid.ToString());
          //          Memo1.Lines.Add(langProfile.fActive.ToString());  // -1时为当前激活输入法

          pbstrProfile := '';
          if Iprofiles.GetLanguageProfileDescription(langProfile.clsid, langProfile.langid, langProfile.guidProfile, pbstrProfile) = S_OK then
          begin
            //Memo1.Lines.Add(pbstrProfile);
            if Iprofiles.IsEnabledLanguageProfile(langProfile.clsid, langProfile.langid, langProfile.guidProfile, pfEnable) = S_OK then
            begin
              if pfEnable = 1 then
              begin
                //显示TSF输入法名称
                Memo1.Lines.Add(pbstrProfile);

                //激活指定输入法(clsid、 guidProfile为空时,取消激活)
                if pbstrProfile = '微软ABC' then
                  Iprofiles.ActivateLanguageProfile(langProfile.clsid, langProfile.langid, langProfile.guidProfile);
              end;
            end;  
          end;

          enumerator.Next(1, langProfile, FetchedItems);
        end;
      end;

    end;

  end;

end;


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值