By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Caturing ACTIVE IE Url

P: n/a
I am looking to capture the URL of the ACTIVE IE window.

How the heck can I determine which window is the active window.

Better yet how do I grab the URL of that particular window ?

I am searching and searching but see no VB samples of anything I want
to do.

I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that
use the IE control, as was mentioned things like Kazza as well.

This .Net can be so damm frustrating sometimes, I mean I love the
power of it but all the code I wrote from VB4-VB6 is pretty much
useless and archane.

Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

Chris
Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
> Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out. heheheh :)
I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that this code will help

ok, well it wont be done with the help of .net libs. But you can do it with
interoperating with win32api. now all you need to do is get the forground
window handle using GetForegroundWindow and than use the EnumChildWIndows
api to find the address window. You'll need to know its class which u'll get
from spy++ and than send it a WM_GETTEXT message to get the url written
inside it.
I hope this helps. But to save you from getting bald if you say I can try to
do it for you and post the actuall code in vb.net.

- Abubakar (not an MVP :) )

"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14*************************@posting.google.co m... I am looking to capture the URL of the ACTIVE IE window.

How the heck can I determine which window is the active window.

Better yet how do I grab the URL of that particular window ?

I am searching and searching but see no VB samples of anything I want
to do.

I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that
use the IE control, as was mentioned things like Kazza as well.

This .Net can be so damm frustrating sometimes, I mean I love the
power of it but all the code I wrote from VB4-VB6 is pretty much
useless and archane.

Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

Chris


Nov 20 '05 #2

P: n/a
> Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out. heheheh :)
I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that this code will help

ok, well it wont be done with the help of .net libs. But you can do it with
interoperating with win32api. now all you need to do is get the forground
window handle using GetForegroundWindow and than use the EnumChildWIndows
api to find the address window. You'll need to know its class which u'll get
from spy++ and than send it a WM_GETTEXT message to get the url written
inside it.
I hope this helps. But to save you from getting bald if you say I can try to
do it for you and post the actuall code in vb.net.

- Abubakar (not an MVP :) )

"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14*************************@posting.google.co m... I am looking to capture the URL of the ACTIVE IE window.

How the heck can I determine which window is the active window.

Better yet how do I grab the URL of that particular window ?

I am searching and searching but see no VB samples of anything I want
to do.

I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that
use the IE control, as was mentioned things like Kazza as well.

This .Net can be so damm frustrating sometimes, I mean I love the
power of it but all the code I wrote from VB4-VB6 is pretty much
useless and archane.

Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

Chris


Nov 20 '05 #3

P: n/a
I want to thank you for the direction, I was missing the
GetForegroundWindow
I didnt like having to go through all the other hoops so Ive
simplified it a bit here is the code for posterity and anyone else
looking to do what I have done. Basically it dosnet do anything except
say IE is not the Forground window unless it is triggered from and IE
add in since well IE will not be in the foreground :)

Im lazy thats part of why I enjoy programming so darn much (toung in
cheek) so I was basically too lazy to do all the things you suggested
so here is what I found works ......

Anyhoo here is the code.
Inherits System.Windows.Forms.Form
Private IEs As New SHDocVw.ShellWindows
Private IE As SHDocVw.InternetExplorer
Private Declare Function GetForegroundWindow Lib "user32" () As
Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim Ret As Long

For Each IE In IEs
'Here we will compare the ACTIVE IE.HWND
Ret = GetForegroundWindow()
If Ret = IE.HWND Then
MsgBox(IE.LocationURL)

Else

MsgBox("IE is not the foreground window the active
window is " & Ret & " the IE it is accessing is " & IE.HWND)
End If

Next

End Sub

Doing it this way there is no reason to "then use the EnumChildWIndows
api to find the address window. You'll need to know its class which
u'll get
from spy++ and than send it a WM_GETTEXT"

Thanks again

Chris


"Abubakar" <em**********@yahoo.com> wrote in message news:<O9*************@TK2MSFTNGP12.phx.gbl>...
Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

heheheh :)
I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that

this code will help

ok, well it wont be done with the help of .net libs. But you can do it with
interoperating with win32api. now all you need to do is get the forground
window handle using GetForegroundWindow and than use the EnumChildWIndows
api to find the address window. You'll need to know its class which u'll get
from spy++ and than send it a WM_GETTEXT message to get the url written
inside it.
I hope this helps. But to save you from getting bald if you say I can try to
do it for you and post the actuall code in vb.net.

- Abubakar (not an MVP :) )

"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14*************************@posting.google.co m...
I am looking to capture the URL of the ACTIVE IE window.

How the heck can I determine which window is the active window.

Better yet how do I grab the URL of that particular window ?

I am searching and searching but see no VB samples of anything I want
to do.

