AutoHotkey Community

It is currently May 27th, 2012, 6:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 194 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 13  Next
Author Message
 Post subject:
PostPosted: October 2nd, 2010, 9:06 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
You would need to pass in an IDispatch interface, such as created by DispatchObj.

Thx Lexikos. That is exactly what I hopped for.

EDIT: One thing, how do I use it for html control ? I don't see on the msdn how to access AddObject method aside from instantiating ScriptControl.

EDIT2: Seems this one: http://msdn.microsoft.com/en-us/library ... 42(v=VS.85).aspx

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2010, 12:41 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
I think that'll just give you the document object, which you probably already have. You just need to store the object somewhere. Below is an updated version of my example in the DispatchObj thread; it assumes ieWin is the WebBrowser or window object of the HTML control and obj is the wrapped DispatchObj:
Code:
; Create 'ahk' variable. (var=''; also works)
ieWin.execScript("var ahk;","JScript")
; Assign dispatch object to ahk variable.
ieWin.ahk := obj

The declaration is necessary because we're interacting with the object via the IDispatch interface, which wasn't designed for dynamic objects. It is possible to add members to dynamic objects via the IDispatchEx interface, assuming they implement it:
Code:
Expando(obj, name)
{
    ; Allow obj to be either a ComObj or interface pointer.
    ptr := IsObject(obj) ? ComObjUnwrap(obj) : obj
    ; Retrieve IDispatchEx interface pointer.
    if dspEx := COM_QueryInterface(ptr, "{A6EF9860-C720-11d0-9337-00A0C90DCAA9}")
    {
        ; dspEx->GetDispID(name, fdexNameCaseSensitive|fdexNameEnsure, &id)
        if !hr := DllCall(NumGet(NumGet(dspEx+0)+7*A_PtrSize), "ptr", dspEx
              , "ptr", COM_SysString(wname,name), "uint", 3, "int*", id, "uint")
        {
            ; Although fdexNameEnsure "requests that the member be created",
            ; obj[name]:=x still causes an "Unknown name" error unless we
            ; do this first: store an empty value in the member.
            VarSetCapacity(args, 16+n:=A_PtrSize*2+8, 0)
            NumPut(1, NumPut(&args+n, args), A_PtrSize, "uint")
            ; dspEx->InvokeEx(id, LOCALE_USER_DEFAULT, DISPATCH_PUT, &args ...)
            hr := DllCall(NumGet(NumGet(dspEx+0)+8*A_PtrSize), "ptr", dspEx
              , "int", id, "uint", 0x400, "uint", 4, "ptr", &args
              , "ptr", 0, "ptr", 0, "ptr", 0, "uint")
        }
        ObjRelease(dspEx)
    }
    else hr := 1*0x80004002 ; E_NOINTERFACE
    IsObject(obj) ? ObjRelease(ptr) : ""
    return hr
}
Example:
Code:
Expando(Document, "foo")
Document.foo := "bar"
See also: expando Property.


While testing, I realized that because x.y and x.y() both use a combination of DISPATCH_PROPERTYGET and DISPATCH_METHOD, you can't call JavaScript functions directly. For instance, having declared a function "myfunc" in a <script>, Document.parentWindow.myfunc() only retrieves a reference to the function; doesn't call it. Similarly, if you use ...myfunc.call(), it retrieves a reference to the call function. This will be changed in the next release so that x.y() is always a method-call. For convenience, x.y will retain its current behaviour.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 2nd, 2010, 7:21 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thx lexikos. Ill see what I can do with all that info if I manage to rewrite DispatchObj.

It seems that not all events work according to docs.

onkeyup and onkeydown set either via ahk code or javascript code don't work. The same html code loaded into IE works.

onkeypress works for most keys. It doesn't report arrows, enter, pageup/down (even if I disable scrollbars via document.body.scroll := "no")
Code:
#SingleInstance, force
   CreateWindow()
   LoadHtml()
   Gui, Show, autosize
return


LoadHtml() {
   global

   html =
   (
   <html>
   <script>
      document.onkeyup = KeyCheck; 
      //alert(document.onkeyup);
      function KeyCheck()   { alert('Key code: ' + event.keyCode); }
   </script>
   <body>
      press key to see code
   </body>
   </html>
   )

   FileDelete _out.html
   FileAppend %html%, _out.html
   htmlDoc.write(html)

   ;x := htmlDoc.onkeyup
   ;m(ComObjType(x, "Name"))
}


CreateWindow() {
   global
   Gui, +LastFound
   hForm := WinExist()

   Gui, Add, Text, HWNDhCtrl w400 h400

   htmlDoc := COM_AtlAxCreateControl( hCtrl, "HTMLfile" ) ; http://msdn.microsoft.com/en-us/library/da181h29
   NativeCom(htmlDoc) ; ensures the "doc" object uses Native COM

   ComObjConnect(htmlDoc, "htmlDoc_")
}   
      
htmlDoc_onkeyup(p){
   msgbox % A_ThisFunc
}

