- 先在窗口上拖一个Microsoft Web Browser上来,调整好大小。
- 通过PB的对象浏览器察看我们可以查到它支持的属性,方法,事件。最主要的用这么几个:
1. Navigate(string url)
2. ExecWB (nCmdID, nCmdExecOpt, [pvaIn], [pvaOut] ) - 下面我们来通过代码实现一个打开网页并弹出另存,然后直接打印的程序。
ole_1.object.Navigate(sle_1.text)
//Ole控件的documentcomplete事件代码
cb_saveas.postevent(clicked!)
我们post 保存按钮的一个event:clicked,在保存按钮中调用IE的另存为功能.
//保存按钮的clicked事件代码
int OLECMDID_PRINT = 6
int OLECMDID_PRINTPREVIEW = 7
int OLECMDID_PAGESETUP = 8
int OLECMDID_SAVEAS = 4
int OLECMDEXECOPT_DODEFAULT = 0
int OLECMDEXECOPT_PROMPTUSER = 1
int OLECMDEXECOPT_DONTPROMPTUSER = 2
try
ole_1.object.ExecWB( OLECMDID_SaveAs, OLECMDEXECOPT_PROMPTUSER )
//ole_1.object.ExecWB( OLECMDID_SaveAs, OLECMDEXECOPT_PROMPTUSER, AsStatement! )都可以
ole_1.object.ExecWB( OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER )
//ole_1.object.ExecWB( OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, AsStatement! )都可以
catch(runtimeerror er)
//通常我们不显示错误,因为用户点了取消也会有一个错误
//messagebox('',er.text)
end try
ExceWb详细的参数说明:
(a).nCmdID
OLECMDID_OPEN = 1,
OLECMDID_NEW = 2,
OLECMDID_SAVE = 3,
OLECMDID_SAVEAS = 4,
OLECMDID_SAVECOPYAS = 5,
OLECMDID_PRINT = 6,
OLECMDID_PRINTPREVIEW = 7,
OLECMDID_PAGESETUP = 8,
OLECMDID_SPELL = 9,
OLECMDID_PROPERTIES = 10,
OLECMDID_CUT = 11,
OLECMDID_COPY = 12,
OLECMDID_PASTE = 13,
OLECMDID_PASTESPECIAL = 14,
OLECMDID_UNDO = 15,
OLECMDID_REDO = 16,
OLECMDID_SELECTALL = 17,
OLECMDID_CLEARSELECTION = 18,
OLECMDID_ZOOM = 19,
OLECMDID_GETZOOMRANGE = 20
OLECMDID_UPDATECOMMANDS = 21
OLECMDID_REFRESH = 22
OLECMDID_STOP = 23
OLECMDID_HIDETOOLBARS = 24
OLECMDID_SETPROGRESSMAX = 25
OLECMDID_SETPROGRESSPOS = 26
OLECMDID_SETPROGRESSTEXT = 27
OLECMDID_SETTITLE = 28
OLECMDID_SETDOWNLOADSTATE = 29
OLECMDID_STOPDOWNLOAD = 30
上面的关键词都可以在浏览器的菜单里面找到对应的选项﹐大家一看就明白的﹗
(b).nCmdExecOpt
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
LECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_SHOWHELP = 3
对于这个参数﹐一般来说﹐选1就可以了。