Internet Explorer 7 - DispHelper

General FreeBASIC programming questions.
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Internet Explorer 7 - DispHelper

Post by TDT »

I have a code to enumerate windows in Internet Explorer 6. But in IE7 this code enumerate only the first tab (not the active). Anyone could help me to list the windows and each tab of it?

The code to IE6

Code: Select all

#include once "windows.bi"
#define UNICODE
#include once "disphelper/disphelper.bi"

dim as hWND HWIN
dim as zstring ptr URL,NOME,VALOR
dim as integer ESPERAR=1,OCUPADO,ATTEMPTS

do
  HWIN = FindWindow("IEFrame" & chr(0),NULL)
  if HWIN then
    dhInitialize(TRUE)
    dhToggleExceptions(TRUE)
    DISPATCH_OBJ(pShell)
    dhCreateObject("Shell.Application", NULL, @pShell)
    FOR_EACH0(ieApp2, pShell, ".Windows")
    do
      if ESPERAR = 1 then
        do
          dhGetValue("%b", @OCUPADO, ieApp2, ".Busy")
          sleep 100
        loop while OCUPADO
      end if
      dhGetValue("%s", @URL, ieApp2, ".LocationURL")
      dhGetValue("%s", @NOME, ieApp2, ".LocationName")
      if len(*URL) > 0 and len(*NOME) > 0 then
        print "URL.....: ";*URL
        print "Titulo..: ";*NOME
      end if      
      ATTEMPTS += 1
      sleep 100
    loop while( ATTEMPTS < 1000 \ 25 )
    dhFreeString(NOME)
    dhFreeString(URL)
    NEXT_(ieApp2)
    SAFE_RELEASE(pShell)
    dhUninitialize(TRUE)
  end if
  sleep 100
loop

end
Note: Why an admin delete my first topic?
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Post by TDT »

Well.. trying and trying more, I obtain a solution!

In IE6 is necessary to use the code below because IE6 has a delay to set the LocationURL and LocationName for a window.

Code: Select all

do
  ...
loop while ( ATTEMPTS < 1000 \ 25 )
Fortunately, in IE7 this code works good. It was enumerate all tabs of each window, but it only was slowly!

The code was print the first tab many times [while (ATTEMPS < 1000 \ 25)] and I was close the window until the program finish.

Now, in version 7, Internet Explorer doesn't have this delay. Then I resolve my problem only removing the lines that I made reference above.

Now, the works code (with some modifications) is:

Code: Select all

#include once "windows.bi"
#define UNICODE
#include once "disphelper/disphelper.bi"

Dim As hWND HWIN
Dim As Zstring Ptr URL,NOME
Dim As Integer OCUPADO

HWIN = FindWindow("IEFrame" & Chr(0),NULL)
If HWIN Then
  dhInitialize(TRUE)
  dhToggleExceptions(FALSE)
  DISPATCH_OBJ(pShell)
  dhCreateObject("Shell.Application", NULL, @pShell)
  FOR_EACH0(ieApp2, pShell, ".Windows")
  Do
    dhGetValue("%b", @OCUPADO, ieApp2, ".Busy")
    Sleep 100
  Loop While OCUPADO
  dhGetValue("%s", @URL, ieApp2, ".LocationURL")
  dhGetValue("%s", @NOME, ieApp2, ".LocationName")
  If Len(*URL) > 0 And Len(*NOME) > 0 Then
    Print "URL.....: ";*URL
    Print "Titulo..: ";*NOME
  End If     
  dhFreeString(NOME)
  dhFreeString(URL)
  sleep 100
  NEXT_(ieApp2)
  SAFE_RELEASE(pShell)
  dhUninitialize(TRUE)
End If
Sleep

End
Thankz for all that opened this topic to try to help me!
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Ressurecting old posts......

Post by bcohio2001 »

In reference to the code above:

Is there something that will get the source/html of the displayed page?
I do not wish to call the server for the data, as it is an ASP page. All I want is what is in the browser window.

Code: Select all

Dim As Zstring Ptr URL,NOME,HTML
<snip>
  dhGetValue("%s", @URL, ieApp2, ".LocationURL")
  dhGetValue("%s", @NOME, ieApp2, ".LocationName")
  ' something like this????
  dhGetValue("%s", @HTML, ieApp2, ".LocationHtml")
  'or ".getHtml" ... ".getSource"

Any ideas on how to adapt for other browsers?

Code: Select all

HWIN = FindWindow("IEFrame" & Chr(0),NULL)
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Re: Ressurecting old posts......

Post by Zippy »

