请指教:如何在VFP里面使用IE浏览器控件?

davlong 2003-04-26 10:52:50
已调出控件,但是不懂初始化和具体使用方法。
请多多指教!!!!!

...全文
718 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
davlong 2003-04-27
  • 打赏
  • 举报
回复
感谢回答,但是说“找不到Olecontrol定义类”,请问哪里有例子可供参考??
fengxi 2003-04-27
  • 打赏
  • 举报
回复
ThisForm.AddObject("Web","Olecontrol","Shell.Explorer.2")
ThisForm.Web.Navigate2("http://www.sina.com.cn")
ThisForm.Web.Width = 300
ThisForm.Web.Height = 200
ThisForm.Web.Visible = .T.
marki 2003-04-27
  • 打赏
  • 举报
回复
或,

ON ERROR WAIT WINDOW "Internet Explorer has been shut down!" TIME 1
IE_handle = 0

IF NOT 'FOXTOOLS' $ SET('LIBRARY')
SET LIBRARY TO SYS(2004)+"FoxTools"
ENDIF

IEWind = MAINHWND()
GetActive=RegFn('GetActiveWindow','','I') && Determine if FoxPro is on top.

oie = CREATEOBJECT("internetexplorer.application")
oie.Visible = .T.
oie.Navigate("http://msdn.microsoft.com/vfoxpro/")

DO WHILE .T. && Keep looping until the ActiveWindow = FoxWind
DOEVENTS()
IF IEWind = CallFn(GetActive)
EXIT
ENDIF
ENDDO

SET LIBRARY TO
oie.Application.Quit
ON ERROR
marki 2003-04-27
  • 打赏
  • 举报
回复
續上貼,

使用 Msinet.ocx

*-----------------------------------
* AUTHOR: Trevor Hancock (TREVORH@MICROSOFT.COM)
* CREATED: 10/24/01 03:07:28 PM for Microsoft Knowledge Base article Q311306
* ABSTRACT: Downloads a Web page and then parses it to extract a stock quote.
*
* DETAILS: This code uses the Msinet.ocx ActiveX control to
* download a Web page from HTTP://Money.cnn.com.
* Specifically, it calls "HTTP://qs.money.cnn.com/apps/stockquote?symbols=",
* passing to the Web page a stock symbol that the user types into THISFORM.txtSYBMOL.
* The Web site returns an entire page of information about the
* stock, which this code then parses to extract the current quote.
*-----------------------------------

PUBLIC ofrmMSINET

ofrmMSINET = NEWOBJECT("frmMSINET")
ofrmMSINET.SHOW
RETURN

**************************
DEFINE CLASS ocxMSINET AS OLECONTROL
OLECLASS = "InetCtls.Inet.1"
ENDDEFINE

**************************
DEFINE CLASS frmMSINET AS FORM
HEIGHT = 70
WIDTH = 304
AUTOCENTER = .T.
BORDERSTYLE = 3
CAPTION = "Stock Quote via MSINET.OCX"
MAXBUTTON = .F.
MINBUTTON = .F.
NAME = "frmMSINET"

ADD OBJECT MSINET AS ocxMSINET WITH ;
TOP = 37, ;
LEFT = 234, ;
HEIGHT = 100, ;
WIDTH = 100, ;
NAME = "MSINET"

ADD OBJECT txtsymbol AS TEXTBOX WITH ;
FONTNAME = "Verdana", ;
VALUE = "MSFT", ;
FORMAT = "!", ;
HEIGHT = 26, ;
LEFT = 94, ;
TABINDEX = 1, ;
TOP = 7, ;
WIDTH = 100, ;
NAME = "txtSymbol"

ADD OBJECT cmdGetQuote AS COMMANDBUTTON WITH ;
TOP = 7, ;
LEFT = 206, ;
HEIGHT = 27, ;
WIDTH = 94, ;
FONTNAME = "Verdana", ;
CAPTION = "Get Quote", ;
TABINDEX = 2, ;
NAME = "cmdGetQuote"