I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that
use the IE control, as was mentioned things like Kazza as well.

This .Net can be so damm frustrating sometimes, I mean I love the
power of it but all the code I wrote from VB4-VB6 is pretty much
useless and archane.

Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

Chris

Nov 20 '05 #4

P: n/a
Whooppppsss I posted the wrong code.......oh well here is what works
as an IE add in.


Module Module1

Private IEs As New SHDocVw.ShellWindows
Private IE As SHDocVw.InternetExplorer
Private Declare Function GetForegroundWindow Lib "user32" () As
Int32


Sub Main()
Dim objWebClient As New WebClient
Dim objUTF8 As New UTF8Encoding

Dim Ret As Int32

For Each IE In IEs
'Here we will compare the ACTIVE IE.HWND
Ret = GetForegroundWindow()
If Ret = IE.HWND Then

MsgBox(IE.LocationURL)
End If

Next


End Sub

End Module

Have fun.....

cw******@yahoo.com (Chris Wertman) wrote in message news:<14**************************@posting.google. com>...
I want to thank you for the direction, I was missing the
GetForegroundWindow
I didnt like having to go through all the other hoops so Ive
simplified it a bit here is the code for posterity and anyone else
looking to do what I have done. Basically it dosnet do anything except
say IE is not the Forground window unless it is triggered from and IE
add in since well IE will not be in the foreground :)

Im lazy thats part of why I enjoy programming so darn much (toung in
cheek) so I was basically too lazy to do all the things you suggested
so here is what I found works ......

Anyhoo here is the code.
Inherits System.Windows.Forms.Form
Private IEs As New SHDocVw.ShellWindows
Private IE As SHDocVw.InternetExplorer
Private Declare Function GetForegroundWindow Lib "user32" () As
Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim Ret As Long

For Each IE In IEs
'Here we will compare the ACTIVE IE.HWND
Ret = GetForegroundWindow()
If Ret = IE.HWND Then
MsgBox(IE.LocationURL)

Else

MsgBox("IE is not the foreground window the active
window is " & Ret & " the IE it is accessing is " & IE.HWND)
End If

Next

End Sub

Doing it this way there is no reason to "then use the EnumChildWIndows
api to find the address window. You'll need to know its class which
u'll get
from spy++ and than send it a WM_GETTEXT"

Thanks again

Chris


"Abubakar" <em**********@yahoo.com> wrote in message news:<O9*************@TK2MSFTNGP12.phx.gbl>...
Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

heheheh :)
I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that

this code will help

ok, well it wont be done with the help of .net libs. But you can do it with
interoperating with win32api. now all you need to do is get the forground
window handle using GetForegroundWindow and than use the EnumChildWIndows
api to find the address window. You'll need to know its class which u'll get
from spy++ and than send it a WM_GETTEXT message to get the url written
inside it.
I hope this helps. But to save you from getting bald if you say I can try to
do it for you and post the actuall code in vb.net.

- Abubakar (not an MVP :) )

"Chris Wertman" <cw******@yahoo.com> wrote in message
news:14*************************@posting.google.co m...
I am looking to capture the URL of the ACTIVE IE window.

How the heck can I determine which window is the active window.

Better yet how do I grab the URL of that particular window ?

I am searching and searching but see no VB samples of anything I want
to do.

I have a bit of code that will grab the URL but it grabs the URL of
ALL IE instances NOT just the active one , this includes things that
use the IE control, as was mentioned things like Kazza as well.

This .Net can be so damm frustrating sometimes, I mean I love the
power of it but all the code I wrote from VB4-VB6 is pretty much
useless and archane.

Im losing my hair on this one.....next week Ill be bald if I dont get
this figured out.

Chris

Nov 20 '05 #5

P: n/a
Hi Chris,

I was the one who answered you in the other newsgroup.
What I do not know is how do you become your Docs, that can in a lot of ways
it can using streaming or using the axwebbrowser and create your own mini
IE.

To see an example of this download this than you have that minibrowser.

http://support.microsoft.com/?kbid=311303

There is also a little bit the mshtml in.

This is a link about mshtml do not think it is nice stuff, although very
effective

http://msdn.microsoft.com/library/de...ng/hosting.asp

And with this there are mostly 2 methodes, with nothing at the end and with
2 at the end, try to use the methods with a 2 at the end.

When you use this you have to set in the beginning Option Strict Off

When you are something further with it, ask again, mostly this questions are
answered in this newsgrou by Charles Law and when not than by me.

I hope this helps a little bit.

Cor




Nov 20 '05 #6

P: n/a
Here is the entire code to do what I am doing so far , I dont like how I
am doing the string replacment I would hink I could just grab it all in
a regular expression.

