Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

tButton temb = new tButton(); ITfLangBarItemMgr pLangBarItemMgr = threadMgr as…

  1. User

    tButton temb = new tButton(); ITfLangBarItemMgr pLangBarItemMgr = _threadMgr as ITfLangBarItemMgr; HRESULT hr = pLangBarItemMgr.AddItem(temb);

    以上代码中pLangBarItemMgr.AddItem执行AddItem方法时,返回E_FAIL错误,请分析怎么改错

    已知tButton 是一个ITfLangBarItemButton接口的实现,声明如下: internal class tButton: ITfLangBarItemButton { bool ascii_mode; private Icon _icon;

        public HRESULT GetInfo([Out] out TF_LANGBARITEMINFO pInfo)
        {
    
            pInfo=new TF_LANGBARITEMINFO();
            pInfo.clsidService = SaywolInputTextService.CLSID_TEXTSERVICE;
            pInfo.guidItem = SaywolInputTextService.GUID_LBI_INPUTMODE;//从Windows 8开始,此值应GUID_LBI_INPUTMODE (或语言栏项将被忽略) 。
            pInfo.dwStyle = TF_LBI_STYLE.TF_LBI_STYLE_BTN_BUTTON;//| TF_LBI_STYLE.TF_LBI_STYLE_BTN_MENU
            pInfo.ulSort = 0;
    
            pInfo.szDescription = "TSF Input Method";
            ascii_mode = false;
            _icon = new Icon("C:\\SaywolInput\\SaywolInputTsf\\TwoThingBig.ico");
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT GetStatus([Out] out TF_LBI_STATUS pdwStatus)
        {
            pdwStatus= TF_LBI_STATUS.TF_LBI_STATUS_HIDDEN;
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT Show([In] bool fShow)
        {
            MessageBox.Show("测试!");
    
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT GetTooltipString([MarshalAs(UnmanagedType.BStr), Out] out string pbstrToolTip)
        {
            pbstrToolTip = "测试";
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT OnClick([In] TfLBIClick click, [In] POINT pt, [In] ref RECT prcArea)
        {
            MessageBox.Show("测试!");
    
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT InitMenu([In, MarshalAs(UnmanagedType.Interface)] ITfMenu pMenu)
        {
            MessageBox.Show("测试!");
    
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT OnMenuSelect([In] uint wID)
        {
            MessageBox.Show("测试!");
    
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT GetIcon([Out] out IntPtr phIcon)
        {
            if (ascii_mode)
                phIcon= _icon.Handle;
            else
            {
                phIcon = _icon.Handle;
            }
    
            phIcon = _icon.Handle;
            return new HRESULT() { Code = 0 };
        }
    
        public HRESULT GetText([MarshalAs(UnmanagedType.BStr), Out] out string pbstrText)
        {
            pbstrText = "测试";
            return new HRESULT() { Code = 0 };
        }
    
        public void OnClick(TfLBIClick click, Point pt, int position, int menuId, ITfMenu menu)
        {
            
        }
    
        void ITfLangBarItemButton.InitMenu(ITfMenu menu)
        {
        }
    
        public bool IsEnabled()
        {
            return true;
        }
    
        public bool IsChecked()
        {
            return true;
    
        }
    
        public void OnUpdate(TfLBIClick click, Point pt, int position, int menuId, ITfMenu menu)
        {
        }
    
        [return: MarshalAs(UnmanagedType.Struct)]
        public TF_DISPLAYATTRIBUTE GetInfo()
        {
            return new TF_DISPLAYATTRIBUTE();
        }
    }
    
  2. Assistant

    在代码中缺少对tButton的Text属性的设置,需要在GetInfo方法中添加pInfo.bstrText = "button text";的代码。例如:

    public HRESULT GetInfo([Out] out TF_LANGBARITEMINFO pInfo) { pInfo = new TF_LANGBARITEMINFO(); pInfo.clsidService = SaywolInputTextService.CLSID_TEXTSERVICE; pInfo.guidItem = SaywolInputTextService.GUID_LBI_INPUTMODE;//从Windows 8开始,此值应GUID_LBI_INPUTMODE (或语言栏项将被忽略) 。 pInfo.dwStyle = TF_LBI_STYLE.TF_LBI_STYLE_BTN_BUTTON;//| TF_LBI_STYLE.TF_LBI_STYLE_BTN_MENU pInfo.ulSort = 0;

    pInfo.bstrText = "button text";
    pInfo.szDescription = "TSF Input Method";
    ascii_mode = false;
    _icon = new Icon("C:\\SaywolInput\\SaywolInputTsf\\TwoThingBig.ico");
    return new HRESULT() { Code = 0 };
    

    }