Exemple #1
0
        public static void Register()
        {
            var regservice = new RegistrationServices();

            regservice.RegisterAssembly(Assembly.LoadFrom("YIME.Core.dll"),
                                        AssemblyRegistrationFlags.SetCodeBase);
            var iconname = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                                                  "YIME.Core.dll");

            Console.WriteLine(iconname);
            Console.WriteLine(CultureInfo.GetCultureInfo("zh-cn").LCID);
            //Insert code here.
            var p      = new ITfInputProcessorProfiles();
            var result = p.Register(CLSID_TEXTSERVICE);

            Console.WriteLine(result.ToString());
            result = p.AddLanguageProfile(CLSID_TEXTSERVICE, new LangID((ushort)CultureInfo.GetCultureInfo("zh-cn").LCID), GUID_PROFILE,
                                          name.ToCharArray(), (uint)name.ToCharArray().Length, iconname.ToCharArray(), (uint)iconname.Length, 0);

            Console.WriteLine(result.ToString());
            var c = new ITfCategoryMgr();

            foreach (var supportCategory in SupportCategories)
            {
                var r = c.RegisterCategory(CLSID_TEXTSERVICE, supportCategory, CLSID_TEXTSERVICE);
                Console.WriteLine(r.ToString());
            }
        }
        /// <summary>
        /// 釋放COM介面
        /// </summary>
        /// <param name="disposing">是否主動釋放</param>
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                // 如果有其他unmanaged東西則在此釋放
            }

            // 如果有其他Textbox之類的, 那麼referenceCount可能會大於0
            int referenceCount = Marshal.ReleaseComObject(inputProcessorProfiles);

            inputProcessorProfiles = null;
        }
        /// <summary>
        /// 初始化ITfInputProcessorProfiles介面
        /// </summary>
        public InputProcessorProfiles()
        {
            Result result = NativeAPI.CreateInputProcessorProfiles(out var profiles);

            if (result.OK)
            {
                inputProcessorProfiles = profiles;
            }
            else
            {
                inputProcessorProfiles = null;
            }
            result.CheckError();
        }
        private bool _AddTextProcessorEngine()
        {
            LangID langid;
            Guid   clsid;
            Guid   guidProfile;

            // Get default profile.
            var profile = new ITfInputProcessorProfiles();

            if (!profile.GetCurrentLanguage(out langid).Succeeded)
            {
                return(false);
            }

            if (!profile.GetDefaultLanguageProfile(langid, Guids.GUID_TFCAT_TIP_KEYBOARD, out clsid, out guidProfile).Succeeded)
            {
                return(false);
            }

            // Is this already added?
            if (_pCompositionProcessorEngine != null)
            {
                LangID langidProfile;
                Guid   guidLanguageProfile = _pCompositionProcessorEngine.GetLanguageProfile(out langidProfile);
                if ((langid.LCID == langidProfile.LCID) && guidProfile == guidLanguageProfile)
                {
                    return(true);
                }
            }

            // Create composition processor engine
            if (_pCompositionProcessorEngine == null)
            {
                _pCompositionProcessorEngine = new CompositionProcessorEngine();
            }
            if (_pCompositionProcessorEngine == null)
            {
                return(false);
            }

            // setup composition processor engine
            if (!_pCompositionProcessorEngine.SetupLanguageProfile(langid, guidProfile, ThreadMgr, ClientId, IsSecureMode, IsComLess))
            {
                return(false);
            }

            return(true);
        }
Exemple #5
0
        public static void Unregister()
        {
            ITfCategoryMgr c = new ITfCategoryMgr();

            foreach (var supportCategory in SupportCategories)
            {
                var r = c.UnregisterCategory(CLSID_TEXTSERVICE, supportCategory, CLSID_TEXTSERVICE);
                Console.WriteLine(r.ToString());
            }
            ITfInputProcessorProfiles p = new ITfInputProcessorProfiles();
            var result = p.Unregister(CLSID_TEXTSERVICE);

            Console.WriteLine(result.ToString());
            var regservice = new RegistrationServices();

            regservice.UnregisterAssembly(Assembly.LoadFrom("YIME.Core.dll"));
        }
 public static extern int TF_CreateInputProcessorProfiles(out ITfInputProcessorProfiles profiles);
 public static extern int TF_CreateInputProcessorProfiles(out ITfInputProcessorProfiles profiles);