HWND hFocus;
HWND hWnd;
hWnd = ::GetForegroundWindow(); // 得到当前窗口
// if (hWnd == this->m_hWnd) return; // 排除程序本身的窗口
DWORD FormThreadID = ::GetCurrentThreadId(); // 本程序的线程ID
// 当前窗口的线程ID
DWORD CWndThreadID = ::GetWindowThreadProcessId(hWnd, NULL);
// 附加输入线程
AttachThreadInput(CWndThreadID, FormThreadID, true);
// 得到当前键盘光标所在的窗口
hFocus = ::GetFocus();
// 取消附加的输入线程
if(hFocus)
{
long style=::GetWindowLong(hFocus,GWL_STYLE);
if(style & ES_PASSWORD)
MessageBox("是个密码框");
}
char wchar[2];
wchar[1]=0xBC;
wchar[0]=0xC6;
// HIMC hIMC=0x000600f6;
DWORD dwSize;
HIMC hIMC = ImmGetContext( hFocus );
unsigned char str[ MAX_PATH ];
dwSize = ImmGetCompositionString( hIMC, GCS_COMPATTR, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_COMPCLAUSE, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_COMPREADATTR, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_COMPREADCLAUSE, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_COMPREADSTR, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_COMPSTR, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_CURSORPOS, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_DELTASTART, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_RESULTCLAUSE, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_RESULTREADCLAUSE, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_RESULTREADSTR, (void*)str, sizeof( str ));//取得汉字输入串
dwSize = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void*)str, sizeof( str ));//取得汉字输入串
unsigned char *p = str;
char *szOut="计算机";
// ImmConversionList
// NotifyIME
::ImmSetCompositionString(hIMC,SCS_SETSTR ,NULL,0,"中文",strlen("中文"));
dwSize = ImmGetCompositionString( hIMC, GCS_RESULTSTR, NULL,NULL);
str[ dwSize ] = 0;
// ::PostMessage(hWnd,WM_IME_COMPOSITION,0,GCS_COMPSTR);
// ::PostMessage(hWnd,WM_IME_COMPOSITION,0,GCS_RESULTSTR);
dwSize = ImmGetCompositionString( hIMC, GCS_RESULTSTR, (void*)str, sizeof( str ));//取得汉字输入串
// if(strlen((LPCSTR)(str) )> 0)
// ::PostMessage(hFocus,WM_IME_COMPOSITION,*(unsigned short *)wchar,0x1dbf);
ImmReleaseContext(hWnd,hIMC);
AttachThreadInput(CWndThreadID, FormThreadID, false);
::ImmSetCompositionString(hIMC,SCS_SETSTR ,NULL,0,"中文",strlen("中文"));
这一句可以设置输入列表窗口的当前选择字符。