Link to home
Start Free TrialLog in
Avatar of lovely_bird
lovely_bird

asked on

WebBrowser

Hi,

I have the following question:

I want the user to be able to browse some sites in the internet.  That's mean, In my Visual Basic Program I want to have a link that takes me to the corresponding website.

But I wrote many codes but unforunately, I did not succeed. Really, I need your help.  I know this question is not easy I believe one of our experts can.

So Please HELP ME.

Thank you.
Avatar of lovely_bird
lovely_bird

ASKER

Please help me!!!!!!!!!!!!
Do you mean you want to be able to click on something, and launch the default browser to a specified web site, or do you want the default browser to be run and you control it from your vb program while it's running?

If you use the application setup wizard in the very beginning of your project, it will ask you if you want to include a web browser in your application to connect to sites.  That will build the browser for you (mostly).  Try giving that a try.
ASKER CERTIFIED SOLUTION
Avatar of YiannisVolos
YiannisVolos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Yiannis,
Thank you for your excellent answer.  But I have another question for you:

The current program that I am developing, when I finish it, I will make an executable file that can be run from any computer so, Imagine that I run this *.exe file on a computer that :
1. does not have an internet connection.
2. have an internet connection with a different path than what my computer (original) have

Does my program work propabley on both computers.  I beleive that the first case the program will not work.  but what about the second case.

Thank you very much Yiannis.
Waiting for your reply.


     Thank you for your excellent answer.  But I have another question for you:

     The current program that I am developing, when I finish it, I will make an
     executable file that can be run from any computer so, Imagine that I run this
     *.exe file on a computer that :
     1. does not have an internet connection.
     2. have an internet connection with a different path than what my computer
     (original) have

     Does my program work propabley on both computers.  I beleive that the first
     case the program will not work.  but what about the second case.

     Thank you very much Yiannis.
     Waiting for your reply.
Hello again...
Thanks for the points!

Well, it will work in both cases. That means it does not matter if your program runs a programs without an internet connection. However you should find the path of Internet Explorer's or you could ask the user to write it down and you could save it in the registry or in a file...

Regards,
Yiannis

Hi also again,
I think you did not understand my question.  I plan to put my VB program once I finish it on a CD Rom Disk, so you may use it also.  What I understand from you that I have to ask every one that will use my program or what.  How many shall I ask.
I like the method you tell me to use.  But I think I will be only able to connect to this site in the Internet because my Internet Explorer is locatted on my D:\ Drive.  So if someone has the Internet Explorer installed on the C:\ Drive this part of my program will not work, which I think it is NOT a good idea.
So what shall I do, please help me.
I am sorry for that but it seems to me that you are the only expert who understand me.
Thank you and I am waiting for your reply ASAP.
Thank you.
Hello again...
You seem you didnt understand how to use the command Shell...
My previews comment sais that you should either ask the user to enter the path of internet explorer and save it somewhere so you wont have to ask it again or seek it by yourself...

Example 1: Typing the path and saving it in the registry.
Lets assume that you have an options dialog where you have a txtbox called IEpath. The user now types the path but you want to save it...
After the user has pressed a button called OK, Apply or whatever you should add this code to save the information typed in the registry...

SaveSetting "MyApplication", "Options", "IE Path", IEpath.txt

Now the user goes at the About section of your program and you have their e.g. a button that is clicked and transfers you at the website...

At the button's source code type...
gotIEpath = GetSetting ("MyApplication", "Options", "IE Path")

i= Shell(gotIEpath+"iexplore.exe", VbNormalFocus)

(Within the path you could save and the name of the file so that you wont have to type '+ "iexplore.exe")

Please look up the syntax of the SaveSetting and GetSetting commands at your VB's help...

You can use Dir and find the path where iexplore.exe exists...

Regards,
Yiannis
Why not just open the default browser (the program associated with html files), or use
Shell ("Start http:\\www.infoseek.com")
Why not just open the default browser (the program associated with html files), or use
Shell ("Start http:\\www.infoseek.com")

To get the default browser - use

'@@@@@@@@ Insert this Code into a Module @@@@@@@@

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
   (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
   ByVal lpParameters As String, ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long
   
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
   (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As _
   String) As Long

' *******************************************************************
' Figure out what the user's default browser is
'
Private Sub DoBrowser(OutputFile As String)
   Dim FileName As String, Dummy As String
   Dim BrowserExec As String * 255
   Dim RetVal As Long
   Dim Filenumber As Integer
   Const SW_SHOWNORMAL = 1                   ' Restores Window if Minimized
   
   BrowserExec = Space(255)
   FileName = "C:\temphtm.HTM"
   
   Filenumber = FreeFile()                   ' Get unused file number
   
   Open FileName For Output As #Filenumber   ' Create temp HTML file
      Write #Filenumber, " <\HTML>"          ' Output text
   Close #Filenumber                         ' Close file
   
   ' Then find the application associated with it.
   RetVal = FindExecutable(FileName, Dummy, BrowserExec)
   BrowserExec = Trim$(BrowserExec)
   ' If an application is found, launch it!
   If RetVal <= 32 Or IsEmpty(BrowserExec) Then    ' Error
       MsgBox "Could not find a browser"
   
   Else
      RetVal = ShellExecute(frmMain.hwnd, "open", BrowserExec, _
         OutputFile, Dummy, SW_SHOWNORMAL)
      If RetVal <= 32 Then                   ' Error
         MsgBox "Page not opened"
      End If
   End If
   
   Kill FileName                             ' delete temp HTML file
   
End Sub


'@@@@@@@@ Insert this Code into a Form @@@@@@@@


DoBrowser "http:\\www.infoseek.com"
Hi spenner & YiannisVolos,
Thank you for taking the time to answer my question.  But I used spenner's method which is only write: Shell ("Start http:\\www.infoseek.com") and it works with me fine.
I want to ask is this only works with Internet Explorer Or it depends on our defualt browser?
Thank you again and sorry for bothering you.
Lovely Bird.
It works for whatever the default browser is I believe.  It's as if you typed the web address in the run box in the start menu