ADD OBJECT lblSymbol AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Verdana", ;
CAPTION = "Stock Symbol:", ;
HEIGHT = 16, ;
LEFT = 3, ;
TOP = 12, ;
WIDTH = 90, ;
TABINDEX = 5, ;
NAME = "lblSymbol"

ADD OBJECT txtQuote AS TEXTBOX WITH ;
FONTNAME = "Verdana", ;
HEIGHT = 23, ;
LEFT = 94, ;
READONLY = .T., ;
TOP = 39, ;
WIDTH = 100, ;
NAME = "txtQuote"

ADD OBJECT lblQuote AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Verdana", ;
CAPTION = "Quote:", ;
HEIGHT = 16, ;
LEFT = 47, ;
TOP = 42, ;
WIDTH = 46, ;
TABINDEX = 5, ;
NAME = "lbQuote"

PROCEDURE cmdGetQuote.CLICK
LOCAL lcQuote AS STRING, ;
lcURL AS STRING

lcQuote = ""
lcGetURl = "HTTP://qs.money.cnn.com/apps/stockquote?symbols=" + ;
ALLT(THISFORM.txtsymbol.VALUE)

WITH THISFORM
*-- Get the quote using the Msinet.ocx ActiveX control.
*-- The quote will load it directly into a variable.
lcQuote = .MSINET.OpenURL(lcGetURl)
IF EMPTY(lcQuote)
MESSAGEBOX("Download Failed.",0,"")
RETURN .F.
ENDIF

