IonicWind Software

IWBasic => General Questions => Topic started by: Andy on June 01, 2010, 08:10:09 AM

Title: Detect an open web site address ?
Post by: Andy on June 01, 2010, 08:10:09 AM

Maybe it's a silly question, but I was looking at the IPaddress example program and wondered if you can detect the IP address can you detect the web page address that IE may have open at a given time ?

Example:

IE has www.google.com open

Are there any commands or code that I could run that would give me "www.google.com" ?

Just an open question, but any ideas would be appreciated.

Thanks,
Andy.
Title: Re: Detect an open web site address ?
Post by: sapero on June 01, 2010, 10:26:45 AM
Hi Andy,
This is a nice and small example, uses IShellWindows and IWebBrowser2 interfaces:
'$include "mshtml.inc" ' optional, DOM access
$include "exdisp.inc"

CoInitialize(0)
IShellWindows shwnd

if (!CoCreateInstance(_CLSID_ShellWindows, NULL, CLSCTX_INPROC_SERVER, _IID_IShellWindows, &shwnd))
int count
VARIANT vItem
' get the number of shell windows
shwnd->get_Count(&count)
char s = IIF(count>1, 115, 32)
print "found ", count, "shell window", s

vItem.vt = VT_I4
' iterate the list
for vItem.lVal=0 to count-1
IDispatch disp
' get the next shell window
if (!shwnd->Item(vItem, &disp))
' is this a webbrowser?
IWebBrowser2 browser
if (!disp->QueryInterface(_IID_IWebBrowser2, &browser))
' get the URL
BSTR bstrUrl
if (!browser->get_LocationURL(&bstrUrl) and bstrUrl)
print *<wstring>bstrUrl
SysFreeString(bstrUrl)
endif
browser->Release()
endif
disp->Release()
endif
next vItem.lVal

shwnd->Release()
endif
CoUninitialize()

_system("pause")


Does not work with IE running in the same session, but as another user.
Title: Re: Detect an open web site address ?
Post by: Andy on June 01, 2010, 10:26:48 PM
Hi Sapero,

Thanks very much for the example code, you are always a great help.

I get two errors though

File: C:\Program Files\EBDev\projects\IElook.eba (7) syntax error - CoCreateInstance
        if (!CoCreateInstance(_CLSID_ShellWindows, NULL, CLSCTX_INPROC_SERVER, _IID_IShellWindows, &shwnd))

File: C:\Program Files\EBDev\projects\IElook.eba (12) syntax error - =
   char s = IIF(count>1, 115, 32)

I have all the include files etc ...

Any ideas what i'm doing wrong ??

Thanks,
Andy.
Title: Re: Detect an open web site address ?
Post by: LarryMc on June 01, 2010, 10:36:28 PM
Compiles for me just the way it is posted with no errors.

I'm running 1.737 of EB/IWBasic

LarryMc
Title: Re: Detect an open web site address ?
Post by: sapero on June 02, 2010, 12:13:38 AM
Andy, "if !x" is the same as "if x=0". Try if (CoCreateInstance(...) = 0)

The second issue: I think you need to split the definition and assignment:
char s
s = ...
Title: Re: Detect an open web site address ?
Post by: LarryMc on June 02, 2010, 05:42:49 AM
Quote from: sapero on June 02, 2010, 12:13:38 AM
The second issue: I think you need to split the definition and assignment:
char s
s = ...


I don't understand why you say that.

And again, it compiles just fine for me.

LarryMc
Title: Re: Detect an open web site address ?
Post by: Andy on June 02, 2010, 06:26:23 AM
Larry and Sapero,

Thanks for trying for me, don't understand why it doesn't compile for me either.

However - I have been looking at the Appbar example, when you run this program it gets the current text (caption) from all the top level windows when you click on the 'Task' button. I was wondering if this could be amended to get an URL address of IE instead.

I came across this web site which has some ideas but at the moment it's too advanced for me:

http://delphi.about.com/od/windowsshellapi/l/aa060303a.htm

I think the idea maybe right but it's too advanced.

Thanks,
Andy.
Title: Re: Detect an open web site address ?
Post by: sapero on June 02, 2010, 08:42:26 AM
Loading URL from combo box is a bad idea, because the combo is not owned by webbrowser control. If you type an url and do not navigate, combo.text will return what you typed instead the url displayed in browser control.

Larry, this feature (type name = value) was not always implemented, I just assumed Andy is using one of the versions from 2006-2007. The ! operator was added in April 2009.
Title: Re: Detect an open web site address ?
Post by: LarryMc on June 02, 2010, 10:52:36 AM
Andy,
What vesrion of EB are you running?

LarryMc