Get IE Address bar URL before the DNS is resolved

Is it possible in VB to Get IE Address bar URL before the DNS is actualy resolved. I mean to say to get the url of address bar as soon as the url is entered and the enter key is pressed or GO button is clicked.

Thanks for your comments..!

Ajay Chadha
LVL 8
AJAY CHADHAAsked:
Who is Participating?
 
Ryan ChongCommented:
Hi Ajay Chadha,

Sorry for the delay, as i'm not online yesterday.

I found that the Ark's is a little bit complicated, so i had developed a new version myself.

Here is it:

Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_NORMAL = 1
Private Declare Function GetTickCount& Lib "kernel32" ()

Private WithEvents IE As SHDocVw.InternetExplorer
Dim i As Long, MinHeight As Long, MaxHeight As Long, itemIndex As Long
Dim t1 As Long, t2 As Long, t3 As Long

Private Sub UpdateIEList(ByRef lv As ListView)
    Dim eIEShellWindow As New SHDocVw.ShellWindows
    Dim eIE As SHDocVw.InternetExplorer
    lv.ListItems.Clear
    i = 0
    itemIndex = 0
    For Each eIE In eIEShellWindow
        i = i + 1
        lv.ListItems.Add i, , eIE.LocationName
        lv.ListItems(i).Tag = eIE.hwnd
        lv.ListItems(i).SubItems(1) = "" & eIE.LocationURL
        DoEvents
    Next
    If lv.ListItems.Count > 0 Then
        itemIndex = i
        SelectLVItem i
        lv.ListItems(i).Selected = True
        Set IE = eIEShellWindow(i - 1)
        Label3 = IE.LocationURL
    End If
End Sub

Private Sub SelectLVItem(ByVal Index As Long)
    Dim i As Long
    For i = 1 To ListView1.ListItems.Count
        If i = Index Then ListView1.ListItems(i).Checked = True Else ListView1.ListItems(i).Checked = False
    Next i
End Sub

Private Sub Check1_Click()
    WebBrowser1.Visible = Check1.Value
    If Check1.Value = 1 Then
        Me.Height = MaxHeight
        If Not IE Is Nothing Then WebBrowser1.Navigate IE.LocationURL
    Else
        Me.Height = MinHeight
    End If
    Me.Left = (Screen.Width - Me.Width) / 2
    Me.Top = Screen.Height - Me.Height - 420
End Sub

Private Sub Form_Activate()
    UpdateIEList ListView1
End Sub

Private Sub Form_Load()
    Label1 = "Check to Monitor"
    Label2 = ""
    Label3 = ""
   
    Check1.Caption = "Show IE Window"
    ListView1.ColumnHeaders.Add , , "Document Title"
    ListView1.ColumnHeaders(1).Width = 2500
    ListView1.ColumnHeaders.Add , , "Document URL"
    ListView1.ColumnHeaders(2).Width = ListView1.Width - ListView1.ColumnHeaders(1).Width - 360
    ListView1.View = lvwReport
    ListView1.HideSelection = False
    ListView1.Checkboxes = True
    ListView1.LabelEdit = lvwManual
    ListView1.FullRowSelect = True
   
    MinHeight = WebBrowser1.Top + 240
    MaxHeight = Me.Height
    Check1_Click
   
    Me.Left = (Screen.Width - Me.Width) / 2
    Me.Top = Screen.Height - Me.Height - 420
   
End Sub

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
    On Error Resume Next
    Dim h As Long
   
    If ListView1.ListItems.Count = 0 Then Exit Sub
   
    itemIndex = Item.Index
    SelectLVItem itemIndex
   
    Dim eIEShellWindow As New SHDocVw.ShellWindows
    Dim eIE As SHDocVw.InternetExplorer
    For Each eIE In eIEShellWindow
        If eIE.hwnd = Val(Item.Tag) Then
            Set IE = eIE
            Label3 = IE.LocationURL
            If WebBrowser1.Visible Then WebBrowser1.Navigate IE.LocationURL
            h = ShowWindow(IE.hwnd, SW_NORMAL)
            h = BringWindowToTop(IE.hwnd)
            Exit For
        End If
        DoEvents
    Next
End Sub

Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    On Error Resume Next
    ListView1.ToolTipText = "IE Handle: " & ListView1.HitTest(x, y).Tag
End Sub

Private Sub IE_DownloadBegin()
    t1 = GetTickCount
    Debug.Print "Start: " & t1
    Label2 = "Download Begin"
End Sub

Private Sub IE_DownloadComplete()
    t3 = GetTickCount
    Debug.Print "Complete: " & t3
    Label2 = "Download Complete"
    DoEvents
    Sleep 1000
    Label2 = ""
End Sub

Private Sub IE_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    t2 = GetTickCount
    Debug.Print "Process: " & t3 & ": " & IE.LocationURL
    ListView1.ListItems(itemIndex).SubItems(1) = "" & IE.LocationURL
End Sub

'I'm not quite sure if this is what you're looking for, hope this will make help.

regards
0
 
priya_pbkCommented:
How are you doing this in Vb, i mean you are opening an IE or you are having a web browser on the form.

Could you elaborate...or tell us what your application is doing?

-priya
0
 
Ryan ChongCommented:
See this example by Ark if it's help:

Receive Events from and Send Events to Open IE Windows:
http://www.freevbcode.com/ShowCode.Asp?ID=1606
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
AJAY CHADHAAuthor Commented:
Hello ryancys,

Yes, That code has exactly what I'm looking for but I hope you will agree on this issue that the part I'm looking for is

