Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reusing a system's default browser

Status
Not open for further replies.

ninomeister

Programmer
Aug 1, 2002
3
US
I am implementing a help support feature a project that I am working on. I would like to allow support for multiple browsers depending on the user's defualt browser. This seems to work fine, however, currently, I create a new browser window each time help is called. What I would like to do is reuse the same browser window for each successive call to help while a browser (the initial default browser) is open. Is there any suggesstions that would help solve this problem. I know that there are web browsing controls in vb, but I do not want to use them because I would really like to allow support for multiple browsers. Thanks.
 
This seems to work

Grant

'--------------

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 Sub Command1_Click()
Dim HTMLFileName As String
HTMLFileName = "LaunchURLInNewBrowser HTMLFileName
End Sub

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
 
Hi,

I've only tested this with IE (since that'a my default browser), but it should work for any browser.
It opens the pages in the same window.

-----------------------------------------------------------
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 SW_SHOW = 1


Private Sub Command1_Click()
Dim hBrowse As Long
hBrowse = ShellExecute(0&, "open", " "", "", SW_SHOW)
End Sub
Private Sub Command2_Click()
Dim hBrowse As Long
hBrowse = ShellExecute(0&, "open", " "", "", SW_SHOW)
End Sub
----------------------------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Thank you for the help. I have tried the ShellExecute command and found that it does indeed display new links within the same browser. However, I am trying to link to tags that I have set up in the html file I created and it does not seem that I am able to do this correctly. For example, if I was trying to get to the top of a page, I would like to have ShellExecute open up the my html file there.

ex. ShellExecute 0&, "help.html#top", "", "", 1

This does not seem to work. However, if I use the Shell command it will, but I get multiple windows. Is there any other way that I could get the behaviour I'm looking for, using any default browser (I know this will work for just IE)? Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top