AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Determine if a WebPage is completely loaded in IE
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Wed Oct 10, 2007 12:09 am    Post subject: Reply with quote

Joy2DWorld wrote:
maybe to keep *all* functions tied to the library. ie. HEX() to acc_hex() ...

OK, I updated ACC.ahk.

Quote:
How to turn the document object handle into handle that can be bound COM_events ?

I'm not sure what you mean, it's already connectible. Would you be more specific?
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Wed Oct 10, 2007 3:09 am    Post subject: Reply with quote

Sean wrote:
Would you be more specific?


@Sean, you've moved with such huge advances the reaches of what AHK is able to do... that sometimes my mind goes fuzzy figuring out all that ground!!

more specifically: How do get the same result that COM_ConnectObject(pie , "Web_") gives us eg. Web_BeforeNavigate2(prms), but with a DOM object event (doc, window, or whatever). For sake of example: onbeforecopy .


ie. something like getref()
http://msdn2.microsoft.com/en-us/library/ekabbe10.aspx
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Wed Oct 10, 2007 4:46 am    Post subject: Reply with quote

Joy2DWorld wrote:
more specifically: How do get the same result that COM_ConnectObject(pie , "Web_") gives us eg. Web_BeforeNavigate2(prms), but with a DOM object event (doc, window, or whatever).

I don't know if DOM provides means to cancel the navigation, I'm a bit skeptical about it. You have to read the documentation in MSDN for it.

BTW, you can use the event of WebBrowser control for it, if you find none.

Code:
#Persistent
MouseGetPos,,,, hIESvr, 2
OnExit,   AccClose

ACC_Init()
IID_IHTMLWindow2   := "{332C4427-26CB-11D0-B483-00C04FD90119}"
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
pacc := ACC_AccessibleObjectFromWindow(hIESvr)
pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)
pweb := COM_QueryService(pwin,IID_IWebBrowserApp,IID_IWebBrowserApp)
psink:= COM_ConnectObject(pweb, "Web_")
Return

AccClose:
COM_Release(psink)
COM_Release(pweb)
COM_Release(pwin)
COM_Release(pacc)
ACC_Term()
ExitApp

Web_BeforeNavigate2(prms, this)
{
   If   COM_DispGetParam(prms, 1) = "http://www.autohotkey.com/"
      NumPut(-1, NumGet(NumGet(prms+0)+8), 0, "short")   ; cancel the navigation
}


Last edited by Sean on Mon Oct 22, 2007 8:19 am; edited 1 time in total
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Wed Oct 10, 2007 9:16 am    Post subject: Reply with quote

Joy2DWorld wrote:
more specifically: How do get the same result that COM_ConnectObject(pie , "Web_") gives us ... but with a DOM object event (doc, window, or whatever). For sake of example: onbeforecopy .

Sean wrote:
I'm not sure what you mean, it's already connectible.
I have used
Code:
COM_ConnectObject(el, "Win_")
where el is a pointer to an element object / HTML/DOM element.
Joy2DWorld wrote:
ie. something like getref()
In context:
Code:
Set object.eventname = GetRef(procname)
My understanding of this is:
  • GetRef(procname) builds an object (implementing IDispatch) wrapping procname().
  • The IDispatch object is assigned to the 'eventname' property.
  • When the event occurs, the default method of the IDispatch object is called, which in turn calls procname().
To do this in AutoHotkey, we need to build our own object implementing IDispatch. Fortunately, ConnectObject() already does this, so we can adapt ConnectObject, CreateIDispatch and DispInterface.

I've just posted an example in the COM Event Handler thread (seems more appropriate.)
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Wed Oct 10, 2007 9:38 pm    Post subject: Reply with quote

@Sean,

Flawless.


@lexikos,

lexikos wrote:
I have used
Code:
COM_ConnectObject(el, "Win_")
where el is a pointer to an element object / HTML/DOM element.


