Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have been developing an application which supports English and Japanese language.

For Japanese language i need the Input Method Editor(IME) language bar for converstion related thing.

But for english language this is not required.

So the task is to hide the IME language bar for english language and make it visible only if the language is japanese.

I have been using the following method to close the IME window but it is not working.

The sample code is attached below:

private bool setIME(bool mode)
        {
            IntPtr hWnd = IntPtr.Zero;
            //hWnd = GetActiveWindow();
            hWnd = textBox1.Handle;
            if (hWnd == IntPtr.Zero)
            {
                //Can't find ActiveWindow
                return false;
            }

            IntPtr context = IntPtr.Zero;

            try
            {
                context = ImmGetContext(hWnd);       //get IMEContext

                if (mode == true)
                {
                    //get IMEStatus
                    //if(ImmGetOpenStatus(IntPtr.Zero)){
                    //    System.Windows.Forms.MessageBox.Show ("IME has be Opened");
                    //}
                    // open IME
                    return ImmSetOpenStatus(context, true); // IME on
                }
                else
                    if (mode == false)
                    {
                        //get IMEStatus
                        if (ImmGetOpenStatus(context))
                        {
                            System.Windows.Forms.MessageBox.Show("IME has be Opened");
                        }
                        // close IME(direct input for Alphabet and Number)
                        bool immSetOpenStatus = ImmSetOpenStatus(context, false);
                        //IntPtr immAssociateContext = ImmAssociateContext(hWnd, context);
                        return immSetOpenStatus; // IME off
                    }

            }
            finally
            {
                if (context != IntPtr.Zero)
                {
                    ImmReleaseContext(hWnd, context);   //Release IMEContext
                }
            }

            return false;
        }


Just verify if i am making any mistake.
Posted
Updated 20-Feb-14 21:03pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900