精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
I am learning TSF and want to implement a text service, according to the sample code provided by MS. It could add a language bar item with menu style using the ITFLangBarItemButton interface. But can I draw a bitmap language bar item with the size 64px(width) by 16px(height) using the ITFLangBarItemBitmap?(I want to show 4 Chinese characters on it). There are 3 methods provided by ITFLangBarItemBitmap, OnClick,GetPreferredSize and DrawBitmap, How to use the methods GetPreferredSize and DrawBitmap? The docs in the ms website is so simple. Can you give me some sample codes or tell me how to use these three methods. Flowing charts are also OK.我正在学习TSF,并希望根据MS提供的示例代码来实现文本服务。它可以使用ITFLangBarItemButton接口添加具有菜单样式的语言栏项目。但是我可以使用ITFLangBarItemBitmap绘制大小为64px(宽)x 16px(高)的位图语言栏吗?(我想在上面显示4个汉字)。ITFLangBarItemBitmap提供了3种方法,OnClick,GetPreferredSize和DrawBitmap,如何使用GetPreferredSize和DrawBitmap方法?ms网站中的文档非常简单。您能给我一些示例代码还是告诉我如何使用这三种方法。流程图也可以。
According to the document, You need to override the 2 methods.
The interface was define as below:根据文档,您需要重写这两种方法。
接口定义如下:
#ifndef __ITfLangBarItemBitmap_INTERFACE_DEFINED__ #define __ITfLangBarItemBitmap_INTERFACE_DEFINED__ /* interface ITfLangBarItemBitmap */ /* [unique][uuid][object] */ EXTERN_C const IID IID_ITfLangBarItemBitmap; #if defined(__cplusplus) && !defined(CINTERFACE) MIDL_INTERFACE("73830352-d722-4179-ada5-f045c98df355") ITfLangBarItemBitmap : public ITfLangBarItem { public: virtual HRESULT STDMETHODCALLTYPE OnClick( /* [in] */ TfLBIClick click, /* [in] */ POINT pt, /* [in] */ __RPC__in const RECT *prcArea) = 0; virtual HRESULT STDMETHODCALLTYPE GetPreferredSize( /* [in] */ __RPC__in const SIZE *pszDefault, /* [out] */ __RPC__out SIZE *psz) = 0; virtual HRESULT STDMETHODCALLTYPE DrawBitmap( /* [in] */ LONG bmWidth, /* [in] */ LONG bmHeight, /* [in] */ DWORD dwFlags, /* [out] */ __RPC__deref_out_opt HBITMAP *phbmp, /* [out] */ __RPC__deref_out_opt HBITMAP *phbmpMask) = 0; }; ... #endif #endif /* __ITfLangBarItemBitmap_INTERFACE_DEFINED__ */
You need to check the parameters first. And then, set [out] parameters with [in] parameters, or without [in] parameters by hard code. For example, you want to set the Preferred size to 64px * 16px, just set in method GetPreferredSize like:您需要先检查参数。然后,通过具体代码设置带有[in] 参数或不带有[in] 参数的 [out]参数 。例如,您要将“首选大小” 设置 为64px * 16px,只需在方法GetPreferredSize中进行设置即可:
HRESULT STDMETHODCALLTYPE GetPreferredSize( /* [in] */ __RPC__in const SIZE *pszDefault, /* [out] */ __RPC__out SIZE *psz) { if(psz != NULL) { *psz.cx = 64; *psz.cy = 16; } return S_OK; }
The same as DrawBitmap, create a HBITMAP with specified width and height for phbmp.
For phbmpMask:
if DrawBitmap succeed, then return S_OK, or return E_INVALIDARG for invalid parameters, or E_OUTOFMEMORY for memory allocation failure when create a bitmap.
与DrawBitmap相同, 为phbmp 创建具有指定宽度和高度的HBITMAP。
对于 phbmpMask:
如果 DrawBitmap成功,则在创建位图时返回S_OK,或者对于 无效参数返回E_INVALIDARG , 对于 内存分配失败返回 E_OUTOFMEMORY 。