bcohio2001 wrote: <snip>
In reference to the code above:

Is there something that will get the source/html of the displayed page?
I do not wish to call the server for the data, as it is an ASP page. All I want is what is in the browser window.
<snip>
InRe disphelper the property is:

.Document.Body.Innertext

which I didn't know until minutes past. I'll offer a bit of code that'll navigate to a url and grab the htlml, a task that's simpler with disphelper but acheivable with other methods. But beyond this I can't help you - I thinkyou are wanting to auto-login or similar, I don't know what the document properties might be. Best wishes.

Try:

Code: Select all

'get IE document body 
'  console app
#include once "windows.bi"
#define UNICODE 'necessary, and this should follow windows.bi
#include once "disphelper/disphelper.bi"
'
'dim as HWND hwndie
dim as HRESULT hres
dim as integer c,bBusy
dim as string ts,zs
dim urltext as string
'
DISPATCH_OBJ(ieApp)
dhInitialize(TRUE)
'
dhCreateObject("InternetExplorer.Application",NULL,@ieApp)
dhPutValue(ieApp,".Visible = %b",TRUE)
'dhGetValue("%p",@hwndIe,ieApp,".HWND")
'
urltext="http://freebasic.net/" & chr(13)
dhCallMethod(ieApp,"Navigate(%s)",urltext)
'
bBusy = -1
while bBusy
    dhGetValue("%b",@bBusy,ieApp,".Busy")
    sleep 500
wend
'
ts = space(4098*10)
hres=dhGetValue("%s",@ts,ieApp,".Document.Body.Innertext")
'
c=0:zs=""
'
while ts[c]<>0
    zs+=chr(ts[c])
    c+=1
wend
'
print "Text: ==> ";
print zs;
print " <=="
'
beep
'
''if you need error checking..
'
'dim szMessage As wstring * 512
'szMessage=wspace(512)
'dhFormatException(NULL,cast(LPWSTR,@szMessage),sizeof(szMessage)/sizeof(szMessage[0]),TRUE)
'print
'print trim(szMessage)
'
print:print "Sleeping to Exit.."
SAFE_RELEASE(ieApp)
dhUninitialize(TRUE)
'
sleep
end
If the code looks shakey it is..

Your task is to finger the rest of it and post your results back.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Post by bcohio2001 »

.Document.Body.Innertext was what I needed! Many thanks.

I plugged that line in my prg and worked exactly as I thought it would. Got all the text off the page, no html or graphics.

Another note:
Yes I am looking for a auto (login/nav) function. I used your "shakey" example and it opened a blank IE and then another one that did the navigation. It tried to read the text of the blank window.
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

The "shakey" part is getting the document text, that's new to me and my code reflects a workaround (zstrings didn't work). The navigation is almost verbatim from the disphelper example (from sourceforge). I'm guessing that your experience reflects your settings in IE 7/8 (what version?). It opens a new instance of IE every time for me, one instance one tab.

If you can figure out the object names of the login/password edit boxes, then the name of the "submit" button (or whatever) then it's probably possible to automate login (I'm sure it is, there are utilities on the net to do just this). A VisualBasic example, if found, would point the way.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Post by bcohio2001 »

[Second attempt at post, explain later.....]

I am using IE7. But I think the main problem is probably.....drumroll.... Vista.

I downloaded and tried Loe's AxSupport, but was having problems with it.
Seems that Vista no longer supports tblinf32.dll
[Added: It is not included in Vista! And informed Loe.]

Refer to last few posts....
http://www.freebasic.net/forum/viewtopi ... 0&start=15

Just for fun I tried:

Code: Select all

'get IE document body 
'  console app
#include once "windows.bi"
#define UNICODE 'necessary, and this should follow windows.bi
#include once "disphelper/disphelper.bi"
'
'dim as HWND hwndie
Dim As HRESULT hres
Dim As Integer c,bBusy
Dim As String ts,zs
Dim urltext As String
'
DISPATCH_OBJ(ieApp)
dhInitialize(TRUE)
'
dhCreateObject("InternetExplorer.Application",NULL,@ieApp)
dhPutValue(ieApp,".Visible = %b",TRUE)
Sleep 1000
'
'urltext="http://freebasic.net/" & Chr(13)
dhCallMethod(ieApp,"Navigate(%s)","http://freebasic.net/")
Sleep 1000
dhCallMethod(ieApp,"Navigate(%s)","http://www.yahoo.com/")
Sleep 1000
dhCallMethod(ieApp,"Navigate(%s)","http://www.microsoft.com/")
Sleep 1000
dhCallMethod(ieApp,"Navigate(%s)","http://www.google.com/")
Sleep 1000
dhCallMethod(ieApp,"Navigate(%s)","http://www.irs.gov/")
Sleep 1000
'
bBusy = -1
While bBusy
    dhGetValue("%b",@bBusy,ieApp,".Busy")
    Sleep 500
