***********百度贴吧抄的代码,用了部分c和c++,输入的数据保存在string类型中
#include <graphics.h>
#include <conio.h>
#include <windows.h>
#include <string>
#pragma comment(lib,"Imm32.lib")
using namespace std;
void GetIMEString(HWND hWnd, string& str)
{
HIMC hIMC = ImmGetContext(hWnd);//获取HIMC
if (hIMC)
{
//这里先说明一下,以输入“中国”为例
//切换到中文输入法后,输入“zhongguo”,这个字符串称作IME组成字符串
//而在输入法列表中选择的字符串“中国”则称作IME结果字符串
static bool flag = false;//输入完成标记:在输入中时,IME组成字符串不为空,置true;输入完成后,IME组成字符串为空,置false
DWORD dwSize = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0); //获取IME组成输入的字符串的长度
if (dwSize > 0)//如果IME组成字符串不为空,且没有错误(此时dwSize为负值),则置输入完成标记为true
{
if (flag == false)
{
flag = true;
}
}
else if (dwSize == 0 && flag) //如果IME组成字符串为空,并且标记为true