I am a little confused as to using th mshtml and how that would offer
any benifit over what I am doing now.

Here is how I am doing it.

Imports System.Text
Imports System.Net
Imports System.Text.RegularExpressions

Module Module1

Private IEs As New SHDocVw.ShellWindows
Private IE As SHDocVw.InternetExplorer
Private Declare Function GetForegroundWindow Lib "user32" () As
Int32

Sub Main()
Dim objWebClient As New WebClient
Dim objUTF8 As New UTF8Encoding

Dim Ret As Int32

For Each IE In IEs
'Here we will compare the ACTIVE IE.HWND
'Title is in this format
'<span class="header6">
'Tom Hawke (Orig. Title: the Link Boys)
'</span>

'Author is in this format
'
Ret = GetForegroundWindow()
If Ret = IE.HWND Then

Dim html As String =
objUTF8.GetString(objWebClient.DownloadData(IE.Loc ationURL))
'Multiple Regex here ?
Dim regex As New Regex("<span
class=""header6"">((.|\n)*?)</span>", RegexOptions.IgnoreCase)
Dim re As New Regex("<[^>]*>", RegexOptions.IgnoreCase)
Dim regex2 As New Regex("<b>Binding:</b>((.|\n)*?)<br>
<b>Publisher:", RegexOptions.IgnoreCase)

'Dim regex As New Regex("<b>Binding:</b>((.|\n)*?)<br>
<b>Publisher:", RegexOptions.IgnoreCase)
'MsgBox(IE.LocationURL)
' Dim Match = regex.Match(html)

Dim title, author, binding, condition As String
title = regex.Match(html).ToString
title = re.Replace(title, "")
binding = regex2.Match(html).ToString
binding = re.Replace(binding, "")
binding = Replace(binding, "Binding:", "")
binding = Replace(binding, "Publisher:", "")

MsgBox(Ret & Trim(title) & " " & binding)
End If

Next


End Sub

End Module

Any suggestions on how I could clean up the stripping of Title and
author would be appreciated.

Chris

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7

P: n/a
Here is the entire code to do what I am doing so far , I dont like how I
am doing the string replacment I would hink I could just grab it all in
a regular expression.

I am a little confused as to using th mshtml and how that would offer
any benifit over what I am doing now.

Here is how I am doing it.

Imports System.Text
Imports System.Net
Imports System.Text.RegularExpressions

Module Module1

Private IEs As New SHDocVw.ShellWindows
Private IE As SHDocVw.InternetExplorer
Private Declare Function GetForegroundWindow Lib "user32" () As
Int32

Sub Main()
Dim objWebClient As New WebClient
Dim objUTF8 As New UTF8Encoding

Dim Ret As Int32

For Each IE In IEs
'Here we will compare the ACTIVE IE.HWND
'Title is in this format
'<span class="header6">
'Tom Hawke (Orig. Title: the Link Boys)
'</span>

'Author is in this format
'
Ret = GetForegroundWindow()
If Ret = IE.HWND Then

Dim html As String =
objUTF8.GetString(objWebClient.DownloadData(IE.Loc ationURL))
'Multiple Regex here ?
Dim regex As New Regex("<span
class=""header6"">((.|\n)*?)</span>", RegexOptions.IgnoreCase)
Dim re As New Regex("<[^>]*>", RegexOptions.IgnoreCase)
Dim regex2 As New Regex("<b>Binding:</b>((.|\n)*?)<br>
<b>Publisher:", RegexOptions.IgnoreCase)

'Dim regex As New Regex("<b>Binding:</b>((.|\n)*?)<br>
<b>Publisher:", RegexOptions.IgnoreCase)
'MsgBox(IE.LocationURL)
' Dim Match = regex.Match(html)

Dim title, author, binding, condition As String
title = regex.Match(html).ToString
title = re.Replace(title, "")
binding = regex2.Match(html).ToString
binding = re.Replace(binding, "")
binding = Replace(binding, "Binding:", "")
binding = Replace(binding, "Publisher:", "")

MsgBox(Ret & Trim(title) & " " & binding)
End If

Next


End Sub

End Module

Any suggestions on how I could clean up the stripping of Title and
author would be appreciated.

Chris

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8

P: n/a
Hi Chris,

They made a document object model to make it able to extract a complete
webpage.
So why do you not use that?

Doing this with the regex is getting the horse after the cart.

Cor
Nov 20 '05 #9

P: n/a

Well I a wee bit confused about that, I read about it in another thread
as suggested and looked on the web but Im still at a loss.

I need to extract about 7 name value pairs , but how would the DOM know
what belongs to what as they are all on the same line and I do not
control the code on the other end.

Any help with an explanation of how the DOM works with something like
this would be appreciated.

Chris


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.