//下面的代码用来屏蔽某一个控件的输入法状态。
HIMC m_hImc; // 全局或者成员变量
// Function for Disabling IME
void CMyDialog::DisableIME()
{
HWND hWnd = GetDlgItem(IDC_EDIT1)->m_hWnd;
if (hWnd && IsWindow(hWnd))
{
// Get input context for backup.
m_hImc = ImmGetContext(hWnd);
// Remove association the testing
if (m_hImc)
ImmAssociateContext(hWnd, NULL);
// Release input context
ImmReleaseContext(hWnd, m_hImc);
::SetFocus(hWnd);
}
}
// Function for Enabling IME
void CMyDlg::EnableIME()
{
HWND hWnd = GetDlgItem(IDC_EDIT1)->m_hWnd;
if (hWnd && IsWindow(hWnd))
{
// Enable IME
if (m_hImc)
{
// Associate the input context with testing window
ImmAssociateContext(hWnd, m_hImc);
m_hImc = NULL;
}
::SetFocus(hWnd);
}
}