NativeCom( ByRef obj ) { ; ensures the "obj" object uses Native COM
   if Not IsObject(obj)
      return
   ComObjError(false)
   if Not ComObjType(obj,"iid")
      obj := ComObjEnwrap(COM_Unwrap(obj))
   ComObjError(true)
}

#include COM.ahk


Now, part of the interface I am making is html table. User should be able to select rows using arrows and launch the action via Enter. Its easily done in javascript but the problem is that arrows and enter do not fire correctly once the html runs inside the gui control. If i change keys to something else, lets say , j, k and space, it works.

Now, onkeypress on arows also doesn't work in browser. So, the solution is to make gui control being able to fire keydown or keyup events which do fire correctly in browser and can handle 'special' keys. I didn't yet found solution to this problem. Is there anything here I am missing ?

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2010, 3:03 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Lexikos wrote:
Document.parentWindow.myfunc() only retrieves a reference to the function; doesn't call it. Similarly, if you use ...myfunc.call(), it retrieves a reference to the call function.
You can call it like this.
Code:
; Document.parentWindow.myfunc("")
ftn := Document.parentWindow.myfunc
ftn.call(ftn)

Quote:
This will be changed in the next release so that x.y() is always a method-call. For convenience, x.y will retain its current behaviour.
I don't think it's a good idea as it may break some codes ported from VBScript. If it has to be done, I suppose it better be restricted to no argument case.
Code:
IS_INVOKE_SET ? DISPATCH_PROPERTYPUT : !aParamCount && IS_INVOKE_CALL ? DISPATCH_METHOD : DISPATCH_PROPERTYGET | DISPATCH_METHOD


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2010, 3:18 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
majkinetor wrote:
Is there anything here I am missing ?
There's a known issue with hosting the IE control which has been discussed at least a few times already. The solution is to hook WM_(SYS)KEYDOWN/UP and have them call IOleInPlaceActiveObject::TranslateAccelerator(). For instance, see Sean's post. I'm not sure if it's the only problem, though.
Sean wrote:
You can call it like this.
Code:
ftn := Document.parentWindow.myfunc
ftn.call(ftn)
I see; the presence of a parameter removes the ambiguity (since DISPATCH_PROPERTYGET for that member doesn't accept parameters). This also works:
Code:
Document.parentWindow.myfunc(1)

Quote:
If it has to be done, I suppose it better be restricted to no argument case.
Good idea.
Quote:
If it has to be done,
What's the point of having different syntaxes if they're all ambiguous?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2010, 3:48 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Lexikos wrote:
What's the point of having different syntaxes if they're all ambiguous?
Yes, actually how to interpret the flags is completely up to the Server/engine. I felt sorry that we could not fully utilize AHK_L's capability to unambiguously differentiate between CALL & GET, due to the notational incompatibility between JScript and VBScript. If we impose the strict syntax, I reckon a lot of users, especially from VBScript, will be utterly confused.

PS. I once tempted about this syntax.
Code:
value := obj.name(...) ; DISPATCH_METHOD
value := obj.name[...] ; DISPATCH_PROPERTYGET
obj.name[...] := value ; DISPATCH_PROPERTYPUT
obj.name(...) := value ; DISPATCH_PROPERTYPUTREF


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 3rd, 2010, 7:42 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
There's a known issue with hosting the IE control which has been discussed at least a few times already. The solution is to hook WM_(SYS)KEYDOWN/UP and have them call IOleInPlaceActiveObject::TranslateAccelerator(). For instance, see Sean's post. I'm not sure if it's the only problem, though.

Thanks. This worked.

Now that both js event and ahkl COM attachment work, how can I get in ahkl the key that was pressed. In doc_onkeydown(p) argument p is of type DispHTMLDocument.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2010, 6:39 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Code:
Text := "Hello World!"

SAPI := ComObjCreate("SAPI.SpVoice")
MsgBox, 0, Rate: 0, Speak the Text
SAPI.speak(Text)

MsgBox, 0, Rate: -7, Slow down the Speech
SAPI.rate := -7
SAPI.speak(Text)

MsgBox, 0, Rate: 7, Speed up the Speech
SAPI.rate := 7
SAPI.speak(Text)

SAPI.rate := 0 ; set to default rate

MsgBox, 0, Volume: 50, Lower the Volume (ranges 0-100)
SAPI.volume := 50
SAPI.speak(Text)

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject: ImageMagickObject
PostPosted: October 22nd, 2010, 1:58 pm 
Offline

Joined: June 4th, 2005, 1:30 am
Posts: 113
Location: Stuttgart, Germany

Code:
oI := ComObjCreate("ImageMagickObject.MagickImage.1")

imgs := Object()
   
Loop, 16 {
   filename := "plasma" . A_Index . ".jpg"
   oI.convert("-size", "200x200", "plasma:", filename)
   imgs.Insert(filename)   
}

imgs.Insert("montage.jpg")   
stitch(oI, imgs*)

stitch(obj, params*) {
   obj.montage("-geometry", "+0+0", params*)
}

oI.convert("montage.jpg", "-verbose", "info:image_info.txt")
oI.convert("montage.jpg", "-define", "histogram:unique-colors=false", "histogram:histogram.gif") ; create histogram
FileRead, info, image_info.txt
FileDelete, image_info.txt
MsgBox % info


Convert image to text:
Code:
oI := ComObjCreate("ImageMagickObject.MagickImage.1")
oI.convert("montage.jpg", "montage.txt")

Output:
Code:
# ImageMagick pixel enumeration: 40,40,255,rgb
0,0: (235,241,255)  #EBF1FF  rgb(235,241,255)
1,0: (221,242,237)  #DDF2ED  rgb(221,242,237)
2,0: (219,253,226)  #DBFDE2  rgb(219,253,226)
3,0: (192,225,208)  #C0E1D0  rgb(192,225,208)
4,0: (202,224,237)  #CAE0ED  rgb(202,224,237)
5,0: (223,232,255)  #DFE8FF  rgb(223,232,255)
6,0: (224,220,245)  #E0DCF5  rgb(224,220,245)
7,0: (240,223,239)  #F0DFEF  rgb(240,223,239)
8,0: (255,240,251)  #FFF0FB  rgb(255,240,251)
9,0: (244,253,255)  #F4FDFF  rgb(244,253,255)
10,0: (188,228,230)  #BCE4E6  rgb(188,228,230)
11,0: (192,239,245)  #C0EFF5  rgb(192,239,245)
12,0: (209,236,255)  #D1ECFF  rgb(209,236,255)
13,0: (232,235,255)  #E8EBFF  rgb(232,235,255)
14,0: (235,237,255)  #EBEDFF  rgb(235,237,255)
15,0: (213,225,237)  #D5E1ED  rgb(213,225,237)
16,0: (230,237,245)  #E6EDF5  rgb(230,237,245)
17,0: (230,249,255)  #E6F9FF  rgb(230,249,255)
...


Get information about a single pixel of an image:
Code:
; http://www.imagemagick.org/script/fx.php
oI := ComObjCreate("ImageMagickObject.MagickImage.1")
r := oI.identify("-format", "%[fx:p{280,280}.r]", "montage.jpg")
MsgBox % r


Notes:
I sometimes need to automatically stitch images together.
I used GflAx previously, but there had to calculate canvas size and positioning myself.
Now ImageMagick does the job for me.

The scope of ImageMagick is endless. Explore!

Tested with AHK v1.0.48.05.L61.

BTW: Thanks Lexikos for all the great changes!


Last edited by olfen on December 7th, 2011, 6:06 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2010, 4:05 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
BTW, IsObject check is not necessary. Error message will be popped up if creation fails.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2010, 4:30 pm 
Offline

Joined: June 4th, 2005, 1:30 am
Posts: 113
Location: Stuttgart, Germany
Sean wrote:
BTW, IsObject check is not necessary. Error message will be popped up if creation fails.
Thank you, Sean. Removed.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2010, 5:48 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
Code:
oWord := ComObjCreate("Word.Application")   ; create MS Word object
oWord.Documents.Add   ; create new document

oWord.Selection.Font.Bold := 1   ; bold
oWord.Selection.TypeText("Visit ") ; type text
oWord.ActiveDocument.Hyperlinks.Add(oWord.Selection.Range, "http://www.autohotkey.com/forum/topic61509.html"
   ,"","","COM Object Reference [AutoHotkey_L]")    ; insert hyperlink
oWord.Selection.TypeText("and learn how to work with ")   ; type text
oWord.Selection.Font.Italic := 1   ; italic
oWord.Selection.TypeText("COM objects")   ; type text
oWord.Selection.Font.Bold := 0, oWord.Selection.Font.Italic := 0   ; bold and italic off
oWord.Selection.TypeText(".")   ; type text
oWord.Selection.TypeParagraph   ; type paragraph (enter, new line)

oWord.Visible := 1, oWord.Activate   ; make it visible and activate it.
ExitApp


Last edited by Learning one on October 22nd, 2010, 5:54 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2010, 5:51 pm 
Online
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Very cool olfen i am often in need of a way to do some behind the sceens manipulation of images. thanks for locating the documentation

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2010, 5:54 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
olfen - thanks for the example. However, call me ignorant, but I cannot get imagemagick registered on my computer. I downloaded ImageMagick-6.6.5-2-Q16-windows-dll.exe & installed it, but ImageMagickObject.MagickImage.1 still isn't a valid class on my computer. I'm running XP SP3 (<512 MB RAM). I noticed the notes state you may have to install Visual C++ 2010 Redistributable Package (x86). Would this be what's causing my problems? Also, do you know if there's a single DLL you can download and register to use this COM object?

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2010, 6:18 am 
Offline

Joined: June 4th, 2005, 1:30 am
Posts: 113
Location: Stuttgart, Germany
I am using XP SP3, too.
Have you tried this (in app dir)?
Code:
regsvr32 /c /s ImageMagickObject.dll

There is no single DLL, ImageMagickObject.dll has several dependencies.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Exabot [Bot], Google Feedfetcher, JamixZol, Yahoo [Bot] and 17 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