如何在Windows

时间:2018-06-19 07:29:43

标签: c++ input

我尝试使用SetWindowsHook,但它在Win7 / Win10中不起作用。我不知道为什么?如果这不可能,有没有其他方法来获取当前输入法的名称?

 LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    PMSG pmsg = (PMSG)lParam;
    if (nCode == HC_ACTION)
    {
        switch (pmsg->message)
        {
        case WM_IME_COMPOSITION:
            {
                HIMC hIMC;
                HWND hWnd = pmsg->hwnd;
                DWORD dwSize;
                char lpstr[20];
                if (pmsg->lParam & GCS_RESULTSTR)
                {

                    hIMC = ImmGetContext(hWnd);

                    dwSize = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0);

                    dwSize += sizeof(WCHAR);

                    memset(lpstr, 0, 20);

                    ImmGetCompositionString(hIMC, GCS_RESULTSTR, lpstr, dwSize);

                    writefile(lpstr);      

                    ImmReleaseContext(hWnd, hIMC);
                }
            }
            break;


        }
    }
    LRESULT lResult = CallNextHookEx(g_hHook, nCode, wParam, lParam);

    return(lResult);
}

0 个答案:

没有答案