コード例 #1
0
        public void OpenIME()
        {
            IntPtr hwndInput = IMM.ImmGetContext(IMM.GetActiveWindow());

            IMM.ImmSetOpenStatus(hwndInput, true);
            IntPtr dw1       = IntPtr.Zero;
            IntPtr dw2       = IntPtr.Zero;
            bool   isSuccess = IMM.ImmGetConversionStatus(hwndInput, ref dw1, ref dw2);

            Log.Info("" + hwndInput + "," + isSuccess);
            if (isSuccess)
            {
                int intTemp = dw1.ToInt32() & IME_CMODE_SOFTKBD;
                if (intTemp > 0)
                {
                    dw1 = (IntPtr)(dw1.ToInt32() ^ IME_CMODE_SOFTKBD);
                }
                else
                {
                    dw1 = (IntPtr)(dw1.ToInt32() | IME_CMODE_SOFTKBD);
                }
            }
            isSuccess = IMM.ImmSetConversionStatus(hwndInput, dw1, dw2);
            IMM.ImmReleaseContext(IMM.GetActiveWindow(), hwndInput);
        }
コード例 #2
0
        /// IntPtr handle is the handle to the textbox
        public string CurrentCompStr(IntPtr handle)
        {
            int readType = GCS_COMPSTR;

            IntPtr hIMC = IMM.ImmGetContext(handle);

            try
            {
                int strLen = IMM.ImmGetCompositionStringW(hIMC, readType, null, 0);

                if (strLen > 0)
                {
                    byte[] buffer = new byte[strLen];

                    IMM.ImmGetCompositionStringW(hIMC, readType, buffer, strLen);

                    return(Encoding.Unicode.GetString(buffer));
                }
                else
                {
                    return(string.Empty);
                }
            }
            finally
            {
                IMM.ImmReleaseContext(handle, hIMC);
            }
        }