*-- Grab the quote from the Web page. If in VFP 7.0, we use the new
*-- STREXTRACT() function to grab the data between two delimiters.
*-- In VFP 6.0, use SUBSTR() to get the data, and then trim off any
*-- trailing HTML with the TRANSFORM() AND VAL() functions.
IF VERSION(5) = 700
lcQuote = STREXTRACT(lcQuote, [stockheader">], [<])
ELSE
*-- Extract the quote from the HTML
lcQuote = SUBSTR(lcQuote, ATC(["stockheader"], lcQuote) + 14, 8)
*-- Trim off the trailing HTML. VAL() will only return the numbers,
*-- which we then change to a string with TRANSFORM()
lcQuote = TRANSFORM(VAL(lcQuote))
ENDIF

*-- Put the quote in the text box.
.txtQuote.VALUE = "$" + lcQuote
ENDWITH
ENDPROC
ENDDEFINE
**************************
参考

Q191222 INFO: Visual FoxPro 6.0 支持的 ActiveX 控件

Q307550 INFO: Visual FoxPro 7.0 支持的 ActiveX 控件
marki 2003-04-27
  • 打赏
  • 举报
回复
另類方法,

如何用 Visual FoxPro 来下载一个网页

文号: Q311306


--------------------------------------------------------------------------------
本文信息适用于:
Microsoft Visual FoxPro for Windows, versions 6.0 , 7.0

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

概述

本文提供的示例代码演示了如何从不用用户界面或自动控制 IE 来从 Internet 上下载网页的内容. 一个示例使用 Urlmon.dll 动态连接库中的函数, 另一个示例使用 Msinet.ocx ActiveX 控件.

更多信息

Urlmon.dll 随许多微软产品和操作系统分发:

Microsoft Internet Explorer 5.0 及以上版本
Microsoft Windows 98 和 Microsoft Windows 98 SE
Microsoft Windows Millennium Edition (Me)
Microsoft Windows 2000 专业版和 Microsoft Windows 2000 服务器
Microsoft Office 2000
Msinet.ocx 随 Microsoft Visual Studio 97 和 Microsoft Visual Studio 6.0 分发. Msinet.ocx 也随以下产品的标准独立版分发:
Microsoft Visual Basic 5.0 和 Visual Basic 6.0
Microsoft Visual FoxPro 6.0 和 Visual FoxPro 7.0
Microsoft Interdev 6.0
Microsoft C++ 5.0 和 C++ 6.0
如果你是这些开发语言中的一种的授权用户, 你可以重分发 Msinet.ocx 控件.

如何使用示例代码

要使用这些示例代码, 按以下步骤:
在 Visual FoxPro version 6.0 或 7.0 中粘贴各示例代码到一个新的程序文件中.


保存并运行程序. 在你运行各程序时, 一个表单显示出来要求一个股票代号.


在文本框中输入一个合法的股票代号, 然后单击 Get Quote 来接收一个报价.


查看源代码中的 cmdGetQuote.click 注释来理解报价是如何接收的.

注意 : 这些代码中下载的网页可能在任何时候改变. 作为结果, 分解网页来获取股票报价的代码可能不再工作. 但是, 用来下载页面的代码的概述仍然是适用的.

使用 Urlmon.dll

*-----------------------------------
* AUTHOR: Trevor Hancock (TREVORH@MICROSOFT.COM)
* CREATED: 10/24/01 03:07:28 PM for Microsoft Knowledge Base article Q311306
* ABSTRACT: Downloads a Web page and then parses the Web page to extract a stock quote.
*
* DETAILS: This code uses the function URLDownloadToFile(), located in
* Urlmon.dll. This function downloads a Web page from
* HTTP://Money.cnn.com. Specifically, the function calls
* "HTTP://qs.money.cnn.com/apps/stockquote?symbols=",
* passing to the Web page a stock symbol that the user types into THISFORM.txtSYMBOL.
* The Web site returns an entire page of information about the
* stock, which this code then parses to extract the current quote.
*-----------------------------------

PUBLIC ofrmURLMON

ofrmURLMON = NEWOBJECT("frmURLMON")
ofrmURLMON.SHOW
RETURN

**************************
DEFINE CLASS frmURLMON AS FORM
HEIGHT = 83
WIDTH = 317
AUTOCENTER = .T.
BORDERSTYLE = 2
CAPTION = "Stock Quote via URLMON.DLL"
MAXBUTTON = .F.
MINBUTTON = .F.
NAME = "frmURLMON"

ADD OBJECT txtsymbol AS TEXTBOX WITH ;
FONTNAME = "Verdana", ;
VALUE = "MSFT", ;
FORMAT = "!", ;
HEIGHT = 26, ;
LEFT = 94, ;
TABINDEX = 1, ;
TOP = 7, ;
WIDTH = 100, ;
NAME = "txtSymbol"

ADD OBJECT cmdGetQuote AS COMMANDBUTTON WITH ;
TOP = 7, ;
LEFT = 206, ;
HEIGHT = 27, ;
WIDTH = 94, ;
FONTNAME = "Verdana", ;
CAPTION = "Get Quote", ;
TABINDEX = 2, ;
NAME = "cmdGetQuote"

ADD OBJECT lblSymbol AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Verdana", ;
CAPTION = "Stock Symbol:", ;
HEIGHT = 16, ;
LEFT = 3, ;
TOP = 12, ;
WIDTH = 90, ;
TABINDEX = 5, ;
NAME = "lblSymbol"

ADD OBJECT txtQuote AS TEXTBOX WITH ;
FONTNAME = "Verdana", ;
HEIGHT = 23, ;
LEFT = 94, ;
READONLY = .T., ;
TOP = 39, ;
WIDTH = 100, ;
NAME = "txtQuote"

ADD OBJECT lblQuote AS LABEL WITH ;
AUTOSIZE = .T., ;
FONTNAME = "Verdana", ;
CAPTION = "Quote:", ;
HEIGHT = 16, ;
LEFT = 47, ;
TOP = 42, ;
WIDTH = 46, ;
TABINDEX = 5, ;
NAME = "lbQuote"

PROCEDURE cmdGetQuote.CLICK
LOCAL lcQuote AS STRING, ;
lcTempTxtFile AS STRING, ;
lnGetResults AS INTEGER, ;
lcURL AS STRING

lcQuote = ""
*-- Set up a variable referring to a temp .TXT file.
*-- Uses the current VFP TEMP DIR [SYS(2023)]
*-- and a random file name [SYS(2015)]
lcTempTxtFile = FORCEEXT(ADDBS(SYS(2023)) + SYS(2015), "TXT")
lnGetResults = 0
lcGetURl = "HTTP://qs.money.cnn.com/apps/stockquote?symbols=" + ;
ALLT(THISFORM.txtsymbol.VALUE)

DECLARE LONG URLDownloadToFile IN URLMON.DLL ;
LONG, STRING, STRING, LONG, LONG

WITH THISFORM
*-- Get the quote using the Urlmon.dll and store it
*-- to a temp .TXT file.
*-- This function returns non-zero if it fails.
lnGetResults = URLDownloadToFile(0, lcGetURl, lcTempTxtFile, 0, 0)
IF lnGetResults # 0
MESSAGEBOX("Download Failed",0,"")
RETURN .F.
ENDIF

*-- Read the Web page into a variable, and then erase it.
lcQuote = FILETOSTR(lcTempTxtFile)
ERASE (lcTempTxtFile)

*-- Grab the quote from the Web page. If in VFP 7.0, we use the new
*-- STREXTRACT() function to grab the data between two delimiters.
*-- In VFP 6.0, use SUBSTR() to get the data, and then trim off any
*-- trailing HTML with the TRANSFORM() AND VAL() functions.
IF VERSION(5) = 700
lcQuote = STREXTRACT(lcQuote, [stockheader">], [<])
ELSE
*-- Extract the quote from the HTML
lcQuote = SUBSTR(lcQuote, ATC(["stockheader"], lcQuote) + 14, 8)
*-- Trim off the trailing HTML. VAL() will only return the numbers,
*-- which we then change to a string with TRANSFORM()
lcQuote = TRANSFORM(VAL(lcQuote))
ENDIF

*-- Put the quote in the text box.
.txtQuote.VALUE = "$" + lcQuote
ENDWITH
ENDPROC
ENDDEFINE
**************************

davlong 2003-04-27
  • 打赏
  • 举报
回复
问题已经解决,原来不要掉那个Web Browser。。。
已经给分,再次感谢各位!!
marki 2003-04-27
  • 打赏
  • 举报
回复
VB不像VFP本身就是一個小數據庫系統,操作數據是麻煩些,
但它結合MDB絕對比得上VFP,最好結合SQLSERVER,不光界面,
安全性及靈活度不是VFP能比的~
davlong 2003-04-27
  • 打赏
  • 举报
回复
VB数据库管理没有那么强吧?正在做一数据库程序
本想用Web页方式使得操作方便和界面漂亮的。。。
marki 2003-04-27
  • 打赏
  • 举报
回复
沒試過...
用VB吧,比這方便多了
davlong 2003-04-27
  • 打赏
  • 举报
回复
是阿,我也这样写上去了,但是老是说找不到那个类,我已经吧Microsoft WEB Browser拉在form表上的了,但是任何程序都没有写运行的时候说有错,是不是我的控件,还是VFp坏了?
我用的是IE6+Winxp Sp1+VFP8。0+中文破解。
这个问题很烦阿。。。。
marki 2003-04-27
  • 打赏
  • 举报
回复
用Microsoft WEB Browser控制...
fengxi 2003-04-27
  • 打赏
  • 举报
回复
我所写的代码既是嵌套在Form里面的啊,可能要IE6部吧,我用VFP8在XP下写的。
davlong 2003-04-27
  • 打赏
  • 举报
回复
我所想要的是嵌套在Form里面阿。
流星尔 2003-04-27
  • 打赏
  • 举报
回复
这样会打开另一个窗口,就像你点了IE快界方式一样
davlong 2003-04-27
  • 打赏
  • 举报
回复
这是调用IE浏览器,能把浏览器嵌套在Form里面吗???
流星尔 2003-04-27
  • 打赏
  • 举报
回复
IE4=CreateObject("InternetExplorer.Application")
ie4.visible=.t.
IE4.menubar = .t.
IE4.toolbar = .t.
IE4.statusbar = .t.
IE4.fullscreen = .f.
IE4.navigate("www.sdgroup.cn") && 应该指明全路径
davlong 2003-04-26
  • 打赏
  • 举报
回复
Up,有没有高手知道??

2,723

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