设置PARENT估计不行,因为要知道工具栏的HWND才行
doll_paul的意思是通过代码使WORD的工具栏固定在一个位置或停靠在窗口上,这个倒是
容易,你只消获取到WordApplication(如果用OLE,则是OLEContainer中的Object),
然后你就可以用MSO中的接口了(须引用$Delphi/Ocx/Servers/中的PAS或注册的类型库)。
WordApplication.CommandBars的每一个Item,都是 CommandBar,
在Office2000.pas你会找到以下定义:
CommandBar = interface(_IMsoOleAccDispObj)
['{000C0304-0000-0000-C000-000000000046}']
property BuiltIn: WordBool read Get_BuiltIn;
property Context: WideString read Get_Context;
property Controls: CommandBarControls read Get_Controls;
property Enabled: WordBool read Get_Enabled;
property Height: SYSINT read Get_Height;
property Index: SYSINT read Get_Index;
property InstanceId: Integer read Get_InstanceId;
property Left: SYSINT read Get_Left;
property Name: WideString read Get_Name;
property NameLocal: WideString read Get_NameLocal;
property Parent: IDispatch read Get_Parent;
property Position: MsoBarPosition read Get_Position;
property RowIndex: SYSINT read Get_RowIndex;
property Protection: MsoBarProtection read Get_Protection;
property Top: SYSINT read Get_Top;
property Type_: MsoBarType read Get_Type_;
property Visible: WordBool read Get_Visible;
property Width: SYSINT read Get_Width;
property AdaptiveMenu: WordBool read Get_AdaptiveMenu;
end;
很明显,我们关心的是Left,Position,RowIndex,Top这几个属性(至于Parent,并不是DELPHI
中的那种定义)。其中:
// Constants for enum MsoBarPosition
type
MsoBarPosition = TOleEnum;
const
msoBarLeft = $00000000;
msoBarTop = $00000001;
msoBarRight = $00000002;
msoBarBottom = $00000003;
msoBarFloating = $00000004;
msoBarPopup = $00000005;
msoBarMenuBar = $00000006;
其中的意义估计大家一看都明白。只要把把Position设置为msoBarTop ,则工具栏会停
靠的窗口上部。
如果不希望用户把工具栏拖走,你可以修改Protection这个属性,定义:
// Constants for enum MsoBarProtection
type
MsoBarProtection = TOleEnum;
const
msoBarNoProtection = $00000000;
msoBarNoCustomize = $00000001;
msoBarNoResize = $00000002;
msoBarNoMove = $00000004;
msoBarNoChangeVisible = $00000008;
msoBarNoChangeDock = $00000010;
msoBarNoVerticalDock = $00000020;
msoBarNoHorizontalDock = $00000040;
很显然,设置成msoBarNoChangeDock 即可。