COM_L Inject javascript

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

13 Oct 2013, 01:54

This should be the equivalent for AHK v1.1+ (no external code needed):

Code: Select all

IE_InjectJS(hWnd_MainWindow, JS_to_Inject, Snippets_to_Return="") {
   window := _win(hWnd_MainWindow)
   if JS_to_Inject
      window.execScript(JS_to_Inject)
   if Snippets_to_Return
      Loop, Parse, Snippets_to_Return, `,
      {
         Loop, Parse, A_LoopField, .
            result := (A_Index=1? window:result)[A_LoopField]
         Ret .= result ","
      }
   return SubStr(Ret,1,-1)
}
_win(hwnd, Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID1 := "{0002DF05-0000-0000-C000-000000000046}"	; IID_IWebBrowserApp
		, IID2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"	; IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_id %hwnd%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
			return	ComObj(9,ComObjQuery(pwb:=ComObjQuery(pdoc,IID1,IID1),IID2,IID2),1)
				,	ObjRelease(pdoc), ObjRelease(pwb)
      }
   }
}
*Tested on IE 10
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

13 Oct 2013, 02:38

jethrow, I have been working on this for over 16 hours now. Red Challanges, links to MS, Calls to non existant functions not actually built in to AHK v1.1+ the great, IEGet() also non existant BTW. I have learned many things all day and all night and almost all the next morning thanks to you. You are without a doubt the most patient genius on the forums. I will always remember this time with you. Thanks, Thanks, Thanks.

Are you going to give me a D-grade, as in go get an older ahk version (degrade), tell me to come
back in a few months, I will understand. You maybe should take your time to figure it out.
Maybe it is better to wait until you at least have the udf's you think you have. Be honest
with yourself at least, that this function is not gonna be bing bang zoom. At least I hope
you appreciate now that it will be worth it, and help the community at large. (A clone of this
function). I mean it has been years since the new ahk, and probably the most powerful
function has not been cloned (converted) yet. What gives?

So now I guess you are gonna say. Just for that I ain't goin. And don't forget that ms
link you sent me to. It says execScript is no longer supported as of IE 11. They said to
use eval. Sounds like fun huh?

I have to sleep now. How about you start a new post and just post your best shot
at cloning the exact function I posted yesterday here. That is my red challange to
you. It is like the Cash Cab TV show. RED LIGHT CHALLANGE!!!

I promise to study every single byte of your code until I understand it all.
I will even take written exams on it if you like. I will take 0 credit for it's inspiration.

Of course, it has to work though. HaHaHaHahahhhahhahahh

Bye for now.
Again and again and again...

The numbers in the copy paste pain? Let us know please. Thanks
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

13 Oct 2013, 02:54

Visioneer wrote:I mean it has been years since the new ahk, and probably the most powerful
function [IE_InjectJS] has not been cloned (converted) yet. What gives?
Care to weigh in tank?

My 2 cents:
Community UDFs are great ... particularly to mask complex code where there are no other options but to utilizing an in-depth understanding of the Windows API. A great example was the COM library for AHK Basic. Another great use for UDFs is for extremely common tasks that aren't quite important enough to implement into AHK itself. Perhaps the best example I can think of is the TF Libarary.

Now, IMO, IE_InjectJS doesn't meet either of these qualifications. Similar to the iWeb library - it's almost as easy to just learn how to do it without the UDF. Plus, & IMO the most important, then you're not dependent on the UDF. Then you don't have to go back to the author if you need a slight modification, or if there is a script-breaking upgrade to the language.

So, that being said, I will decline your challenge ;) . But, do note, I have a virtually unlimited amount of patience for any respectful individual who genuinely wants to learn what I know.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

13 Oct 2013, 13:45

hey jethrow,

Some of your best work. Just changed snippets to VarNames and bingo!

God bless you. I can not write enough Thank You's.

I will make some time to look up the components and try to phathom it.

You could probably write a book on it.

After the football game I will post a calling thing so it can be tested quickly,
and add in the 2 optional COM_invoke things. Later on I will try to show how
I can get the js code from server or local js files and use it with your function.

Allow me to COM_invoke the last 3 words of the old Honeymooners TV shows.

jethrow, your the greatest!
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

13 Oct 2013, 13:53

Visioneer wrote:... changed snippets to VarNames ...
I updated the code. Also note, I used snippets because you aren't necessarily returning variables (in your example you weren't at all).
Visioneer wrote:... add in the 2 optional COM_invoke things.
You're slipping back into AHK Basic again.

AHK Basic (requires COM library):
COM_Invoke(pObject, "property")

AHK v1.1+:
Object.property
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

13 Oct 2013, 17:30

Hi jethrow,

Please convert the 2 COM_invoke lines to be applied to the proper pwb or pwin
thing (as shown in the old code). The old code used pwin I believe for the execScript and
the COM_invoke's used pwb. Check the old code I posted. Anyway these 2 have been
renamed to COM_to_Call1 and COM_to_Call2 respectively. It should allow some simple COM
commands to be imposed on the HWND window. Once we get it completed please post one
where IE9/7 users won't get the numbers in their copy/pastes. Maybe without numbers at
all.

Thanks

Code: Select all

F1::
myL =
(
alert("something");
//a javascript comment
//... a mile long javascript with functions, vars, vars from ahk, document writes, returning vars from webpage, whatever. Millions of js code are available also.
document.activeElement.focus();
var whoisthegreatest = "jethrow";
)

/*
IE_InjectJS(myHwnd, "window.onbeforeunload = null;", "", "Stop", "Quit")  ;This uses the 4th and 5th parameters.
I realize these parameters are misnamed. The 4th and 5th parameters just allow me to call for COM commands to be 
invoked (simply done) at 2 optional places. It can also allow an important fork in the road regarding
"silent" to be implementeed using the "LOAD" in JS_to_Invoke1, which I won't use in the public version. 
They should probably be called COM_to_Call1 and COM_to_Call2.  
They can be used to simply call a few COM things like Stop, Quit, GoBack, etc. It moves some simple COM
calls out to the function calls, which can be anywhere in the script. COM commands are important too.   
*/

;IE_InjectJS(myHwnd, "window.onbeforeunload = null;", "", "Stop", "Quit")  ;This uses the 4th and 5th parameters. It should close a stubborn window.

myReturnVar := IE_InjectJS(WinExist("ahk_class IEFrame"),myL, "document.title,document.activeElement.tagName,whoisthegreatest")

MsgBox, 4096,, myReturnVar is: %myReturnVar%, 5

Loop, Parse, myReturnVar, `,
{
if A_Index = 1
myVar1 = %A_LoopField%
if A_Index = 2
myVar2 = %A_LoopField%
if A_Index = 3
myVar3 = %A_LoopField%

}
MsgBox, 4096,, myVar1 is: %myVar1%`nmyVar2 is: %myVar2%`nmyVar3 is: %myVar3%, 5

return


IE_InjectJS(hWnd_MainWindow, JS_to_Inject, VarNames_to_Return="", COM_to_Call1="", COM_to_Call2="") {
   
   window := _win(hWnd_MainWindow)
   
   if JS_to_Inject
      window.execScript(JS_to_Inject)
   
   
   if COM_to_Call1 
   {

   ;MsgBox, 4096,, COM_to_Call1 is: %COM_to_Call1%, 4
   ;COM_Invoke(pwb, COM_to_Call1)  ;this needs to be converted to new ahk_l function 
   
   pwb[COM_to_Call1]

   }     
   
   
   if VarNames_to_Return
      Loop, Parse, VarNames_to_Return, `,
      {
         Loop, Parse, A_LoopField, .
            result := (A_Index=1? window:result)[A_LoopField]
         Ret .= result ","
      }

   
   if COM_to_Call2 
   {
   ;MsgBox, 4096,, COM_to_Call2 is: %COM_to_Call2%, 4
   ;COM_Invoke(pwb, COM_to_Call2)  ;this needs to be converted to new ahk_l function 

   pwb[COM_to_Call2]
   
   }  


   return SubStr(Ret,1,-1)
}



_win(hwnd, Svr#=1) {               ;// based on ComObjQuery docs

   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID1 := "{0002DF05-0000-0000-C000-000000000046}"	; IID_IWebBrowserApp
		, IID2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"	; IID_IHTMLWindow2

   SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_id %hwnd%

   if (ErrorLevel != "FAIL") {

      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)

      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {

         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)

			return	ComObj(9,ComObjQuery(pwb:=ComObjQuery(pdoc,IID1,IID1),IID2,IID2),1)
				,	ObjRelease(pdoc), ObjRelease(pwb)

      }

   }

}


GuiClose:
 ExitApp
Last edited by Visioneer on 15 Oct 2013, 02:21, edited 2 times in total.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: COM_L Inject javascript

14 Oct 2013, 03:11

jethrow wrote: IMPORTANT: On a side note, I may update the WBGet & IEGet functions. I'm thinking of switching them, and then allowing IEGet (currently WBGet) the optionally return the window, document, or webbrowser object.
I'd have a use for it :) just saying
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

14 Oct 2013, 12:36

Hi jethrow,
You're slipping back into AHK Basic again.
Does that kind of sarcasm give you pleasure?
When I add the 2 function parameters, it is exactly the same for basic as
for v1.1+. It is the converting of the 2 lines inside the function that I am simply
asking your help to convert from what we all know is old basic ahk to new ahkv1.1+.

So based on your cryptic teaching answer to the question:
How do I convert?
COM_Invoke(pwb, COM_to_Call2)
to new ahk v1.1+

you reply:

AHK Basic (requires COM library): - (Duh?)
COM_Invoke(pObject, "property")

AHK v1.1+:
Object.property - (Cryptic teaching reply.)

Then I try
to covert the 2 old ahk basic lines it would be: ?

window.COM_to_Call1
and
window.COM_to_Call2

Say that COM_to_Call2 is a parameter var with value of: Quit or Stop or GoBack etc.

but I keep getting an error. I have tried many many variations of this.

So please tell me how "object.property" is supposed to help me.

Is the "object" window?
How does the property (from the var COM_to_CALL2) get applied to object.

I looked for quite awhile for straight forward examples of converting basic to 1.1+
but they seem to have disappeared from what I used to see. (you do that?)
You have some links to check, if you insist on not just giving me the answer.
I am writing another program having nothing to do with this function. I have
many things to take care of. I don't have time to be a student of COM.
Besides, at my age (62) I am on the way down, not up. I thought the community should
have this function so I have put in over 24 hours on it.

Basically I want to limp away from this project with what little dignity
you have left me. I have already told you how great you are, but you
still feel the need to crush me just that little bit more. You have almost
convinced me that I should not be using ahk or even programmng any more.
I wonder if you ever consider that possibility when you taunt your (students).
Maybe you should ask them if they want straight answers or nice teaching riddles,
at the beginning of your sessions with users. You might be surprised at their answers.
I mean everything can't be a "teachable moment".

Thanks

ps:
I on purpose don't spoon-feed 100% of the answer to questions ... this helps determine how to best help the user. For instance, in your case, if you are having trouble identifying that you're missing a UDF, then that gives everyone a indicator of how to best help you.
I thought you were missing the WbGet() and IEGet() from the NEW
ahkv1.1+ as far as you knew. If you are going to "switch" them, btw, I would like to get
them when you finish them. They sound promising.

That masterpiece of yours was inserted long after other posts were made. People will see that and wonder why my patience was so thin after you had just posted such a wonderful thing. Well played jethrow. Well played. RHIP. Moderators too I guess.

Please "spoon-feed" this baby and finish the one line of code. I am sure they will be the same as each other. The added parametters are COM_to_Call1 and COM_to_Call2.
The old ahk code that needs to be converted to NEW ahk v1.1+ is:

;COM_Invoke(pwb, COM_to_Call2)
where COM_to_Call1[2] is basic COM commands like quit, goback, stop, etc.
The "object" needs to be the object needed to work in the function I posted of
your wonderful IE_Inject function. Maybe "window" ? It needs to be in the proper context
of where it is located in your function.

I am specifying as you asked before, that I do not want lessons. Please just clone the code please.

Thanks
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

15 Oct 2013, 00:36

Nice guilt trip - you trying to make me feel like the judge in Luke 18?
Visioneer wrote:Then I try
to covert the 2 old ahk basic lines it would be: ?

window.COM_to_Call1
and
window.COM_to_Call2

Say that COM_to_Call2 is a parameter var with value of: Quit or Stop or GoBack etc.
First off - Quit, Stop, & GoBack are members of the WebBrowser/IE object, not the window object. Therefore, there is no valid conversion since the AHK Basic code wasn't valid. Moveover, I know that you never even tried the code in AHK Basic or AHK v1.1+ before asking me to give you the answer.
Visioneer wrote:;COM_Invoke(pwb, COM_to_Call2)
where COM_to_Call1[2] is basic COM commands like quit, goback, stop, etc.
That's more like it - though I already gave you the answer in 2 separate places earlier in this topic ...

... but here you go: pwb[COM_to_Call2]

Note that COM_to_Call2 cannot be a dot-path call - that was syntax sugar that Sean implemented in the COM library because the functionality of Native COM didn't exist yet (see the IE_InjectJS I posted for how to parse a dot-path call). Also note that AHK Basic used raw interface pointers because AHK objects didn't exist yet. That's why it's pwb, rather than wb (p stands for pointer). Since you are using AHK with Native COM support, I'd recommend using the variable name wb over pwb. If you unwrap the object, then I'd assign it to pwb so you remember to release it.
Blackholyman wrote:I'd have a use for it :) just saying
Me too.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

15 Oct 2013, 01:24

Code: Select all

18 Then Jesus told his disciples a parable to show them that they should always pray and not give up. 2 He said: “In a certain town there was a judge who neither feared God nor cared what people thought. 3 And there was a widow in that town who kept coming to him with the plea, ‘Grant me justice against my adversary.’

4 “For some time he refused. But finally he said to himself, ‘Even though I don’t fear God or care what people think, 5 yet because this widow keeps bothering me, I will see that she gets justice, so that she won’t eventually come and attack me!’”

6 And the Lord said, “Listen to what the unjust judge says. 7 And will not God bring about justice for his chosen ones, who cry out to him day and night? Will he keep putting them off? 8 I tell you, he will see that they get justice, and quickly. However, when the Son of Man comes, will he find faith on the earth?”
I guess I am getting those gd numbers pasted where ever I go.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

15 Oct 2013, 02:32

Ok jethrow,

I tried the pwb[COM_to_Call1] and 2 thing in my local copy of my version of the
function. It did not crash this time, but there was no COM command executed.

So I do not see any wb or pwb in the top function. I guess this would be a reference
to a browser (webpage. I do not see or know how to add one myself.

I have edited my posted copy to include the pwb[COM_to_Call1] and pwb[COM_to_Call2]
Please try to use it to easily test your function and add in a pwb/wb reference. Just press f1 to test it.

Thanks
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

15 Oct 2013, 23:39

Code: Select all

COM_to_Call1 := "document.title"
COM_to_Call2 := "Quit"

wb := ComObjCreate("InternetExplorer.Application")
wb.Navigate("www.google.com")
wb.Visible := true

while wb.busy
	sleep 10

Loop, Parse, COM_to_Call1, .
	result := (A_Index=1? wb:result)[A_LoopField]
MsgBox,, %COM_to_Call1%, %result%

wb[COM_to_Call2]
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

16 Oct 2013, 01:18

Thanks jethrow,

Very interesting. I need to get a wb that refers to the HWND being used inside
your IE_InjectJS function. It probably would have been more apparent to me
if your had used 1 function instead of 2 the way the way you did. The webpage
of course would already exist in this senario when using this IE_InjectJS functon.
This added feature in meant to co-exist with IE_InjectJS. It is part of it, is it not?

I think the actual usage should be in the top part function. The COM_to_Call1 should
probably be just before the execScript is used so we can prep the webpage if necessary.
The COM_to_Call2 should be after the snippets are collected to maybe do aftermath
stuff like quit or goBack etc. I would also like to see if COM_to_Call could have more
than 1 command in it. One example of it's use would be to help close those infernal
webpages that won't close or goBack without a struggle, They popup that "stay on this page" thing.

I could take a stab at it, but I want to make sure that the final public function is
perfect for the community. I think it is a very important function for a lot of folks.

BTW: When you said you did not think I even tried out your function in either
ahk basic or ahk v.1.1+, it made me wonder if your function is by any chance
compatible with both? I of course tried it with ahk v1.1+ as I wrote the F1: thing
which even parses out and msgBox'es the 3 variables/snippets, so people could try it
quickly. But I never did try it with ahk basic. It is compatible with ahk basic as
well ? That would be astounding. Of course not necessary, but astounding.

Also I prefer Varnames to Snippets in deference to ahklearner who wrote the first
version long ago. It is a continuity thing. Also, variables is what they all wind up being.
Also I mostly use it for varables that exist in the original webpage.

Many Thanks

ps: I hope you will take a look at my request for help I just posted on ChangeDisplaySettings
function. I am trying to word them a little differently now after this session with you. :)
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

23 Oct 2013, 16:59

Ok, here is the finished product. It uses 5 parameters. jethrow, if you feel the need to repost
this, please do not put the numbers in as it makes it a pain to copy paste.
I will post this by itself on autohotkey.com and ahkscript.org so people can
see it quickly without all the drama.

Enjoy folks.

Thanks

Code: Select all

F2::
ExitApp

F1::
;We use this because wonderful COM often causes errors. Like GoBack on the first page in history gives an error.
;Once you get used to this function, you will save many hours by not having to learn "the COM way" for almost everthing.
;Maybe it is just me, but I would like to see a chm help file for COM. I hate pouring through 20 pages of
;forum posts at every turn. 
;BTW: Use the site:ahkscript.org ??? or site:autohotkey.com ??? with google to have a better chance at searching.  
ComObjError(false)

;The example myScript var can be a very very long javascript. 
myScript =
(
alert("something");
//a javascript comment
//... a mile long javascript with functions, vars, vars from ahk, document writes, returning vars/content from webpage, whatever. 
//Millions of js code are available also.
document.activeElement.focus();
var message = "jethrow mostly wrote this function(s). Visioneer helped a tiny little bit.";
)

/*
IE_InjectJS(myHwnd, "window.onbeforeunload = null;", "", "Stop", "Quit")  ;This uses the 4th and 5th parameters
to allow some simple COM commands to be executed on the IE webpage both before the (javascript/get vars) is called 
and/or after the (javascript/get vars) are called.   
They can be used to simply call a few COM things like Stop, Quit, GoBack, etc. It moves some simple COM
calls out to the function call, which can be anywhere in the script. COM commands can be important too.   
*/
 
;This returns 3 vars and injects myScript javascript and executes 1 COM command at the end(COM_to_Call2)(5th parameter).
myReturnVar := IE_InjectJS(WinExist("ahk_class IEFrame"), myScript, "document.title,document.activeElement.tagName,message", "", "GoBack")

;This is my favorite way to get the Title and URL of a webpage.
;myReturnVar := IE_InjectJS(WinExist("ahk_class IEFrame"), myScript, "document.title,location.href", "", "")

;This only excutes a COM command (GoBack)(Twice) at the end. No vars are returned.
;IE_InjectJS(WinExist("ahk_class IEFrame"), "", "", "", "GoBack,GoBack")

;This uses myHWND directly which can be obtained many ways.
;WinGet, myHWND, ID, ahk_class IEFrame
;myHWND := WinExist("A")
;IE_InjectJS(myHWND, "", "", "", "GoBack,GoBack")

;MsgBox, 4096,, myReturnVar is: %myReturnVar%, 5

;if Vars are being returned, this will parse them out and display their values.
if myReturnVar
{
Loop, Parse, myReturnVar, `,
{
if A_Index = 1
myVar1 = %A_LoopField%
if A_Index = 2
myVar2 = %A_LoopField%
if A_Index = 3
myVar3 = %A_LoopField%
}
MsgBox, 4096,, myVar1 is: %myVar1%`nmyVar2 is: %myVar2%`nmyVar3 is: %myVar3%
}

return ;End F1::


;COM_to_Call[1|2] can be a [,] delimited string of simple COM commands like GoBack,GoBack etc.
;VarNames_to_Return can be Vars in the webpage, or webpage contents like document.title, location.href etc.
;All parameters are optional except hWnd_MainWindow. Thanks to jethrow. 
IE_InjectJS(hWnd_MainWindow, JS_to_Inject="", VarNames_to_Return="", COM_to_Call1="", COM_to_Call2="") {
   
   window := _win(hWnd_MainWindow)
   
   wb := WBGet("ahk_id" hWnd_MainWindow)
   
   if COM_to Call1 
   {
    ;MsgBox, 4096,, COM_to_Call1 is: %COM_to_Call1%, 4       
    Loop, Parse, COM_to_Call1, `, 
    {
    ;MsgBox, 4096,, A_LoopField is: %A_LoopField%, 4
    wb[A_LoopField]     
    }    
   }     
            
   if JS_to_Inject
      window.execScript(JS_to_Inject)
            
   if VarNames_to_Return
      Loop, Parse, VarNames_to_Return, `,
      {
         Loop, Parse, A_LoopField, .
            result := (A_Index=1? window:result)[A_LoopField]
         Ret .= result ","
      }
  
   if COM_to_Call2 
   {
    ;MsgBox, 4096,, COM_to_Call2 is: %COM_to_Call2%, 4                 
    Loop, Parse, COM_to_Call2, `, 
    {
    ;MsgBox, 4096,, A_LoopField is: %A_LoopField%, 4
    wb[A_LoopField]     
    }               
   }  

   return SubStr(Ret,1,-1)
}

_win(hwnd, Svr#=1) {               ;// based on ComObjQuery docs

   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID1 := "{0002DF05-0000-0000-C000-000000000046}"	; IID_IWebBrowserApp
		, IID2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"	; IID_IHTMLWindow2

   SendMessage msg, 0, 0, Internet Explorer_Server1, ahk_id %hwnd%

   if (ErrorLevel != "FAIL") {

      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)

      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {

         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)

			return	ComObj(9,ComObjQuery(pwb:=ComObjQuery(pdoc,IID1,IID1),IID2,IID2),1)
				,	ObjRelease(pdoc), ObjRelease(pwb)

      }

   }

}

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
Last edited by Visioneer on 23 Oct 2013, 19:37, edited 1 time in total.
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

23 Oct 2013, 17:10

Take a look at the WBGet or IEGet function. Note that a webbrowser object has a HWND property.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

26 Oct 2013, 20:13

Hi jethrow,

Thanks for everything.

How great thou art.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DaveF, Hansielein and 126 guests