function GetIMEList(slRet: TStrings; OnlyEnabled: Boolean = True): Boolean; var pProfiles: PTfInputProcessorProfiles; IProfiles: ITfInputProcessorProfiles; LangId: Word; EnumProfiles: IEnumTfLanguageProfiles; LangProfile: TF_LANGUAGEPROFILE; FetchedItems: Cardinal; strProfile: WideString; nEnabled: Integer; hRet: HRESULT; begin Result:= False;
if not IsMSCTFAvailable() then Exit;
hRet:= TF_CreateInputProcessorProfiles(@pProfiles); if not Succeeded(hRet) then Exit;
IProfiles := ITfInputProcessorProfiles(pProfiles); LangId:= 0; IProfiles.GetCurrentLanguage(LangId); if LangId = Word(-1) then Exit;
EnumProfiles:= nil; IProfiles.EnumLanguageProfiles(LangId, EnumProfiles); if EnumProfiles = nil then Exit;
slRet.Clear; EnumProfiles.Next(1, LangProfile, FetchedItems); while FetchedItems > 0 do begin strProfile := ''; hRet:= IProfiles.GetLanguageProfileDescription(LangProfile.clsid, LangProfile.langid, LangProfile.guidProfile, strProfile); if Succeeded(hRet) then begin if OnlyEnabled then begin nEnabled:= 0; hRet:= IProfiles.IsEnabledLanguageProfile(LangProfile.clsid, LangProfile.langid, LangProfile.guidProfile, nEnabled);
if Succeeded(hRet) and (nEnabled = 1) then slRet.Add(strProfile); end else begin slRet.Add(strProfile); end; end; EnumProfiles.Next(1, langProfile, FetchedItems); end; end;
function SetIMEName(slRet: String): Boolean; var pProfiles: PTfInputProcessorProfiles; IProfiles: ITfInputProcessorProfiles; LangId: Word; EnumProfiles: IEnumTfLanguageProfiles; LangProfile: TF_LANGUAGEPROFILE; FetchedItems: Cardinal; strProfile: WideString; nEnabled: Integer; hRet: HRESULT; begin Result:= False;
if not IsMSCTFAvailable() then Exit;
hRet:= TF_CreateInputProcessorProfiles(@pProfiles); if not Succeeded(hRet) then Exit;
IProfiles := ITfInputProcessorProfiles(pProfiles); LangId:= 0; IProfiles.GetCurrentLanguage(LangId); if LangId = Word(-1) then Exit;
EnumProfiles:= nil; IProfiles.EnumLanguageProfiles(LangId, EnumProfiles); if EnumProfiles = nil then Exit;
EnumProfiles.Next(1, LangProfile, FetchedItems); while FetchedItems > 0 do begin strProfile := '';
hRet:= IProfiles.GetLanguageProfileDescription(LangProfile.clsid, LangProfile.langid, LangProfile.guidProfile, strProfile); if Succeeded(hRet) then begin if strProfile=slRet then begin //slRet.Add(strProfile); ActivateLanguageProfile IProfiles.ActivateLanguageProfile(LangProfile.clsid, LangProfile.langid, LangProfile.guidProfile); result:=True; Break; end; end; EnumProfiles.Next(1, langProfile, FetchedItems); end; end; 设置输入法的
----------------------------------------------
qq:171833017,靖源软件http://www.dxmylove.com
想关闭输入法,可以使用如下代码。 if Name = '' then begin ALangID := $0409; IProfiles.ChangeCurrentLanguage(ALangID); exit; end;
----------------------------------------------
(C)(P)Flying Wang