Wend
'
ts = Space(4098*10)
hres=dhGetValue("%s",@ts,ieApp,".Document.Body.Innertext")
'
c=0:zs=""
'
While ts[c]<>0
    zs+=Chr(ts[c])
    c+=1
Wend
'
Print "Text: ==> ";
Print zs;
Print " <=="
'
Beep
'
''if you need error checking..
'
'dim szMessage As wstring * 512
'szMessage=wspace(512)
'dhFormatException(NULL,cast(LPWSTR,@szMessage),sizeof(szMessage)/sizeof(szMessage[0]),TRUE)
'print
'print trim(szMessage)
'
Print:print "Sleeping to Exit.."
SAFE_RELEASE(ieApp)
dhUninitialize(TRUE)
'
Sleep
End
Results:
Opened new blank window with nothing in address bar.
Navigated to each page in new tabs in a window that I was using to do the first attempt at this post.
Printed in the console window a bunch of blank lines, got the innertext from the blank window.
I exited the program, then [DUH] closed ALL IE windows.
Last edited by bcohio2001 on Jan 31, 2009 11:47, edited 3 times in total.
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

Problem #1 in your test:

'urltext="http://freebasic.net/" & Chr(13)

note the carriage return appended to the url. Without that cr IE won't navigate anywhere. So, either populate a string separately like above and pass the string or do this:

dhCallMethod(ieApp,"Navigate(%s)","http://www.irs.gov/" & chr(13))

You will get NOWHERE without the appended carriage return. Stop. Do not pass GO. Do not collect $200.

Prob #2 is that your sleep 1000 between navigate calls is.. insufficient. Note the hBusy while wend loop, it's needed between each navigate. Even with a 50mbps connection IE needs time to initialize, the servers you are hitting need time to respond.

I thought I'd mess with this, see if I could test plugging in values on a web page. I thought (!) the basic Google search page would be a place to start - there must be a THOUSAND lines of source code behind that page. Ack.

Noted, lack of tblinf32.dll support in Vista. Is it "unsupported" or simply not there? Maybe Loe has a work-around.
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

@bcohio2001

I need a prize for this one - or learn some javascript/js scripting so this isn't so difficult for me next time.. I fingered it out, I'm able to programatically (using disphelper) navigate to freebasic.net and login.

I'd rather post code that's specific to the site you are trying to hit, minus the real login/password of course. Provide a url, I'll post code if I can figure out another website - css and embedded forms will be more difficult.

And again, I'm pretty certain that your double-window experience relates to your IE settings. Check your internet settings, on the first tab there's a "Tabs" windows "Settings" button, click, then on next tab there's
something to the effect of "opening links for other programs in:", set this to "the current tab or window".
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Post by bcohio2001 »

Javascript??? You want javascript.... here you go! This is off my personal/family web page that I wrote. It is not currently on the web now, but it was at one time.

Code: Select all

<script type="text/javascript">
function NextBit() {
	if (WhichNext == 1) {
		if (FormData.FUserName.value != "" && FormData.FUserMail.value != "") // both have data?
			FormData.ContB.disabled = false;
	}
	if (WhichNext == 2) {
		if (FormData.Who.selectedIndex > 0){
			FormData.ContB.disabled = false;
			document.getElementById("SelPer").innerHTML = FullName(FormData.Who.options[FormData.Who.selectedIndex].value);
		}
	}
	if (WhichNext == 3) {
		if (FormData.Sex[1].checked == true || FormData.Sex[0].checked == true){
			FormData.FirstName.disabled = false;
			FormData.MiddleName.disabled = false;
			FormData.LastName.disabled = false;
			FormData.BirthMonth.disabled = false;
			FormData.BirthDate.disabled = false;
			FormData.BirthYear.disabled = false;
			if (FormData.Sex[0].checked == true)
				FormData.Suffix.disabled = false;
			else
				FormData.Suffix.disabled = true;
			// now is required info in?
			if (FormData.FirstName.value != "" && FormData.LastName.value != "") // both have data?
				FormData.ContB.disabled = false;
		}
		else {
			FormData.FirstName.disabled = true;
			FormData.MiddleName.disabled = true;
			FormData.LastName.disabled = true;
			FormData.BirthMonth.disabled = true;
			FormData.BirthDate.disabled = true;
			FormData.BirthYear.disabled = true;
		}
	}
	if (WhichNext == 4) {
		document.getElementById("PerInp").innerHTML = FormData.FirstName.value
		if (FormData.Alive[1].checked == true || FormData.Alive[0].checked == true){
			if (FormData.Alive[0].checked == true) { // Alive
				document.getElementById("IsDead").style.display = "none"
				document.getElementById("IsAlive").style.display = "inline"
			}
			else {
				document.getElementById("IsAlive").style.display = "none";
				document.getElementById("IsDead").style.display = "inline";
			}
			FormData.ContB.disabled = false;
		}
	}
	if (WhichNext == 5) FormData.ContB.disabled = false; // may not know date of death!
	if (WhichNext == 6) {
		if (FormData.How.selectedIndex > 0)
			FormData.ContB.disabled = false;
	}
	if (WhichNext == 7) {
		document.getElementById("divButton").style.display = "none";
		if (FormData.AddMore[1].checked == true || FormData.AddMore[0].checked == true)
			FormData.SubmitB.disabled = false;
		else
			FormData.SubmitB.disabled = true;
	}
}

