AutoHotkey Community

It is currently May 25th, 2012, 8:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 119 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 8  Next
Author Message
 Post subject:
PostPosted: October 10th, 2007, 12:09 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2007, 3:09 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2007, 4:46 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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 October 22nd, 2007, 8:19 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2007, 9:16 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2007, 9:38 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
@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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2007, 10:15 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Win_onscroll()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2007, 2:26 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
@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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2007, 4:57 pm 
Ya why not put it into a command in AHK software.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2007, 3:50 pm 
Offline

Joined: October 22nd, 2007, 3:44 pm
Posts: 11
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 ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2007, 1:06 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2007, 7:38 am 
Offline

Joined: October 22nd, 2007, 3:44 pm
Posts: 11
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 ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2007, 12:47 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2007, 4:06 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2007, 5:16 pm 
Offline

Joined: October 22nd, 2007, 3:44 pm
Posts: 11
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 24th, 2007, 1:15 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 119 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 8  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Relayer and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group