Results 1 to 5 of 5

Thread: How Can I Make It Go To web Page using the same browser ...............

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    How Can I Make It Go To web Page using the same browser and if there one not open one it well open one?

  2. #2
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Try this.

    .bas
    Code:
    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
    Dim success As Integer
    
    Function ShellToBrowser%(Frm As Form, ByVal URL$, ByVal WindowStyle%)
             Dim api%
                 api% = ShellExecute(Frm.hwnd, "open", URL$, "", App.Path, WindowStyle%)
          
             'Check return value
             If api% < 31 Then
                 'error code - see api help for more info
                 MsgBox App.Title & " had a problem running your web browser." & _
                   "You should check that your browser is correctly installed." & _
                   "(Error" & Format$(api%) & ")", 48, "Browser Unavailable"
                 ShellToBrowser% = False
             ElseIf api% = 32 Then
                 'no file association
                 MsgBox App.Title & " could not find a file association for " & _
                   URL$ & " on your system. You should check that your browser" & _
                   "is correctly installed and associated with this type of file.", 48, "Browser Unavailable"
                 ShellToBrowser% = False
             Else
                 'It worked!
                 ShellToBrowser% = True
          
             End If
             
    End Function
    Public Sub LaunchSite(Site As String, frm As Form)
    	success% = ShellToBrowser(frm, Site, 0)
    End Sub
    Form Code:
    Code:
    Private Sub Command1_Click()
    LaunchSite "http://www.vb-world.net", Me
    End Sub

    I'm not too sure that this will work, but try it... however I think it does.

    ------------------
    Tom Young, 14 Year Old
    [email protected]
    ICQ: 15743470
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's a routine I wrote a while back which does just that..

    In a Module..
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
    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 Const GW_CHILD = 5
    Private Const GW_HWNDNEXT = 2
    Private Const WM_SETTEXT = &HC
    Private Const WM_KEYDOWN = &H100
    
    Private lEditHwnd As Long
    
    Public Function NavigateIE(ByVal sString As String) As Boolean
        Dim lIEWnd As Long
        lIEWnd = FindWindowEx(0&, 0&, "IEFrame", vbNullString)
        If lIEWnd Then
            Call EnumHwnd(lIEWnd)
            Call SendMessage(lEditHwnd, WM_SETTEXT, 0&, ByVal sString)
            Call SendMessage(lEditHwnd, WM_KEYDOWN, vbKeyReturn, 0&)
            Call SetForegroundWindow(lIEWnd)
            NavigateIE2 = True
        Else
            ShellExecute 0, "OPEN", sString, "", "", 1
        End If
    End Function
    
    Private Sub EnumHwnd(ByVal hwnd As Long)
        Dim lChild As Long
        Dim sClass As String * 255
        lChild = GetWindow(hwnd, GW_CHILD)
        Do While lChild
            Call GetClassName(lChild, sClass, 255)
            If Left(sClass, 4) = "Edit" Then
                lEditHwnd = lChild
                Exit Do
            End If
            Call EnumHwnd(lChild)
            lChild = GetNextWindow(lChild, GW_HWNDNEXT)
        Loop
    End Sub
    Usage: NavigateIE "URL"

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    thanx everyone and arron i like yours the best and thanx

  5. #5
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    If all you want to do is display the page, why don't you just use a WebBrowser?

    It's a lot simpler:

    WebBrowser1.Navigate (your URL here)

    You can even keep it invisible until you need to use it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width