你的位置:编程库 >> 资讯 >> Power Builder >> 分布式编程 >> 详细内容 在线投稿

在PowerBuilder中使用Microsoft Web浏览器控件

发布: 2008-6-26 20:42 |  作者: admin |   查看: 67次

 利用Internet Explorer带的"Microsoft Web Browser" ActiveX 控件,我们可以使pb应用程序中带有浏览器的功能。

PowerBuilder 6 须知

在PowerBuilder 6.x中, BeforeNavigate2, NavigateComplete, 和DocumentComplete事件件不会被触发 这在 PowerBuilder 7.x 中被纠正。 

设计方法 

本例中,我们把"Microsoft Web Browser Control"命名为"ole_1.",ole的所有的事件被显示在列表框lb_1中 ,我们可以看到所有被触发的事件。

单行编辑器 "sle_1"用于输入URLs,回车后件调用浏览器其控件。其他按钮用于显示ole控件的其他特点。本例中使用的浏览器控件为Explorer 4.0 SP1a.附带的版本。导航到URL

 导航到URL的命令为: 

ole_1.object.Navigate( sle_1.text )

您可以在单独的按钮中执行如上代码,也可以放在单行编辑器的回车事件中:

事件: sle_1.evt_keyup

// wait for the

if key = keyEnter! then

ole_1.object.Navigate( sle_1.text )

end if

 

向前或向后按钮

  如下方法实现浏览的前后操作:

ole_1.object.GoBack() //后退

ole_1.object.GoForward() //向前

打印Web页面

打印页面比较复杂,我们需要使用 generic "ExecWB" 方法类传递打印命令及其参数:

// Print this web page

int OLECMDID_PRINT = 6

int OLECMDID_PRINTPREVIEW = 7

int OLECMDID_PAGESETUP = 8

int OLECMDEXECOPT_DODEFAULT = 0

int OLECMDEXECOPT_PROMPTUSER = 1

int OLECMDEXECOPT_DONTPROMPTUSER = 2

ole_1.object.ExecWB( OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER )

or

ole_1.object.ExecWB( OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, AsStatement! )

页面设置

 和打印相似,页面设置需要一个命令,但他要求"AsStatement!" 修正

ole_1.object.ExecWB( OLECMDID_PAGESETUP, OLECMDEXECOPT_DONTPROMPTUSER, AsStatement! )

一些有用的事件: 

DownloadBegin() and DownloadComplete()

提供对用户下载的反馈信息

StatusTextChange( string newText )

更新状态条

DocumentComplete( oleobject obj, any URL )

当整个页面被打开后触发(PowerBuilder 6.x不支持)

TitleChange( string newTitle )

更新标题条

ProgressChange( long progress, long progressMax )

用于显示下载的进程

BeforeNavigate2( many args )

提供载导航前的警告.(pb6不支持)

 

Resizing the Browse Window

下例处理窗口的'resize'事件。 定义实例变量:

int iOldWinWidth = 0

int iOldWinHeight = 0

窗口的打开事件中: 

iOldWinWidth = this.width

iOldWinHeight = this.height

 

窗口的 "Resize" 事件:

 

event window.Resize(unsignedlong sizeType, integer newWidth, integer newHeight )

// resize the OLE object too

if sizeType <> 0 then

return 0

end if

int ObjWidth, ObjHeight

int marginLeft, marginRight

int marginTop, marginBottom

// The space (margins) around the web-browser control

// This technique depends on there being NO BORDER around the OLE control

marginLeft = ole_1.x

marginRight = iOldWinWidth - ole_1.width - marginLeft

marginTop = ole_1.y

marginBottom = iOldWinHeight - ole_1.height - marginTop

ObjWidth = newWidth - (marginRight + marginLeft)

ObjHeight = newHeight - (marginTop + marginBottom)

// Tell the control - but first convert to PIXELS

ole_1.width = objWidth

ole_1.object.width = UnitsToPixels( objWidth, XUnitsToPixels!)

ole_1.height = objheight

ole_1.object.height = UnitsToPixels( objheight, YUnitsToPixels!)

// store the new height/width in the window's instance variables

iOldWinWidth = newWidth

iOldWinHeight = newHeight

// continue processing

return 0

 

处理OLE误错

 和其他OLE 控件一样,当发生任何错误时浏览器控件返回ole异常。这些异常包括: 

打印 | 收藏此页 |  推荐给好友 | 举报
上一篇 下一篇
 

评分:0

发表评论
查看全部回复【已有0位网友发表了看法】