function SaveAdd(FormData) {
 	var Num = 900, Count = 1;
	if (CookieValue("NewPCount") != null){
		Count = parseInt(CookieValue("NewPCount"),10)+1;
		Num = Count+899;
	}
	var PerNameStr = FormData.FirstName.value + " ";
	if (FormData.MiddleName.length != 0) PerNameStr += FormData.MiddleName.value + " ";
	PerNameStr += FormData.LastName.value;
	if (FormData.Sex[0].checked && FormData.Suffix.value != "") PerNameStr += ", " + FormData.Suffix.value;
	SetCookie("AddP"+Num,PerNameStr,14,"days"); 
	SetCookie("NewPCount",Count,14,"days");

	PerNameStr = ((FormData.AddMore[0].checked) ? "Done" : "More");
	SetCookie("AddPNext",PerNameStr,10,"minutes");
	if (PerNameStr == "More") {
		SetCookie("FUserName",FormData.FUserName.value,10,"minutes");
		SetCookie("FUserMail",FormData.FUserMail.value,10,"minutes");
	}
 }
 
function CanCont() { // button click
	document.getElementById("div"+WhichNext).style.display = "none"
	WhichNext++;
	document.getElementById("div"+WhichNext).style.display = "inline"
	FormData.ContB.disabled = true; // disable button
	setInterval("NextBit()",500);
}
var WhichNext = 1;
</script>
But note that I wish to call asp pages, which use VBScript to retrive data. At one time, MANY years ago, my pages were in asp being hosted at my ISP.

Here is my program plan:
1. Init [of course]
2. open normal window
3. if user/me selects update stats
3a. open IE - invisible
3b. auto log in
3c. loop through array of asp pages to hit
3d. get/save data off each [Leaving IE invisible]
4. update main window
5. if wish to make changes, make IE visible.
6. while making changes, get the changes and update data
7. when end prg, close IE if already haven't

I have edited my previous post to note that the dll is not included in Vista.

IMO, I think that this is still my main problem. At least from what I have witnessed on my screen. The dhCreateObject opens a completly blank window! Then the Navigate command, using the "& Chr(13)" opens a new browser window, and any more navigates opens new tabs, probably would open more windows if I didn't have tabbed browsing.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Post by bcohio2001 »

Just had to make new post for this!

I have figrued out my double window problem. Just now have to figure out how to fix it.

Was just tinkering with it and ran it.
Opened the 2 windows. The blank and the one that it displayed the page.
I closed the one with the multiple tabs. and started really looking at the blank window.

In the drop down address bar, had some sites listed, so I selected one and got a message box. [I saved it, and wish I could post it.]

*****************************************************
Internet Explorer needs to open a new window to display this webpage.

For your computer's security, websites that are in different security zones must open in different windows.
******************************************************

I wonder if all I have to do is put the site in my "trusted" security zone. or is there a setting I could use from disphelper.

Something like....
dhPutValue(ieApp,".Security = %b",FALSE)
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

bcohio2001 wrote:Just had to make new post for this!

I have figrued out my double window problem. Just now have to figure out how to fix it.

Was just tinkering with it and ran it.
Opened the 2 windows. The blank and the one that it displayed the page.
I closed the one with the multiple tabs. and started really looking at the blank window.

In the drop down address bar, had some sites listed, so I selected one and got a message box. [I saved it, and wish I could post it.]

