Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

COM Event Handler


  • Please log in to reply
18 replies to this topic
Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
It's now merged into CoHelper.ahk.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
One example is DWebBrowserEvents2. And, I implemented only for NavigateComplete2, with the prefix Web_.
NEED DebugView to display the triggered event.

#Include CoHelper.ahk
#Include AtlAx.ahk
#SingleInstance force 

GoSub, GuiStart

Gui, +Resize +LastFound
Gui, Show, w800 h600 Center, WebBrowser
hWnd := WinExist()
pwb  := ActiveXObject("Shell.Explorer")

AtlAxAttachControl(pwb, hWnd)
psink := ConnectObject(pwb, "Web_")
; ConnectObject(pwb, "Web_", "DWebBrowserEvents2")

Invoke(pwb, "Navigate", "http://www.autohotkey.com/")
Sleep 5000
Invoke(pwb, "Navigate", "http://www.autohotkey.com/forum/")
Sleep 5000
Invoke(pwb, "GoBack")
Sleep 3000
Invoke(pwb, "GoForward")
Return

GuiStart:
CoInitialize()
AtlAxWinInit()
Return
GuiClose:
Gui, Destroy
Release(pwb)
AtlAxWinTerm()
CoUninitialize()
ExitApp

[color=green]Web_[/color][color=red]NavigateComplete2[/color](prms, this)
{
	OutputDebug, DONE!
}


Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
Another example. Create two web browsers and the second one will mirror the first one, i.e., if you navigate the web in the first browser, the second one also will navigate to the new address.

#SingleInstance force 

GoSub, GuiStart

Gui, +LastFound
Gui, Show, w800 h600 Center, WebBrowser
hGui := WinExist()

pwb1 := AtlAxGetControl(AtlAxCreateContainer(hGui,  10, 10, 380, 580, "Shell.Explorer"))
pwb2 := AtlAxGetControl(AtlAxCreateContainer(hGui, 410, 10, 380, 580, "Shell.Explorer"))

psink := ConnectObject(pwb1, "Web_")

Invoke(pwb1, "Navigate", "http://www.autohotkey.com/")
Sleep 5000
Invoke(pwb1, "Navigate", "http://www.autohotkey.com/forum/")
Sleep 5000
Invoke(pwb1, "GoBack")
Sleep 3000
Invoke(pwb1, "GoForward")
Return

GuiStart:
CoInitialize()
AtlAxWinInit()
Return
GuiClose:
Gui, Destroy
Release(psink)
Release(pwb1)
Release(pwb2)
AtlAxWinTerm()
CoUninitialize()
ExitApp

;Web_NavigateComplete2(prms, this)
Web_BeforeNavigate2(prms, this)
{
	Global	pwb2
   	Invoke(pwb2, "Navigate", DispGetParam(prms,1))
}

#Include CoHelper.ahk
#Include AtlAx.ahk


Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
@Sean,


incredible, mind-bending stuff....



wow.