Private Sub IEWin_IENavigationBegin(hwnd As Long, ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)

Could you pls look into the code and create a simpler version out of it because i don't want to use all that code for just a single purpose.

Thanks for your comments.

Ajay Chadha
0
 
Ryan ChongCommented:
Will look through the code tonight, cheers.
0
 
AJAY CHADHAAuthor Commented:
Thanks man, I'll wait for your precious comments.

Ajay Chadha ... :-)
0
 
AJAY CHADHAAuthor Commented:
Hi ryancys,

Did you found some spare time to have a look at the code..?

Ajay Chadha
0
 
AJAY CHADHAAuthor Commented:
Hello Ryansys,

I'm sorry but I was looking for the IE_DownloadComplete event and your code doesn't have it.

Well, to make it more simple. I'm looking for a code which will add the IE url to the a listbox (not listview) as soon as it is typed and this can be done in IE_DownloadComplete event.

Thanks and Will wait for your reply..!

Ajay Chadha
0
 
AJAY CHADHAAuthor Commented:
Also, I'm gettign the 429 error "ActiveX Component can't create object" on the following line

Dim eIEShellWindow As New SHDocVw.ShellWindows

Ajay Chadha
0
 
AJAY CHADHAAuthor Commented:
Are you there ryansys..?
0
 
Ryan ChongCommented:
Sorry for the delay Chadhaajay.

> "ActiveX Component can't create object" on the following line

Dim eIEShellWindow As New SHDocVw.ShellWindows

We need to add the M$ HTML Object Library from the Reference.

and

> Well, to make it more simple. I'm looking for a code which will add the IE url to the a listbox (not listview) as soon as it is typed and this can be done in IE_DownloadComplete event.

So is that means Add an item to ListBox after the IE_DownloadComplete event fired? Anyway, i will try figure it..

* I'm now only will be available online 3 times a week (typically Mon,Wed & Fri in my timezone, +8 hours), so you'll not able to see me tomorrow.. Sorry about that.

regards,
ryancys
0
 
AJAY CHADHAAuthor Commented:
I need to add the url from address bar to listbox as soon as the IE_BeforeNaviage option is fired

Thanks..!!

Ajay Chadha
0
 
AJAY CHADHAAuthor Commented:
Sorry, but it should add the url to list box at this event
IENavigationBegin

Ajay Chadha
0
 
Ryan ChongCommented:
Dear chadhaajay,
I think this should be the simplest one!
This time i use the Timer to keep trick the URL from the IE Windows. (Don't know whether you like to use Timer or not, but since using Timer, we don't need IENavigationBegin event already..). Hope this will finally solve your problem.

regards,
ryancys

Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long

Dim i As Long, j As Long

Private Sub UpdateIEList()
    Dim eIEShellWindow As New SHDocVw.ShellWindows
    Dim eIE As SHDocVw.InternetExplorer
    List1.Clear
    i = 0
    For Each eIE In eIEShellWindow
        List1.AddItem "" & eIE.LocationURL, i
        'Save the Handle for futher use if needed
        List1.ItemData(i) = eIE.hwnd
        i = i + 1
        DoEvents
    Next
End Sub

Private Sub Command1_Click()
    Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
    Timer1.Enabled = False
End Sub

Private Sub Form_Activate()
    UpdateIEList
End Sub

Private Sub Form_Load()
    StayOnTop Me, True
    Timer1.Interval = 1000 '10 ?
    Timer1.Enabled = False
    Command1.Caption = "Monitoring"
    Command1.Caption = "Stop Monitoring"
End Sub

Private Sub List1_Click()
    On Error Resume Next
    Label1.Caption = "Window Handle: " & List1.ItemData(List1.ListIndex)
End Sub

Private Sub Timer1_Timer()
    UpdateIEList
End Sub

Private Sub StayOnTop(frm As Form, fOnTop As Boolean)
    Dim lState As Long
    Dim iLeft As Integer, iTop As Integer, iWidth As Integer, iHeight As Integer
    With frm
        iLeft = .Left / Screen.TwipsPerPixelX
        iTop = .Top / Screen.TwipsPerPixelY
        iWidth = .Width / Screen.TwipsPerPixelX
        iHeight = .Height / Screen.TwipsPerPixelY
    End With
    If fOnTop Then
        lState = HWND_TOPMOST
    Else
        lState = HWND_NOTOPMOST
    End If
    Call SetWindowPos(frm.hwnd, lState, iLeft, iTop, iWidth, iHeight, 0)
End Sub
0
 
AJAY CHADHAAuthor Commented:
Hello Ryansys,

you are still not on my point. I was talking to get the url as soon as it is typed in address bar text box, but yours is not the one i asked for.

I want to have the url added to the listbox as soon as it is typed in adress bar and enter key is pressed.

I don't expected the coe above. I need the modification to Ark's Code..!

Will you pls look in that code and specially at the IEBeforeNavigate event

Ajay Chadha
0
 
Ryan ChongCommented:
So the code posted on 06/27/2002 11:34PM PST is not working too? But i think you can customize the code yourself, isn't it?..
0
 
AJAY CHADHAAuthor Commented:
if you can figure ot out. I tried to do it but its too messy code to get something out of it
0
 
Ryan ChongCommented:
That's the problem, i face some difficulties to remove unused code from Ark's sample. So, that's why i only can do what i can do :(
0
 
DanRollinsCommented:
Hi chadhaajay,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.

chadhaajay, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
NetminderCommented:
Per recommendation, force-accepted.

Netminder
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.