MFC 禁用输入法

时间:2024-03-03 19:44:54
#include <Imm.h>

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);
    }
}