*****************************************************
Internet Explorer needs to open a new window to display this webpage.

For your computer's security, websites that are in different security zones must open in different windows.
******************************************************

I wonder if all I have to do is put the site in my "trusted" security zone. or is there a setting I could use from disphelper.

Something like....
dhPutValue(ieApp,".Security = %b",FALSE)
Looks like you were correct when you surmised that this is a Vista prob. Rather, an IE 7/8 problem (setting) that only manifests in Vista.

http://www.technologyquestions.com/tech ... bpage.html

The good news is that you can fixit.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Post by bcohio2001 »

I put the site in my "Trusted" zone and it worked! I haven't had the chance to follow that link that you posted, but will after this.

Was able to open ONE window to the site. Looked at iexplore.cpp and found a way to fill in form data. ATM can't get it to submit correctly. For some reason it doesn't work right.

Code: Select all

dhCallMethod(ieApp,"Navigate(%s)","http://www.freebasic.net/forum/")
bBusy = -1
While bBusy
	dhGetValue("%b",@bBusy,ieApp,".Busy")
	Sleep 500
Wend
''
'log in
' fill text boxes

dhPutValue(ieApp, ".document.all(%s).value = %s", "username", "bcohio2001")
dhPutValue(ieApp, ".document.all(%s).value = %s", "password", "xxxx")
Sleep 5000
bBusy = -1
While bBusy
	dhGetValue("%b",@bBusy,ieApp,".Busy")
	Sleep 500
Wend
'submit
Print "Pressing submit"
dhCallMethod(ieApp, ".document.forms(%d).submit", 0)
When I comment out the submit call, I can go to the page and press the button myself and it logs me in.
But when I let the program do it, I get the main log in screen.
On both sites! [Freebasic and the site trying to hit]
Zippy
Posts: 1295
Joined: Feb 10, 2006 18:05

Post by Zippy »

You have to use a slightly different method to submit the fb login form. I said I'd rather not post the fb auto-login code here. I'll post what works with Google:

Code: Select all

'disphelper navigate Google Search 
'  console app
#include once "windows.bi"
#define UNICODE 'necessary, and this should follow windows.bi
#include once "disphelper/disphelper.bi"
'
dim as integer bBusy
dim urltext as string
'
DISPATCH_OBJ(ieApp)
dhInitialize(TRUE)
'
dhCreateObject("InternetExplorer.Application",NULL,@ieApp)
'if ieApp<=0 '???
dhPutValue(ieApp,".Visible = %b",TRUE)
'
urltext="http://www.google.com/ig?hl=en" & chr(13)
dhCallMethod(ieApp,"Navigate(%s)",urltext)
'
bBusy = -1
while bBusy
    dhGetValue("%b",@bBusy,ieApp,".Busy")
    sleep 500
wend
'
sleep 1000
'
'the search query input, where the input box is named "q"
dhPutValue(ieApp,".Document.All.namedItem(%s).value = %s","q","ie DOM") 
'
'
'any of the following three methods will submit the search form:
'
'this relies on our form being the first drawn on page
dhCallMethod(ieApp,".Document.forms(%d).submit()",0)
'
'or this is preferred, me thinks, if the form is NAMED
'  where the name of the form is "f"
'dhCallMethod(ieApp,".Document.forms(%s).submit()","f")
'
'or click the submit() button, here named "btnG"
'dhCallMethod(ieApp,".Document.All.namedItem(%s).click()","btnG")
'
beep
'
''if you need error checking..
'
dim szMessage As wstring * 512
szMessage=wspace(512)
dhFormatException(NULL,cast(LPWSTR,@szMessage),sizeof(szMessage)/sizeof(szMessage[0]),TRUE)
print
print trim(szMessage)
'
SAFE_RELEASE(ieApp)
dhUninitialize(TRUE)
'
print:print "Sleeping 10 seconds to Exit.."
sleep 10000
end
There are a couple of things that may throw you with other urls. One of which is the fact that a form can have multiple submit buttons - probably the first drawn gets the submit action but I don't know. And I think that there can be same-named elements in different forms, that's trippy.

Too bad we can't see your target url..
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Post by bcohio2001 »

I will try these submits and report back later.....

The reason I will not divulge the site.... rule that states...one account per computer.

Basicly if you try to log in from different computers, my account might be deleted! Or even if I let someone else log into there account from my computer BOTH accounts may be deleted.

PS. Loe emailed me a copy of tblinf32.dll. Not sure if it will work. Almost scared to register it.

It's later...... the third one worked for the site.
Post Reply