修改输入法源码 - 日文输入法例

整理日: 2015年2月16日


enum _IME_Mode
{
    _IME_Off = 1, 
    _IME_Hiragana, 
    _IME_Katakana, 
    _IME_Alpha, 
    _IME_KatakanaHalf,
    _IME_AlphaHalf
};

void SetImeConversionStatus(HWND hwnd, _IME_Mode mode)
{
    HIMC hImc = ImmGetContext(hwnd);

    if (mode == _IME_Off)
    {
        // IMEオフ
        ImmSetOpenStatus(hImc, FALSE);
    } else
    {
        ImmSetOpenStatus(hImc, TRUE);
        DWORD dwConversion = 0;
        DWORD dwSentence = 0;
        ImmGetConversionStatus(hImc, &dwConversion, &dwSentence);
        switch (mode)
        {
        case _IME_Hiragana: // ひらがな
            dwConversion |= IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
            dwConversion &= ~IME_CMODE_KATAKANA;
            break;
        case _IME_Katakana: // 全角カタカナ
            dwConversion |=
                IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE | IME_CMODE_KATAKANA;
            break;
        case _IME_Alpha: // 全角英数
            dwConversion |= IME_CMODE_FULLSHAPE;
            dwConversion &= ~(IME_CMODE_NATIVE | IME_CMODE_KATAKANA);
            break;
        case _IME_KatakanaHalf: // 半角カタカナ
            dwConversion |= IME_CMODE_NATIVE | IME_CMODE_KATAKANA;
            dwConversion &= ~IME_CMODE_FULLSHAPE;
            break;
        case _IME_AlphaHalf: // 半角英数
            dwConversion &=
                ~(IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE | IME_CMODE_KATAKANA);
            break;
        default:
            break;
        }
        ImmSetConversionStatus(hImc, dwConversion, dwSentence);
    }
    ImmReleaseContext(hwnd, hImc);
}

你可能感兴趣的:(输入法)