PC Review


Reply
Thread Tools Rate Thread

Caturing ACTIVE IE Url

 
 
Chris Wertman
Guest
Posts: n/a
 
      10th Apr 2004
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
 
Reply With Quote
 
 
 
 
Abubakar
Guest
Posts: n/a
 
      10th Apr 2004
> 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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




 
Reply With Quote
 
Chris Wertman
Guest
Posts: n/a
 
      13th Apr 2004
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" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

 
Reply With Quote
 
Chris Wertman
Guest
Posts: n/a
 
      13th Apr 2004
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.....

(E-Mail Removed) (Chris Wertman) wrote in message news:<(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Apr 2004
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










 
Reply With Quote
 
Chris Wertman
Guest
Posts: n/a
 
      13th Apr 2004
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.LocationURL))
'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!
 
Reply With Quote
 
Chris Wertman
Guest
Posts: n/a
 
      13th Apr 2004
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.LocationURL))
'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!
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Apr 2004
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


 
Reply With Quote
 
Chris Wertman
Guest
Posts: n/a
 
      13th Apr 2004

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!
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make active cell border prominent and keep entire active row selected for better visibility Radhika Microsoft Excel Programming 2 30th Dec 2008 08:51 AM
Active/Active Clusters print server browse issues chadsmith3@hotmail.com Microsoft Windows 2000 Networking 0 13th Sep 2006 07:31 PM
Can a a 2 node cluster support both active/active and active/passive configurations John H Microsoft Windows 2000 Advanced Server 0 19th Sep 2005 02:16 PM
Disk exchange on two-node MS SQL 2000 active/active cluster Roust_m Microsoft Windows 2000 Advanced Server 0 21st May 2004 03:02 PM
setting up a domain controller in active/active cluster environment =?Utf-8?B?S2FpemFk?= Microsoft Windows 2000 Advanced Server 1 30th Dec 2003 04:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:17 PM.