could you give an example of callback function (ie. function name) that's work with... [am streching my brain to try to keep pace with you'all!!!]
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Wed Oct 10, 2007 10:15 pm    Post subject: Reply with quote

Win_onscroll()
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Thu Oct 11, 2007 2:26 pm    Post subject: Reply with quote

@lexikos,

wow. ok, am starting to catch on... thanks!!


and, more and more realizing the incredible power/simplicity in use of what Sean has done with the Invoke()... incredible.
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Guest1213
Guest





PostPosted: Thu Oct 11, 2007 4:57 pm    Post subject: Reply with quote

Ya why not put it into a command in AHK software.
Back to top
hotzenpl0tz



Joined: 22 Oct 2007
Posts: 11

PostPosted: Mon Oct 22, 2007 3:50 pm    Post subject: Reply with quote

Could someone give me a pointer, what I would have to look at, to make this work for the active internet explorer window ?

I have the following problem, that I have to deal with pretty often:

a) I have to open up a webpage, wait for it to load, then navigate to the login part of the webpage, and login.

b) Now I have to navigate to a certain link, that opens another internet explorer window. Now again, I have to wait until it is loaded until I can continue with my automation tasks.

For "a)" I can deal with, with the proposed solutions in here. Now I need something to work with "b)" - what would be great, would be a way to determine if the webbrowser has started to load the webpage, then wait until it is loaded (with the same methods posted here I suppose) and then continue.
The problem is, that I can't just fire of the script to wait for load, after the new internet explorer window has opened, because I have to wait for it to start loading the webpage first, otherwise the script won't work. Is there a way to do that, maybe with that COM stuff ?
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Tue Oct 23, 2007 1:06 am    Post subject: Reply with quote

hotzenpl0tz wrote:
The problem is, that I can't just fire of the script to wait for load, after the new internet explorer window has opened, because I have to wait for it to start loading the webpage first, otherwise the script won't work. Is there a way to do that, maybe with that COM stuff ?

You may read it:
http://www.autohotkey.com/forum/topic19256-15.html
Back to top
View user's profile Send private message
hotzenpl0tz



Joined: 22 Oct 2007
Posts: 11

PostPosted: Tue Oct 23, 2007 7:38 am    Post subject: Reply with quote

Hm thanks, but I have to admit that I couldn't find the part relevant to my problem. I saw the following code you suggested:

Code:

#Include CoHelper.ahk
F12::
CoInitialize()
pie := ActiveXObject("InternetExplorer.Application")
Invoke(pie, "Visible=", "True")
Invoke(pie, "Navigate", "http://maps.google.ca/maps?ie=UTF-8&oe=UTF-8&hl=en&tab=wl&q=")
Loop
{
   If   Invoke(pie, "ReadyState") = 4
      Break
   Sleep,   500
}
Release(pie)
CoUninitialize()
Run,   calc.exe
Return


Now this works great, to open up a new page and navigate to it, but I don't know how to modify it, so it works with an explorer instance that gets opened by clicking on a link on a webpage by javascript or such. Now if that is answered in one of your later posts (I read through them all, but it's very possible that I didn't get it, I am not that fluent with COM, DOM etc.), I would be greatfull if you could point me to the correct post. If not, maybe you could post a small example code snippet, if there is a way to write a "loop" statement, that wats for the "Internet Explorer_Server control" to be available, and then continues on with the Waitforload Script. Thanks alot in advance, and sorry for wasting your time Wink
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Tue Oct 23, 2007 12:47 pm    Post subject: Reply with quote

hotzenpl0tz wrote:
I don't know how to modify it, so it works with an explorer instance that gets opened by clicking on a link on a webpage by javascript or such.
Sean demonstrated further up this page (page 3) how to get the WebBrowser object (pweb) of a running instance of Internet Explorer. WebBrowser and InternetExplorer have most (if not all) of the same properties and methods.

