Solved

Get IE Address bar URL before the DNS is resolved

Posted on 2002-06-23
20
390 Views
Last Modified: 2007-11-27
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
0
Comment
Question by:AJAY CHADHA
20 Comments
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7102893
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7103019
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7108659
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7109773
Will look through the code tonight, cheers.
0
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7110257
Thanks man, I'll wait for your precious comments.

Ajay Chadha ... :-)
0
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7113859
Hi ryancys,

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

Ajay Chadha
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 200 total points
ID: 7115706
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7118758
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7118760
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7119665
Are you there ryansys..?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7121238
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7122506
I need to add the url from address bar to listbox as soon as the IE_BeforeNaviage option is fired

Thanks..!!

Ajay Chadha
0
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7122510
Sorry, but it should add the url to list box at this event
IENavigationBegin

Ajay Chadha
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7123939
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7125358
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7126098
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
 
LVL 8

Author Comment

by:AJAY CHADHA
ID: 7127848
if you can figure ot out. I tried to do it but its too messy code to get something out of it
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 7131430
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7962872
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
 
LVL 5

Expert Comment

by:Netminder
ID: 8023225
Per recommendation, force-accepted.

Netminder
EE Admin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now