• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 720
  • Last Modified:

how can i call a URL

I want to put a button in a form that call a URL  (ex www.google.com"
How can i do that?
thank you very much
Lucília Coelho
0
luciliacoelho
Asked:
luciliacoelho
1 Solution
 
dec0mpileCommented:
Try to do this:

declare integer ShellExecute in shell32.dll ;

ShellExecute(0,"open","www.google.com",0,0,1)

Open in new window

Also see this example:
http://www.berezniker.com/content/pages/visual-foxpro/opening-url-default-web-browser
0
 
luciliacoelhoAuthor Commented:
i try the example and it works well, but the the result is 3 browsers open. the code off the example is as follow

#DEFINE SW_SHOWNORMAL 1
 
lcUrl = "http://msdn.microsoft.com/vfoxpro"

* WSH
oShell = Createobject("wscript.shell")
oShell.Run(lcUrl)
*oShell.Run(lcUrl, SW_SHOWNORMAL)

* ShellExecute Win API
DECLARE Long ShellExecute IN "Shell32.dll" ;
      Long hwnd, String lpVerb, String lpFile, ;
      String lpParameters, String lpDirectory, Long nShowCmd
ShellExecute(0, "Open", lcUrl, "", "", SW_SHOWNORMAL)

* Shell object
oShell = CREATEOBJECT("Shell.Application")
oShell.Open(lcUrl)
 

What is wrong in this code?
Kind regards
LC
0
 
pcelbaCommented:
Everything is OK.

Sergey Berezniker published THREE different examples how to open web browser and display the web page... and you've executed all of them so the result is THREE browsers open...

You should select one method only.

You may also define the search term when invoking Google. To search for, e.g. My first Googling attempt  define the following URL:

lcUrl = "http://www.google.com/#q=My+first+Googling+attempt"


More advanced use of web browser is OLE automation where you can control almost everything programmatically from FoxPro or other language. See the following exsample: http://fox.wikis.com/wc.dll?Wiki~IEAutomationExample
0
 
Olaf DoschkeSoftware DeveloperCommented:
Do you really want a browser to open?

You can also put a Webbrowser Control on your form by adding an OLECONTROL to it from the form controls toolbar and choosing "Microsoft Web Browser" from the Insert Object dialog.

Then in your form button do
thisform.olecontrol1.navigate2("www.google.com")

VFP also offers the hyperlink control, which again opens a browser:
o = CreateObject("hyperlink")
o.NavigateTo("www.google.com")

Open in new window


And to complete the overview about possibilities you can also do a silent http request via

loRequest = Createobject('MsXml2.XmlHttp')
loRequest.Open("GET","http://www.google.com", .F.)
lcResponse = loRequest.ResponseText

Open in new window

This gives you the pure html code, no secondary requests are done, as a browser does, eg the google logo isn't loaded. The MsXml2.XmlHttp also offers an ResponseXML property and XML parsing options.

And last not least you can use
DECLARE INTEGER URLDownloadToFile IN urlmon.dll;
    INTEGER pCaller,;
    STRING  szURL,;
    STRING  szFileName,;
    INTEGER dwReserved,;
    INTEGER lpfnCB

nResult = URLDownloadToFile(0, "http://www.google.com", "D:\temp\google.html", 0,0)

Open in new window

...which returns the html of google.com into a html file. You can also request other things but the start page, you can eg download files like jpg, zip, etc, knowing their URL.

Bye, Olaf.
0
 
luciliacoelhoAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for luciliacoelho's comment #a39282904

for the following reason:

Ir worked as sent in the expert answer
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now