PB ole Web浏览器控件  

PB中使用Microsoft Web Browser控件步骤:

在pb的某窗口中加入OLE对象,选择Insert control(插入控件),然后选中"Microsoft WEB 浏览器",(随系统而定的版本),就可以在这个窗口直接使用IE浏览器控件了。

常用函数:(对这个ole控件取名叫ole_web)

ole_web.object.navigate(string ls_url) file://浏览某url,

    譬如:ole_web.object.navigate('http://liulee.myrice.com') 就是浏览 http://liulee.myrice.com 页面,当然支持本地文件,也支持本地图片文件的浏览,如jpeg,jpg,gif,png等等,如果是不支持的文件,则直接弹出选择打开文件对话框,和ie一模一样。

ole_web.object.goback() file://回退(如果没有内容可退,则会弹出错误,可以屏蔽该错误)

ole_web.object.goforward() file://前进,同上

常用事件:

documentcomplete : url请求的页面完成;

downloadcomplete:url中请求的下载完成;

常用属性:

ole_web.object.width :pixel高度,需要转换为pbunit高度才可以调整

ole_web.object.height:同上

ole_web.object.offline:离线方式,true,false两者之一

-----------------------------------------------------------------------------------------------------

打开某个网页: 

ole_1.object.Navigate("http://www.sound-net.com", '', '', '', '') 

当然如果你要做更加复杂的工作,这些是不够的 

--------------------------------------------------------------- 

如果你对javascript,dhtml熟悉的话,对下边很容易理解: 

通过pb中的browser 可以看到浏览器控件中有个对象ole_1.object.document.相当于网页中的document对象,由此可以在pb中得到和操纵许多document的属性,甚至还可以利用Document.parentWindow得到一些window对象的属性, 

例如: 

ole_1.object.Document.parentwindows.image2.value 

如果要触发某个控件(id 为image4)的click事件 

ole_1.object.Document.parentwindows.image4.click() 

ole_1.object.document.forms.length 来得到有几个form 

ole_1.object.document.forms[0].name  得到名称 

ole_1.object.document.forms[0].submit() 根据名称提交 

ole_1.object.document.forms[i].Submit.click() 

遍历font的tag: 

oleobject ole_all,ole_font 

ole_all=  ole_1.object.document.body.all 

ole_font =ole_all.tags("FONT") 

messagebox("",integer(ole_font.length)) 

改变网页背景色: 

ole_1.object.Document.body.background="" 

ole_1.object.Document.body.bgcolor=rgb(rand(255),rand(255),rand(255)) 

得到网页源码 

ls = ole_1.object.document.documentElement.outerHTML 

前进,后退: 

ole_1.object.GoBack() 

ole_1.object.GoForward() 

或者: 

ole_1.object.document.parentWindow.history.back() 

ole_1.object.document.parentWindow.history.forward() 

怎么相应点击网页的事件? 

在clicked事件中加入: 

ls_tagName=ole_1.object.document.activeElement.tagName 

if upper(trim(ls_tagName))="A" then  //同理可以对INPUT等响应 

ls_name = ole_1.object.document.activeElement.id 

ls_a=ole_1.object.Document.activeElement.href 

//然后在这里根据链接的id或者href choosecase 

CHOOSE CASE ls_name 

CASE "A_test" 

//do something 

   END CHOOSE 

end if 

怎么查找网页中document对象属性? 

   

最好的办法就是用我们的pb8,新建web target,加入并且打开一个网页,在左边tab页选中page-〉client side,从树中就可以查到网页中document对象的属性方法,直接copy下来修改修改就可以用了。

 

//===================================================================

百度: 

输入搜索 

ole_webBrowser.object.document.getElementByIdx_x("kw").InnerText ="youzhi1007" 

点击按钮 

ole_webBrowser.object.document.getElementByIdx_x("sb").click 

google 

ole_webBrowser.object.Document.GetElementsByName("q").item(0).SetAttribute("value", "youzhi1007") 

ole_webBrowser.object.Document.GetElementsByname("btnG").item(0).click

......................................................

PB中的INET控件的使用 

INET控件可以模拟向INTERNET以GET或POST形式发送请求,并且可能得到请求返回的页面内容,它需要与INTERRNETESULT控件使用.这两个控件都是不可视的,帮助文件写得并不很详细,正确使用这两个控件需要先对这两个控件派生两个标准类,再程序中再实例化使用.

NEW一个STANDARD CLASS,选择INET,保存成n_inet

NEW一个STANDARD CLASS,选择INTERNETRESULT,在INTERNETDATA函数中写上  messagebox('返回结果',string(data)),保存成n_ir

下面就试下,如下脚本

n_inet ln_inet

n_ir ln_ir

ln_inet = create n_inet

ln_ir = create n_ir

integer li_ret

li_ret = n_inet.geturl('http://www.china-puer.cn/list.asp?id=1450',ln_ir)

if li_ret <1 then messagebox('发生错误',string(li_ret))