关于在office toolbar中自定义控件

 我用英文写的东西,狗屁不通,也懒得翻译了,讲究看看吧

As we know the word COM does not provide enough interface for us to customize the toolbar interface, we can only create four type of control: button, edit box, menu  (pop button), combo box,  but those interfaces can not meet all out require (we need to draw a icon and a edit box with google logo), So we have to develop a way to implement a self customize UI.

I try to study into the inner part of word toolbar UI and summary the behavior of it.

A. when we create a toolbar in the word, it is not simplely a control which the operation system defined.  When we open many word document, in different word windows,  in fact, in each windows there is one unique control (each control has a unique windows handle), so if we want to customize the UI, we should consider all the control in different word windows .

B. when we create or switch between word windows, the word application may rearrange the toolbar, that means a toolbar that is our google translate toolbar may change into other toolbar which has save or font icon, and other toolbar may change into our google translate toolbar, but no matter how they change, there is always one google toolbar in a word windows

C. the child control in toolbar may be destroy and recreate by word application.

  When we switch the word windows or some unknown action, the childe control in toolbar will be destroy and sent a WM_PARENTNOTIFY message to toolbar window, the word application will recreate controls which we use word api to create, but for our customized control, the word do nothing after destroy it, so we should recreate it ourself

D. when close word window the toolbar in that window may be destroy the toolbar window

E. we can drag the tool bar from the top of word windows and the toolbar can be float or dock on the top, left ,right ,bottom of the word window, when we drag in fact, the toolbar are different window (have different hwnds)

F. the button and pop menu in toolbar in fact are not windows (has not hwnd), it is draw by gdi in toolbar window, and for the edit box and combo box, word application creates it only when it need to interactive (it creates the first time that mouse hover over it, before it is just draw by gdi)

 

 

My solution

To solve the customized UI of toolbar, we find the google translate toolbar windows and replace its default windows process function (subclass), and draw and create it in the new windows process function. But we should concert the above  behave of toolbar which are mentioned above

 

 

A.    create a timer to find toolbar

  Because the toolbar is not fix to one certain window, so we try to search the toolbar using a timer to find a toolbar window handler every 100ms, if we find the toolbar windows we subclass it. (see the ToolBarControlManager::SeekWordWindows  function for seek and ToolBarControl class for control subclass action)

B.     compare the toolbar name

We set the toolbar name “GoogleTranslateToolBar” when init and this is out search’s condition

C.     process the WM_PARENTNOTIFY message

If toolbar window receive WM_PARENTNOTIFY and check this message is caused by child control destroy we delete the toolbar and wait for the timer to recreate it. Please see ToolBarControl:: OnParentNotify.

D.    process the WM_DESTORY message

same as above please ToolBarControl:: OnDestory

E.  mouse move problem process the WM_MOUSEMOVE message

                  Because the toolbar may need wm_mousemove message to draw the high light or something else of the toolbar control, so if we create

F. imit the toolbar

we limit the toolbar from dragging around word window, (see the toolbar behave F)

the code is:

  sp_cmd_bar->Protection =

    (Office::MsoBarProtection)(Office::msoBarNoChangeDock |

                              Office::msoBarNoChangeVisible |

                              Office::msoBarNoCustomize |

                              Office::msoBarNoResize);

如果看不懂,的确需要可以留言问我
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值