To get a different (from the example) instance of IE, change
Code:
MouseGetPos,,,, hIESvr, 2
to
Code:
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1, ahk_class IEFrame  ; or whatever WinTitle
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1331

PostPosted: Tue Oct 23, 2007 4:06 pm    Post subject: Reply with quote

lexikos wrote:
Sean demonstrated further up this page (page 3) how to get the WebBrowser object (pweb) of a running instance of Internet Explorer.

Just in case, this technique can be used with any DOM objects, not only with Window object, as far as I tested. So, if don't like to use ACC.ahk, may do it with the code in the first post of this thread by adding:
Code:
pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)

hotzenpl0tz wrote:
so it works with an explorer instance that gets opened by clicking on a link on a webpage by javascript or such.

I'm not sure of exactly what you have in mind. If what lexicos suggested is what you wanted, you may ignore the following.
Here is one example, which will always open a new window for the page you clicked in the first/original start-up IE window, and waits for it completely loaded and then pop up message box.

Code:
#Persistent
OnExit, CleanUp

COM_CoInitialize()
pweb := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pweb, "Visible=", "True")
COM_Invoke(pweb, "Navigate", "http://www.autohotkey.com/forum/")
ReadyState(pweb)
MsgBox, Ready
COM_ConnectObject(pweb, "Web_")
Return

CleanUp:
COM_Release(pweb)
COM_CoUninitialize()
ExitApp


Web_BeforeNavigate2(prms, this)
{
   NumPut(-1, NumGet(NumGet(prms+0)+8), 0, "short")   ; cancel the navigation
   pweb := COM_CreateObject("InternetExplorer.Application")
   COM_Invoke(pweb, "Visible=", "True")
   COM_Invoke(pweb, "Navigate", COM_DispGetParam(prms, 1))
   ReadyState(pweb)
   COM_Release(pweb)
   MsgBox, Ready
}

ReadyState(pweb)
{
   Loop
      If   COM_Invoke(pweb, "ReadyState") <> 4
         Sleep,   500
      Else   Break
}
Back to top
View user's profile Send private message
hotzenpl0tz



Joined: 22 Oct 2007
Posts: 11

PostPosted: Tue Oct 23, 2007 5:16 pm    Post subject: Reply with quote

Thanks you two, your comments brought me a few steps forward, although I will need some time to get a hang of the COM stuff. Until now, I tried to automate some tasks I had to do with a webbrowser by using the old "done in statusbar" method, but that was just plain unreliable.

For what it's worth, the following describes what I am attempting to do - because I think it is probable that somebody will have to do something similar someday, and I will post the most important parts of my solution, should I get it working reliably:

At work, we have a big database of Computers, Users, Telephone numbers, Login Information etc. This database used to be an MS Access Database localy in our department, that we could access with VBScript or something similar to get the needed information and automate some repetitive tasks (insert data into an excel sheet for example). The system was now changed - the database is now only accessible with a webinterface and I have to do some insane HTML Sourcecode parsing to get the desired information. Now the problem isn't the parsing but the way I have to go to get it: I need to open an internet explorer instance, login to the webpage, then navigate to the search button, press that button - now a second internet explorer instance opens with the search field, I then input the pc login name I am looking for. When that search finishes, the internet explorer instance in the background (the first instance) changes to the search result, and from there on I have to go on, get the source and do my parsing. As you may guess, this involves ALOT of timing issues - and those appear in 2 different internet explorer instances, so this is getting pretty confusing.

Nevertheless, I think some of the points you gave me can help me here - I think looking for the events with COM_Connectobject should help me out here. Thanks for the help you have given me, it is greatly appreciated Smile
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2542
Location: Australia, Qld

PostPosted: Wed Oct 24, 2007 1:15 am    Post subject: Reply with quote

Sean wrote:
Code:
pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
Shouldn't that be IHTMLDocument or IHTMLDocument2? Actually, I find it easier to do:
Code:
pdoc := COM_Invoke(pweb,"Document")
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 3 of 6

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group