Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Retrieve IE4.0 URL for use in VB

Posted on 1999-07-23
2
Medium Priority
?
227 Views
Last Modified: 2010-08-05
I'm writing a program that will store the current
URL (in VB) that a user is browsing from IE 4.0. The event
is triggered when they click on a VB command "cmdSaveURL".

1. Can you offer some code that will retrieve the URL from
their browser?

2. Can you off som code that will place a new URL in the
users IE 4.0 so that the existing window goes to the new URL - without launching a new EI4.0 window?
0
Comment
Question by:rickwinterkorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:y2kwacko
ID: 1527029
I don't have IE4 installed but you can go about this using the FindWindow, FindWindowEx function to get the handle of the combobox IE4 uses for the url then you can either use PastMessage or SendMessage with the WM_GETTEXT to retrieve the url it is at you can use PostMessage or SendMessage with WM_SETTEXT to set the url if you want a sample using these functions I can give you one feel free to ask

Good Luck
Kevin
0
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1527030
' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : http://www.vb-helper.com/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 24/11/98
' * Time             : 13:12
' * Module Name      : GetInternetAdress_Module
' * Module Filename  : InternetAdress.bas
' **********************************************************************
' * Comments         : See what URL Netscape or Internet Explorer is displaying.
' * Use the EnumWindows and GetWindowText API functions to look for a window
' * with title ending in " - Netscape" and " - Microsoft Internet Explorer".
' * Then search the window and its children
' * for an Edit object. Finally, use the WM_GETTEXTLENGTH message to see what
' * value the object holds.
' *
' **********************************************************************

Option Explicit

Global gcolAdress       As Collection

Public Type ProcData
   AppHwnd     As Long
   title       As String
   Placement   As String
   left        As Long
   tOp         As Long
   Right       As Long
   Bottom      As Long
End Type

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName 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 Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE

Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDFIRST = 0

Public Function EditInfo(window_hwnd As Long) As String
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 24/11/98
   ' * Time             : 13:14
   ' * Module Name      : GetInternetAdress_Module
   ' * Module Filename  : Module1.bas
   ' * Procedure Name   : EditInfo
   ' * Parameters       :
   ' *                    window_hwnd As Long
   ' **********************************************************************
   ' * Comments         :
   ' * If this window is of the Edit class, return
   ' * its contents. Otherwise search its children
   ' * for an Edit object.
   ' *
   ' **********************************************************************

   Dim txt           As String
   Dim buf           As String
   Dim buflen        As Long
   Dim child_hwnd    As Long
   Dim children()    As Long
   Dim num_children  As Integer
   Dim I             As Integer

   ' Get the class name.
   buflen = 256
   buf = Space$(buflen - 1)
   buflen = GetClassName(window_hwnd, buf, buflen)
   buf = left$(buf, buflen)

   ' See if we found an Edit object.
   If buf = "Edit" Then
      EditInfo = WindowText(window_hwnd)
      Exit Function
   End If

   ' It's not an Edit object. Search the children.
   ' Make a list of the child windows.
   num_children = 0
   child_hwnd = GetWindow(window_hwnd, GW_CHILD)
   Do While child_hwnd <> 0
      num_children = num_children + 1
      ReDim Preserve children(1 To num_children)
      children(num_children) = child_hwnd

      child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
   Loop

   ' Get information on the child windows.
   For I = 1 To num_children
      txt = EditInfo(children(I))
      If txt <> "" Then Exit For
   Next

   EditInfo = txt

End Function

Public Function WindowText(window_hwnd As Long) As String
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 24/11/98
   ' * Time             : 13:15
   ' * Module Name      : GetInternetAdress_Module
   ' * Module Filename  : Module1.bas
   ' * Procedure Name   : WindowText
   ' * Parameters       :
   ' *                    window_hwnd As Long
   ' **********************************************************************
   ' * Comments         : Return the text associated with the window.
   ' *
   ' *
   ' **********************************************************************

   Dim txtlen     As Long
   Dim txt        As String

   WindowText = ""
   If window_hwnd = 0 Then Exit Function

   txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
   If txtlen = 0 Then Exit Function

   txtlen = txtlen + 1
   txt = Space$(txtlen)
   txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
   WindowText = left$(txt, txtlen)

End Function

Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
   
   Dim sBuf       As String * 1024
   Dim sBrowser   As String
   Dim nLength    As Long
   Dim sTmp       As String
   Dim clsLink    As class_HTMLLink

   ' *** Get the window's title.
   nLength = GetWindowText(app_hwnd, sBuf, Len(sBuf))
   sBrowser = left$(sBuf, nLength)

   ' *** See if the title ends with " - Netscape".
   ' *** or
   ' *** See if the title ends with " - Microsoft Internet Explorer".
   If (Right$(sBrowser, 30) = " - Microsoft Internet Explorer") Or (Right$(sBrowser, 11) = " - Netscape") Or (left$(sBrowser, 11) = "Netscape - ") Then
     
      Set clsLink = New class_HTMLLink
     
      ' *** This is it. Find the ComboBox information.
      If (Right$(sBrowser, 30) = " - Microsoft Internet Explorer") Then ' *** IE4
         clsLink.sTitle = left(sBrowser, Len(sBrowser) - 30)
         clsLink.bNetscape = False
      ElseIf (Right$(sBrowser, 11) = " - Netscape") Then                ' *** Netscape 4
         clsLink.sTitle = left(sBrowser, Len(sBrowser) - 11)
         clsLink.bNetscape = True
      ElseIf (left$(sBrowser, 11) = "Netscape - ") Then                 ' *** Netscape 3
         clsLink.sTitle = Right(sBrowser, Len(sBrowser) - 11)
         clsLink.bNetscape = True
      Else
         clsLink.sTitle = sBrowser
      End If
     
      clsLink.sURL = EditInfo(app_hwnd)

      On Error Resume Next
      gcolAdress.Add clsLink, clsLink.sURL

      Set clsLink = Nothing
     
      ' *** Continue searching for other browser
      EnumProc = 1
   
   Else
      ' *** Continue searching til find it.
      EnumProc = 1
   End If

End Function


0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question