case WM_IME_COMPOSITION: if (lParam & GCS_RESULTSTR) { hIMC = ImmGetContext(hWnd);
If (!hIMC) MyError(ERROR_NULLCONTEXT);
// Get the size of the result string. dwSize = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0);
// increase buffer size for terminating null character, // maybe it is in UNICODE dwSize += sizeof(WCHAR);
hstr = GlobalAlloc(GHND,dwSize); if (hstr == NULL) MyError(ERROR_GLOBALALLOC);
lpstr = GlobalLock(hstr); if (lpstr == NULL) MyError(ERROR_GLOBALLOCK);
// Get the result strings that is generated by IME into lpstr. ImmGetCompositionString(hIMC, GCS_RESULTSTR, lpstr, dwSize); ImmReleaseContext(hWnd, hIMC);
// add this string into text buffer of application
GlobalUnlock(hstr); GlobalFree(hstr); }
IME和Unicode
Windows 98/Me、Windows NT/2000/XP:在原先支持ANSI界面的基础上,Windows增加了IME对Unicode界面的支持。Windows 98/Me支持除了ImmIsUIMessage之外所有的Unicode函数,同时在Windows 98/Me系统中所有的消息都是基于ANSI的。因为Windows 98/Me不支持Unicode消息,应用程序可以使用ImmGetCompositionString函数从Windows 98/Me上基于Unicode的IME处获取Unicode字符。