TSFとは
Text Services Frameworkの略。
Microsoft WindowsのインプットメソッドAPIであるInput Method Manager (IMM32) の後継となる汎用テキスト入力フレームワーク。
Windows Vista以降、IMM32に代わりTSFが使用されるようになっている。
IMM32APIを使用したアプリケーションが動作するよう、IMM32をエミュレーションしてTSFと接続する CUAS (Cicero Unaware Application Support) が存在する。
これにより、VistaでもImm32ベースのIM(ATOKなど)が動作する。
IMM32APIの互換性
ImmGetDescription の代替え
IMM32APIのImmGetDescription関数は、エミュレーションによっても互換性がない。
TSFでIMの名称を取得するには、ITfInputProcessorProfiles クラスのGetLanguageProfileDescription メソッドを使用する。
BOOL result = TRUE;
PWCHAR pszDescription = NULL;
UINT nDescriptionSize;
ITfInputProcessorProfiles* pInputProcessorProfiles = NULL;
ITfInputProcessorProfileMgr* pInputProcessorProfileMgr = NULL;
IEnumTfInputProcessorProfiles* pEnumInputProcessorProfiles = NULL;
TF_INPUTPROCESSORPROFILE profile;
TF_INPUTPROCESSORPROFILE* pProfile = &profile;
HRESULT hr;
BSTR bstrProfile = NULL;
ZeroMemory(pProfile, sizeof(TF_INPUTPROCESSORPROFILE));
ZeroMemory(pProfileMSIME, sizeof(TF_INPUTPROCESSORPROFILE));
try{
// ITfInputProcessorProfiles インターフェイスを取得する
hr = CoCreateInstance(
CLSID_TF_InputProcessorProfiles,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITfInputProcessorProfiles,
(LPVOID*)&pInputProcessorProfiles);
if (hr != S_OK){
throw 0;
}
// ITfInputProcessorProfileMgr インターフェイスを取得する
hr = pInputProcessorProfiles->QueryInterface(
IID_ITfInputProcessorProfileMgr,
(LPVOID*)&pInputProcessorProfileMgr);
if (hr != S_OK){
throw 0;
}
// 日本語のTF_INPUTPROCESSORPROFILEの列挙を取得する
hr = pInputProcessorProfileMgr->EnumProfiles(1041, &pEnumInputProcessorProfiles);
if (hr != S_OK){
throw 0;
}
while ( (hr = pEnumInputProcessorProfiles->Next(1, pProfile, NULL)) == S_OK ){
if (pProfile->dwProfileType == TF_PROFILETYPE_INPUTPROCESSOR){
if (pProfile->catid == GUID_TFCAT_TIP_KEYBOARD){
// TSF
hr = pInputProcessorProfiles->GetLanguageProfileDescription(
pProfile->clsid,
pProfile->langid,
pProfile->guidProfile,
&bstrProfile);
if (hr != S_OK){
continue;
}
}else if (pProfile->dwProfileType == TF_PROFILETYPE_KEYBOARDLAYOUT){
// Keybord layout
nDescriptionSize = ImmGetDescription(pProfile->hkl, NULL, 0) + 1;
if(pszDescription != NULL){
delete [] pszDescription;
pszDescription = NULL;
}
pszDescription = new WCHAR[nDescriptionSize];
memset(pszDescription, 0x00, sizeof(WCHAR) * nDescriptionSize);
ImmGetDescription(pProfile->hkl, pszDescription, nDescriptionSize);
}
}
}catch(...){
result = FALSE;
}
if(pszDescription != NULL){
delete [] pszDescription;
}
最終更新:2011年09月27日 17:12