Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

open browser in new window

2 views
Skip to first unread message

matt

unread,
Jan 23, 2000, 3:00:00 AM1/23/00
to
hi, i have a question.
i know how to open a website in a browser, but will open in it a browser
that is already open.

how do you get vb to open a website in a new window?

thanks
matt

Dougie Browser

unread,
Jan 23, 2000, 3:00:00 AM1/23/00
to
Add a new MDI Form, then add the browser form.

You can reset the internet address you want it to display
when it loads.

If Len(StartingAddress) > 0 Then

cboAddress.Text = StartingAddress
change the above line

cboAddress.AddItem cboAddress.Text
'try to navigate to the starting address
timTimer.Enabled = True
brwWebBrowser.Navigate StartingAddress
End If


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful

matt

unread,
Jan 23, 2000, 3:00:00 AM1/23/00
to
I guess i wasnt clear in my message. Just read it and it does not make much
sense to me.

what i ment is the following.

I have a button on a form. When you click on it, i want it to open the
default web browser and go to that address. The only probelm is that the
code that i have will open in in an internet explorer window that is open
already.

I want it to open it in a brand new window

thanks
matt
Dougie Browser <starwalke...@snowcrest.net.invalid> wrote in message
news:2885bff5...@usw-ex0109-069.remarq.com...

Howard Henry Schlunder

unread,
Jan 23, 2000, 3:00:00 AM1/23/00
to
Ben Bishop asked this exact same question two days ago.  Anyway, since nobody replied, I decided to code a solution and post it earlier today.  Here is what I replied with:
 
The recycling of windows is purely an intended design goal of your web browser.  If you want it to vary, you will have to launch the browser using some other method that forces fresh window creation.  While I've not tried it with other web browsers, it appears to lanuch new windows of Internet Explorer if you execute the actual filename and give the URL as a command line parameter instead of just executing the URL with the ShellExecute API call.  Anyway, I took the liberty to write some code for which will open the Registry, figure out what the default browser's command line is, close the registry, and finally use ShellExecute to lanuch a fresh web browser for you.  If my function fails, it will return False, otherwise True.
 
The following code uses very long lines and rather than manually splitting each VB line of code into segments, I've decided to just use the HTML format.  While it will certainly wrap while viewing it, if your Email/Newsgroup reader is halfway decent, you will still be able to cut and paste it into VB, retaining the proper locations of carrage return + line feeds.
 
Option Explicit
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData 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 HKEY_CLASSES_ROOT = &H80000000
Private Const ERROR_SUCCESS = 0&
Private Const SYNCHRONIZE = &H100000
Private Const KEY_NOTIFY = &H10
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_QUERY_VALUE = &H1
Private Const READ_CONTROL = &H20000
Private Const KEY_READ = ((READ_CONTROL Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
 
Private Function LaunchURLInNewBrowser(URL As String) As Boolean
Dim KeyHandle As Long, ValueType As Long
Dim StringSize As Long, RegString() As Byte, myString As String
  If RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\shell\open\command", 0, KEY_READ, KeyHandle) = ERROR_SUCCESS Then
    Call RegQueryValueEx(KeyHandle, "", 0, ValueType, StringSize, StringSize)
    ReDim RegString(0 To StringSize - 1)
    Call RegQueryValueEx(KeyHandle, "", 0, ValueType, RegString(0), StringSize)
    myString = Left$(StrConv(RegString, vbUnicode), UBound(RegString))
    Call RegCloseKey(KeyHandle)
    myString = Left$(myString, InStrRev(myString, """", , vbBinaryCompare) - 1)
    myString = Right$(myString, Len(myString) - 1)
    If ShellExecute(Me.hwnd, "open", myString, URL, "", vbNormalFocus) > 32 Then
      LaunchURLInNewBrowser = True
    End If
  End If
End Function
 
Private Sub Command1_Click()
  LaunchURLInNewBrowser "http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?ViewItem&item=239850613"
End Sub

 
Howard Henry Schlunder
 

Ben Bishop

unread,
Jan 25, 2000, 3:00:00 AM1/25/00
to
"Howard Henry Schlunder" <howa...@yahoo.com> writes:

>Ben Bishop asked this exact same question two days ago. Anyway, since =
>nobody replied, I decided to code a solution and post it earlier today. =


>Here is what I replied with:

I was surprised that your posting had sigfnificantly different
encoding than the e-mail version you had sent me. The version on
c.l.v-b.m had both text and html version, both of which were
absolutely useless for cutting and pasting using my text newsgroup
reader (but the e-mail was easier, thanks) (see the above quote-lines
for an example of one of the problems -- the trailing "="s which I
believe are part of mime-encoding)

In either case, the code didn't work in VB5, the first error being the
use of "InStrRev" which was not found. Since I had a working
alternative by then, I didn't try to hunt down any other possible
problems.

I appologize for not mentioning the version of VB I was working with.

Ian Williams sent me some other code which does seem to work in VB5
(and does exactly what I need); I hope he doesn't mind me posting it,
but I didn't see his response in the newsgroup...

From: Ian Williams <i...@kingsoft-denmark.com>
To: Ben Bishop <a...@shore.net>
Subject: Re: starting a _new_ browser window

you can do it like this, just call the Sub LaunchNewBrowser, passing
it the URL you want to display.

********
'Module code

Option Explicit
Option Compare Text

Private Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, _
ByVal lpResult As String) As Long

Dim strDefPath As String

Sub LaunchNewBrowser(strURL As String)
Dim z
If strDefPath = "" Then strDefPath = GetExePath("htm")
If strDefPath = "NoExtension" Or strDefPath = "NoDefApp" Then
'Handle error
Else
z = Shell(strDefPath & " " & strURL, 1)
End If
End Sub

Private Function GetExePath(Extension As String) As String
Dim Result As String, z As Long, Path As String
Dim FileName As String, fnum As Integer
If Extension = "" Then
GetExePath = "NoExtension"
Exit Function
End If
Result = Space$(270)
Path = Environ("temp") & "\"
FileName = "~testing." & Extension
fnum = FreeFile
Open Path & FileName For Output As #fnum
Close #fnum
z = FindExecutable(FileName, Path, Result)
Kill Path & FileName
Do While fnum > 0
fnum = InStr(Result, Chr(0))
If fnum > 0 Then Mid(Result, fnum, 1) = " "
Loop
Result = Trim(Result)
fnum = InStr(Result, ".EXE")
If Len(Result) > 0 And fnum > 0 Then
Result = Left$(Result, fnum) & "EXE"
GetExePath = Result
Else
GetExePath = "NoDefApp"
End If
End Function
**********


regards

Ian Williams

homepage http://www.kingsoft-denmark.com/


----- Original Message -----
From: Ben Bishop <a...@shore.net>
Newsgroups: comp.lang.basic.visual.misc
Sent: Friday, January 21, 2000 11:01 PM
Subject: starting a _new_ browser window


> I'm sure part of this is in a faq -- I've seen it ot posed often enough,
> but there is a twist to it.
>
> My VB program has a url it wants to launch (actually, it may have many).
>
> Is there any syntax which will launch the browser in a _new_ window?
> I don't particularly like having an existing window taken over and
> replaced by the new page.
>
> Any help would be appreciated.
>
> Ben Bishop
> aci @ shore.net

Kackerot

unread,
Jan 27, 2000, 3:00:00 AM1/27/00
to
I'm pretty sure you can just do:

Dim URL As String
Private Sub Command1_Click()
webbrwsr = Shell("Start " & URL, vbNormalFocus)
End
End Sub

That should open the default web browser

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


0 new messages