YYTan
YYTan

Reputation: 511

Custom keyboard with Korean IME in WinCE

I have developed a custom keyboard for WinCE, using SendInput and a panel with buttons. The custom keyboard is working fine and textbox in my WinForm is able to display the characters.

Currently I am trying to implement Korean IME into the custom keyboard using the following method:

// Subclass to capture Windows messages, passing the handle of the TextBox
_newproc = new WndProcDelegate(MyWndProc);
_oldproc = GetWindowLong(textBox1.Handle, -4);
result = SetWindowLong(textBox1.Handle, -4, Marshal.GetFunctionPointerForDelegate(_newproc));

// Capture the WM_IME_COMPOSITION message to get the composite character
public IntPtr MyWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
        switch (msg)
        {
            case WM_IME_COMPOSITION:
            {
               int comp = lParam.ToInt32();
               int intdwSize = 0;

                if ((comp & GCS_RESULTSTR) > 0)
                    {
                        IntPtr intICHwnd = IntPtr.Zero;
                        intICHwnd = ImmGetContext(hWnd);

                        intdwSize = ImmGetCompositionString(intICHwnd, GCS_RESULTSTR, 0, 0);
                        if (intdwSize != 0)
                        {
                            StringBuilder s = new StringBuilder(intdwSize + 1);
                            intdwSize = ImmGetCompositionString(intICHwnd, GCS_RESULTSTR, s, intdwSize);
                            textBox1.Text = s.ToString();
                        }
                        ImmReleaseContext(hWnd
                            , intICHwnd);
                    }
                    else if ((comp & GCS_COMPSTR) > 0)
                    {
                        IntPtr intICHwnd = IntPtr.Zero;

                        intICHwnd = ImmGetContext(hWnd);

                        intdwSize = ImmGetCompositionString(intICHwnd, GCS_COMPSTR, 0, 0);
                        if (intdwSize != 0)
                        {
                            StringBuilder s = new StringBuilder(intdwSize);
                            intdwSize = ImmGetCompositionString(intICHwnd, GCS_COMPSTR, s, intdwSize);
                            // Trying to display the composite character in the textbox
                            textBox1.Text = s.ToString();
                        }
                        ImmReleaseContext(hWnd, intICHwnd);

                    }
                }
                break;


            default:
                break;
        }

     return CallWindowProc(_oldproc, hWnd, msg, wParam, lParam);
 }

I managed to capture the particular Windows message (WM_IME_COMPOSITION), but apparently, the process of composition is not working at all, I am still trying to figure out which part went wrong, though, I hope someone could point me to the correct direction, any help is appreciated. Thanks.

Upvotes: 2

Views: 645

Answers (1)

YYTan
YYTan

Reputation: 511

I have found a solution to the problem I face. The problem does not stem from the above code, but rather the controls i used. Initially, I tested my custom keyboard with a textBox and buttons. However, each click on the button causes the focus to shift from the textBox to the button, somehow ending the composition.

By replacing the Button controls with pictureBox, the composition is successful. Hope this helps.

Upvotes: 1

Related Questions