how to open webbrowser using Vb6.0
hi,
i am creating an application in which i want to do when any user click on button of caption"open" then automatically webbrowser should open with url which i will be given. for eg. if i ve give www.yahoo.com should open when button click. if user click on open button then automatically yahoo.com should open in web browser(machine's default browser any I.E. or Mozilla or netscape ) .
can anyone tell me how to do that
Re: how to open webbrowser using Vb6.0
Quote:
Originally Posted by query4u
hi,
i am creating an application in which i want to do when any user click on button of caption"open" then automatically webbrowser should open with url which i will be given. for eg. if i ve give
www.yahoo.com should open when button click. if user click on open button then automatically yahoo.com should open in web browser(machine's default browser any I.E. or Mozilla or netscape ) .
can anyone tell me how to do that
The easiest way would be to use ShellExecute API
Code:
Private 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
Const SW_SHOWNORMAL = 1
Private Sub CommandButton1_Click()
ShellExecute Me.hwnd, vbNullString, "http://www.yahoo.com", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Re: how to open webbrowser using Vb6.0
Code:
'GEneral Declarations
Private 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
Private Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As _
String, ByVal lpResult As String) As Long
Private Sub cmdOpen_Click()
Dim FileName, Dummy As String
Dim BrowserExec As String * 255
Dim RetVal As Long
Dim FileNumber As Integer
' First, create a known, temporary HTML file
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> <\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 associated Browser", vbExclamation, _
"Browser Not Found"
Else
RetVal = ShellExecute(Me.hwnd, "open", BrowserExec, _
"http://www.yahoo.com", Dummy, 3)
If RetVal <= 32 Then ' Error
MsgBox "Web Page not Opened", vbExclamation, "URL Failed"
End If
End If
Kill FileName ' delete temp HTML file
End Sub
Re: how to open webbrowser using Vb6.0
thanx HanneSThEGreaT for your solution.