Input Method Manager Functions - correct call order for Hiragana to Kanji candidates list c++ covnersion

404 views Asked by At

I'm trying to convert the Hiaragana characters to candidates list (Kanji). Looks like it should be possible by using the Input Method Manager Functions but it doesn't work as I expected.
I installed the Japanese Language pack and I'm able to open IME in the text editor so some functionalities should be enabled.

In src we have sth like:

HIMC context = ImmCreateContext();//non-NULL result
bool result = ImmSetOpenStatus(context, true);//result == true
std::wstring wstr = L"こいび";//Hiragana string for conversion
result = ImmSetConversionStatus(context, IME_CMODE_JAPANESE, IME_SMODE_NONE);//result == true
result = ImmSetCompositionString(context, SCS_SETSTR, (LPVOID)wstr.c_str(), wstr.length(), NULL, 0);//result == true
DWORD listCount = 0;
DWORD lpdResult = 0;
lpdResult = ImmGetCandidateListCount(context, &listCount);//listCount == 0, lpdResult  == 144

Looks like it works somehow but I'm always getting similar results (I checked it for standard letters, shorter JPN string and by creating std::string + conversion to wstring).
Unfortunately I didn't found example related to it so maybe I didn't call something or I called something in wrong order.
The MS documentation contains not too much details about it so I'm not sure what's wrong.

1

There are 1 answers

0
huinalam On

Imm function must use in window message loop.

for example, https://learn.microsoft.com/en-us/windows/desktop/api/Imm/nf-imm-immgetcandidatelistcounta look remark part.

"Applications typically call this function in response to an IMN_OPENCANDIDATE or IMN_CHANGECANDIDATE command."

when message loop type is "IMN_OPENCANDIDATE" or "IMN_CHANGECANDIDATE", you can use immgetcandidatelistcount function.