K
K
kurumpa2015-01-10 18:21:51
C++ / C#
kurumpa, 2015-01-10 18:21:51

What recipient should be specified for the WM_INPUTLANGCHANGEREQUEST message?

In my layout switcher, I encountered the problem of switching layouts in Skype (judging by the reviews, this is not the only program in which this behavior is observed). The problem is rather strange: if there is only one letter in the message box, everything works as it should, otherwise the WM_INPUTLANGCHANGEREQUEST message is not processed. Message sending code:

public static void SetNextKeyboardLayout()
    {
        IntPtr hWnd = GetForegroundWindow();
        uint processId;
        uint activeThreadId = GetWindowThreadProcessId(hWnd, out processId);
        uint currentThreadId = GetCurrentThreadId();

        AttachThreadInput(activeThreadId, currentThreadId, true);
        IntPtr focusedHandle = GetFocus();
        AttachThreadInput(activeThreadId, currentThreadId, false);

        PostMessage(focusedHandle == IntPtr.Zero ? hWnd : focusedHandle, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, HKL_NEXT);
    }

focusedHandle was made for WPF applications, without this piece the layout does not switch in them. I suspect that I am incorrectly specifying the recipient of the message. It's just that GetForegroundWindow() doesn't work, nor does any combination of GetParentWindow(). Where should this message be sent?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-01-13
@rdifb0

In my switch, I use this piece of code (collected from the world by thread)

void function()
{
  var threadInfo = new WinAPI.GUITHREADINFO();
  threadInfo.cbSize = Marshal.SizeOf(threadInfo);
  WinAPI.GetGUIThreadInfo(0, ref threadInfo);

  IntPtr hWnd = (threadInfo.hwndFocus != IntPtr.Zero) ? threadInfo.hwndFocus : threadInfo.hwndActive;
  WinAPI.PostMessage(hWnd, WinAPI.WM_INPUTLANGCHANGEREQUEST, WinAPI.WM_INPUTLANGCHANGE_SYSCHARSET, (int)_seconLayot);
}

where WinAPI is just a class with described structures and Dll imports. I don't have any issues with switching.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question