unclear of Invoke( vs. Invoke_(

is there a post/thread that points the way ?

ps: find your COM wrapper much more AHK functional than using 'Windows Scripting for AutoHotkey'...
Joyce Jamce

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

incredible, mind-bending stuff....

Joy2DWorld, you're the only one who shows interest in it. ;)
As a matter of fact, it's incomplete in the strict sense, but looks like no need to complete it.

unclear of Invoke( vs. Invoke_(

I intentionally avoided talking about Invoke_() as it could confuse the users who have no experience with Variant and its VT_TYPE. And, I now suppose Invoke_() is needed only when some of the parameters are of VT_BYREF type, so, Invoke() would be sufficient in most cases.
The difference is that you have to specify both VT_TYPE and argument with Invoke_(), somewhat analogous with

SendMessage, uMsg, wParam, lParam, , ahk_id %hWnd%
[color=red]vs[/color]
DllCall("SendMessage", "Uint", hWnd, "Uint", uMsg, "Uint", wParam, "Uint", lParam)

There are some examples using Invoke_():
<!-- m -->http://www.autohotke... ... &start=120<!-- m -->
<!-- m -->http://www.autohotke...pic.php?t=21808<!-- m -->

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

ps: find your COM wrapper much more AHK functional than using 'Windows Scripting for AutoHotkey'...

You may utilize the ScriptControl directly from CoHelper.ahk. I took an example from the thread:
<!-- m -->http://www.autohotke...ic21674-30.html<!-- m -->

#Include CoHelper.ahk

Code=
(
  sh=new ActiveXObject("WScript.Shell");
  sh.Popup('Hello, world!', 2);
)

CoInitialize()
psc := ActiveXObject("MSScriptControl.ScriptControl")
Invoke(psc, "Language[color=red]=[/color]", "JScript")
Invoke(psc, "ExecuteStatement", Code)
Release(psc)
CoUninitialize()


daonlyfreez
  • Members
  • 995 posts
  • Last active: Jan 23 2013 08:16 AM
  • Joined: 16 Mar 2005
Wow!

This comes very close to controlling a webpage contents with JavaScript. Could you give an example where you get/set data with JavaScript from the contents of a webpage inside an IEControl?

8)
Posted Image mirror 1mirror 2mirror 3ahk4.me • PM or Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

Joy2DWorld, you're the only one who shows interest in it

Ah, you are getting pathetic :p

Well, if you care, I think you did amazing job. I can imagine what kind of things your COM functions can produce, and with events now, world of oportunities is endless.
Posted Image

BoBo¨
  • Guests
  • Last active:
  • Joined: --

Joy2DWorld, you're the only one who shows interest in it.

Not indeed! I'm always fascinated about the functionalites/modules you 'connect' to AHK (same with Laszlo/PhiLho/majkinetor/Skan/daonlyfreez/..).
Cool stuff! :D

Unfortuantely (TBH, an assumption) a high percentage of the users here will end up within a 'consumer' position when it comes to express their interest in it.
Eg. I'd have to ask for each and every bit and bite, params etc. to get something like this running.
Beside the fact that I immediately become frustrated not to be able to make it myself, I often think "don't ask for that thing, you'll be responsible to waste the time of a rocket scientist". Others might have thought something similar in the past. So, it's getting silent out there ... :wink:

Thx for listening. 8)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Nothing but the truth.

99.9% of active AHK developers poorly document their stuff, or don't document it at all.

Others tend not to create reusable code, but just to present idea, like PhiLho or have limited functionality due to the bad design of some features (like what was the case with IE control at the start, where only 1 control could be created)

On the other hand, even well documented code often doesn't get any response if not directly usable by the members in their latests scripts, which is the reason I find this community as selfish in nature (although relaxing comparing to other communities on the net) and its members generaly can not look further then 1 metter ahead.

No wonder why ppl that did the most for AHK community left one day.
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
Oops, guys, I wasn't serious. I didn't complain. I also seldom posted under the threads even if I found them great. So, I'm well aware that no reply doesn't necessarily mean the work is useless. I just felt the forum is rather calm recently, but that's only my feeling too. BTW, I found myself posting strange needless messages recently, I don't know why. Maybe I'm not in the normal condition, at least emotionally.

As regards the documentation, that's really a headache to me. That postpones the implementation of the standard library of COM/CoHelper etc. And, I already wrote the wrapper of the Accessibility, but didn't post it due to the documentation stuff, even though it's a real fun as combining with ISpeechVoice it can be a screen reader.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

This comes very close to controlling a webpage contents with JavaScript. Could you give an example where you get/set data with JavaScript from the contents of a webpage inside an IEControl?

I'm not so sure if it can be used that way. That should be done through DOM, I think. As you seem to be well versed in JavaScript, why don't you try to implement DOM? I suppose Titan is considering to implement XML DOM, OTOH.

The purpose of the above example was just to show that it's possible to use the MSScriptControl via Invoke() too, so it can be handy in some circumstances. If heavily use the VBScript/JScript, then better use WS4AHK.ahk as erictheturtle well organizes it to be easily handled.

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006

it's incomplete in the strict sense, but looks like no need to complete it.



1. Keep in mind that genius takes a while for others to appreciate. You're natural ability to grasp the complexities of MS's structures and procedures is *far* beyond my own, and I imagine, the *vast* majority of everyone else as well.

2. What you've done with the COM is so giant, may take a while for realization of what you've done!



trouple of questions:

A. just showing my COM ignorance, what is incomplete in the function ?

B. have looked and tried to figure out, how/where does the extension get added for the "Web_" callback name ?

C. On totally different subject: For functions that return an array structure, is there a standard way to deal with that, or does one need to be coded ? (if necessary to code, possible to give some direction on what is needed code wise?)
Joyce Jamce

daonlyfreez
  • Members
  • 995 posts
  • Last active: Jan 23 2013 08:16 AM
  • Joined: 16 Mar 2005

I'm not so sure if it can be used that way. That should be done through DOM, I think. As you seem to be well versed in JavaScript, why don't you try to implement DOM? I suppose Titan is considering to implement XML DOM, OTOH.


True. I thought this might be used to hook into the DOM, but it seems it "only" directly calls the script-interpreter. I might know a bit about JavaScript, but this COM-stuff is way over my head, so implementing DOM support with IEControl I myself will probably never be able to accomplish. :?
Posted Image mirror 1mirror 2mirror 3ahk4.me • PM or Posted Image

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
#Include CoHelper.ahk
CoInitialize()
psc := ActiveXObject("MSScriptControl.ScriptControl")
Invoke(psc, "Language[color=red]=[/color]", "JScript")
Invoke(psc, "ExecuteStatement", "sh=new ActiveXObject(""WScript.Shell"");`nsh.Popup('Hello, world!', 2);")
Release(psc)
CoUninitialize()
Clean!!


please forgive these questions:


Why is CoInitialize necessary ?

possible to create an object from a dll ... ? How to ?

possible to do script eval and get return value ? How to ?


(and sorry if these q's seem so ignorant.)


ps: possible to *add* standard wrapper option for "." in place of "=" ?
Joyce Jamce