AutoHotkey Community

It is currently May 27th, 2012, 11:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 194 posts ]  Go to page 1, 2, 3, 4, 5 ... 13  Next
Author Message
PostPosted: August 17th, 2010, 8:08 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Purpose: to create a basic reference for commonly used COM objects.
AutoHotkey_L supports COM natively (thank you Lexikos, Sean, & fincs :) ). This doesn't eliminate the COM Standard Library, but it does add quite a bit of functionality to AutoHotkey. However, if users don't know or understand any COM objects, this Native COM support is less appealing/useful. Therefore, I am creating this thread as somewhat of a basic COM object reference. Forum members can add a COM object "profile", and I will link it to the original post. Questions are also welcome. Here is the suggested BBCode for the COM obj profile:
Code:
[list][*][b]COM Object:[/b] [*][b]Purpose:[/b] [*][b]System Requirements:[/b] [*][b]Documentation Link:[/b] [*][b]Other Links:[/b][*][b]Basic Code Example:[/b] [/list]
NOTE - for the Documentation Link, please provide a link to the method/properties documentation.

See Also: CLSID Registry Scanner - view information about COM/ActiveX components installed on your computer.

COM Object List:MS Office ApplicationsObjects Requiring Additional Files/Installation (see also - Register ActiveX Component)

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on May 5th, 2012, 6:22 pm, edited 41 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2010, 8:08 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
... some other COM posts:

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on April 16th, 2011, 8:20 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2010, 8:10 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Code:
oSD := ComObjCreate("Scripting.Dictionary")

; Add Items
oSD.Add("Name", "AutoHotkey")
oSD.Add("Abv", "AHK")
oSD.Item("URL") := "www.autohotkey.com"

; Get Item
MsgBox, 0, Get Key, % "Name = " oSD.item("Name")

; Get Number of Items
MsgBox, 0, Item Count, % "Total Items: " oSD.Count

; Check for Key Existance
MsgBox, 0, Key Exist?
      , %   "Abv Exist: " oSD.Exists("Abv") "`n"
      .     "Test Exist: " oSD.Exists("Test")

; Remove a Key
oSD.Remove("Abv")
MsgBox, 0, Removed: "Abv", % "Abv Exist: " oSD.Exists("Abv")

; Enumerate Keys
for Key in oSD
   list .= Key " = " oSD.item(Key) "`n"
MsgBox, 0, Enumerated Keys, %list%

; Clear the Dictionary
oSD.RemoveAll()
MsgBox, 0, Removed All Keys, % "Total Items: " oSD.Count

Quote:
... what can Scripting.Dictionary do that the built-in objects can't do?
Great question - Case Sensitive Keys & Enumerating Keys in Order of Creation (natively):
Code:
oSD := ComObjCreate("Scripting.Dictionary")

; Case Sensitive Keys
oSD.item["ahk"] := "autohotkey"
oSD.item["AHK"] := "AutoHotkey"
MsgBox, % oSD.item["ahk"] "`n" oSD.item["AHK"]

oSD.RemoveAll()

; Enumerate Keys in Order of Creation
Loop, 5
    oSD.item[6-A_Index] := "Value " A_Index
for key in oSD
    t .= key " = " oSD.item[key] "`n"
MsgBox, %t%

Related: How make Associative array keys case sensitive

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on January 2nd, 2011, 9:33 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 7:45 pm 
this is execellent, i know nothing of COM so please teach me in this thread :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 7:46 pm 
and i assume the same Scripting.Dictionary can be done in regular AHK? perhaps you should post both vanilla and _L code?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 7:57 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Vanilla is not supported here, it's an AutoHotkey_L-only thread.
It is strongly recommended that you use AutoHotkey_L for COM tasks.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 8:00 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
guest3456 wrote:
...perhaps you should post both vanilla and _L code?
One of the main reasons COM seems so confusing, IMO, is because of the syntax that was required with Vanilla AHK. However, with Native COM support in AutoHotkey_L, COM has a more natural syntax. Therefore, I'm going to refrain from posting Vanilla AHK syntax in this thread to minimalize confusion & lessen the learning curve. However, there are several posts throughout the forums. Here's one both Lexikos and Sean participated in: Arrays using ws4ahk, & Dictionary\Array Objects

@fincs - thanks for the input, and thanks for helping in the development of AHK w/ Native COM Support :D

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 11:05 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
More importantly, what can Scripting.Dictionary do that the built-in objects can't do?

Code:
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", "http://www.autohotkey.net/~Lexikos/AutoHotkey_L/docs/AHKL_ChangeLog.htm")
WebRequest.Send()
RegExMatch(WebRequest.ResponseText, "(?<=<h2>).*?(?=</h2>)", ver)
MsgBox % ver
WebRequest := ""

* Note MSDN says Windows 2000 or later required, but I've seen some other cases where this wasn't accurate; maybe they say that since they really don't support older versions of Windows. Furthermore, AutoHotkey_L requires Windows 2000 or later.

Btw, perhaps the wiki is a good place to put this reference (without the discussion).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2010, 11:20 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Lexikos wrote:
... what can Scripting.Dictionary do that the built-in objects can't do?
This is an extremely good point. The main reason included it is for an example of using COM, since it's such a simple object.

Lexikos wrote:
... perhaps the wiki is a good place to put this reference (without the discussion).
I had thought about this too - perhaps we could do that as well. However, I was hoping to create somewhat of a learning environment where users could learn COM by creating an object "profile" with examples. My plan is to link multiple posts for each object back to the original post - especially for objects such as the MS Office Applications.

BTW - Thank You for the continued effort on developing AutoHotkey_L! :D

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2010, 9:17 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
  • COM Object: HTMLfile
  • Purpose: Represents an HTML document. Can be used to read, write, & interact with HTML.
  • System Requirements: General
  • Documentation Link: Object, Interface
  • Other Links: W3Schools - Document Object
  • Basic Code Example - this example extracts all the text & URLs from the links on the Google Search Page:
Code:
; download the webpage source
URLDownloadToFile, http://www.google.com, Google_HTML
FileRead, html, Google_HTML
FileDelete, Google_HTML

; write the Google Source to an HTMLfile
doc := ComObjCreate("HTMLfile")
doc.write(html)

; loop through all the links
links := doc.links
while (A_Index<=links.length, i:=A_Index-1)
   list .= i ") " links[i].innerText "`nURL: " links[i].href "`n`n"

; some URLs have "about:" rather than the domain
StringReplace, list, list, about:, http://www.google.com, All

MsgBox, %list%


This next example shows how an HTMLfile object* can be used to create an HTML Control:
Code:
color := HtmlBgColor()

; HTML to be added to a GUI:
html =
(
   <body style='background-color:%color%;overflow:auto'>
      <span id='id' style='color:black'>text color</span> example
   </body>
)

; create a simple GUI
Gui, Add, Button, x6 y60 w55 h20, Red
Gui, Add, Button, x71 y60 w55 h20, Blue
Gui, Add, ActiveX, x0 y-5 w140 h50 vDocument, HTMLFile
Document.write(html)
Gui, Show, x399 y246 w138 h86, HTML
Return

GuiClose:
   Gui, Destroy
   ExitApp
ButtonRed:
ButtonBlue:
   Document.all["id"].style.color := SubStr(A_ThisLabel,7)
   Return

HtmlBgColor() {
   Format := A_FormatInteger
   SetFormat, IntegerFast, Hex
   color := SubStr(DllCall("GetSysColor", "int",15),3)
   SetFormat, IntegerFast, %Format%
   return, SubStr(color,5,2) SubStr(color,3,2) SubStr(color,1,2) ; switch from BGR -> RGB
}

*Note - the HTMLfile object isn't required to accomplish this. You could simply write the HTML when adding the ActiveX Control:
Code:
Gui, Add, ActiveX, x0 y-5 w140 h50 vDocument, MSHTML:%html%

This post has an example of a completely HTML based GUI.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on March 2nd, 2012, 3:59 am, edited 8 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2010, 12:16 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
FYI Jethrow
I dont know if your aware but creating a htmldocument can also cause code to be live. Javascript executes any how. some window objects may not but its handy from a urldownloadtofile fileread standpoint for dynamic content :wink:

_________________
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: August 23rd, 2010, 1:51 am 
tank wrote:
... htmldocument can also cause code to be live.
The keyword here is "can", i.e. it only happens on some systems.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2010, 3:52 am 
Offline

Joined: June 4th, 2005, 1:30 am
Posts: 113
Location: Stuttgart, Germany
Quote:
GFL SDK is a library to load/save easily graphics formats.

It has the features :

Import about 100 graphic file formats
Export about 40 graphic file formats
Support of 10/12/16bits per component
Color mode convert
Lut transforms (brightness, contrast, ...)
Filters (blur, average, ...)
Tools (resize, de-interlace, ...)
Multi-page file creation
JPEG lossless transform
EXIF reading (with or without loading picture)
IPTC reading/writting (with or without loading picture)
And many may other things...

GFL SDK is provided as FREEWARE for private non-commercial or educational use (including non-profit organization)

Code:
oG := ComObjCreate("GflAx.GflAx") ; create GflAx object
oG.SaveFormatName := "tiff"       ; save image in Tagged Image File Format

w := 600, h := 420                ; set width and height of new image
oG.NewBitmap(w, h, 0x0)           ; create new bitmap

oG.LineWidth := 4                 ; set linewidth to 4
oG.LineColor := 0xB0CD7D          ; set linecolor to 0xB0CD7D (BGR-Format)

; Vertex contains a list of x\y-coordinates for use with AddVertex, DrawPolyLine and FreeVertex.
; Of course this list can be created dynamically in practical use.
Vertex := "0,240|25,240|29,210|42,269|56,225|62,240|117,240|137,190|158,269|167,217|170,240|233,240|"
. "248,179|267,270|281,218|288,240|354,240|372,176|390,259|402,220|408,240|458,240|487,118|530,319|552,185|"
. "565,240|600,240"

Loop, parse, Vertex, |           
{
  StringSplit, v, A_LoopField, `,
  oG.AddVertex(v1, v2)            ; add separate coordinates to the vertex list
}

oG.DrawPolyLine                   ; draw a polyline from the vertex list
oG.FreeVertex                     ; free the vertex list

oG.FillColor := 0xB0CD7D          ; set fillcolor to 0xB0CD7D (BGR-Format)
oG.DrawFillCircle(598, 240, 3)    ; draw a filled cricle
oG.GaussianBlur(0.6)              ; blur image
oG.SaveBitmap("Line")             ; save image

r1 := 30, r2 := 15                ; define width\height for columns\rows of grid
oG.NewBitmap(w, h, 0x004037)      ; create new bitmap with background-color
                                  ; 0x004037 (BGR-Format)

oG.LineWidth := 1                 ; set linewidth to 1
oG.LineColor := 0x054D3F          ; set linecolor to 0x054D3F (BGR-Format)
xy := 0
Loop, % w/r2 - 1
  xy += r2, oG.DrawLine(xy, 0, xy, h), oG.DrawLine(0, xy, w, xy)  ; Draw grid

oG.LineWidth := 1                 ; set linewidth to 1
oG.LineColor := 0x32824D          ; set linecolor to 0x32824D (BGR-Format)
xy := 0
Loop, % w/r1 - 1
  xy += r1, oG.DrawLine(xy, 0, xy, h), oG.DrawLine(0, xy, w, xy) ; Draw grid

oG.SaveBitmap("Grid")             ; save image

; Merge Grid.tif and Line.tif                                                                         
oG.MergeAddFile("Grid.tif", 50, 0 ,0)
oG.MergeAddFile("Line.tif", 50, 0 ,0)
oG.Merge
oG.MergeClear

; set font properties
oG.FontName := "Arial"
oG.FontSize := 24
oG.FontBold := true

; draw the text
oG.TextOut("AHK_L", 30, 30, 0x0000ff)
oG.SaveBitmap(A_ScriptName)

ObjRelease(oG)                    ; release object


Last edited by olfen on August 27th, 2010, 6:01 pm, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2010, 5:18 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
NOTE: On Windows 7, regsvr32.exe must be run as the Administrator

Olfen - thanks for the post - I've been wanting to learn more about drawing & creating images using AHK :) . Could you modify your post though? This example seems to require the GFL ActiveX Component (GflAx.dll) - which needs to be registered on the computer. The following script shows how this process can be automated ( requires DLL file: GlfAx.dll )
Code:
; Register ActiveX Component
RunWait, REGSVR32 /s GflAx.dll ; assuming DLL is in the Script Directory


; ... Run Code ...


; Unregister ActiveX Component
RunWait, REGSVR32 /u /s GflAx.dll

If some other users could help me out -- is it suspicious at all for a script/program to register it's own ActiveX Component -- or is this normal?

EDIT - Also, you can check if an ActiveX Component is Registered based on the ProgID (GflAx.GflAx) by checking the Registry:
Code:
RegRead, D, HKCR, GflAx.GflAx
if Errorlevel ; or If D =
   MsgBox, DLL Not Registered
else
   MsgBox, DLL is Registered

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on March 2nd, 2012, 3:48 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2010, 9:13 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
  • COM Object: ScriptControl
  • Purpose: Dynamically execute VBScript or JScript
    NOTE: Many VBScript & JScript scripts can be translated to AHK, rather than using the ScriptControl object. (see the last example)
  • System Requirements: 32bit AHK (see here for 64bit compatability)
  • Documentation Link: Using the ScriptControl
  • Other Links:
  • Basic Code Examples:
The first example will execute some basic VBScript:
Code:
oSC := ComObjCreate("ScriptControl")

; define the Language
oSC.Language := "VBScript"

; define the VBScript
script =
(
Dim string
Arr = Array("Auto", "Hot", "key!")
For Each i In Arr
   string = string & i
Next
MsgBox "Joined Array Elements:" & vbCR & string, 64, "VBScript MsgBox"
)

; execute the VBScript
oSC.ExecuteStatement(script)

; extract values from the VBScript
MsgBox, 64, AutoHotkey MsgBox, % "Joined Array Elements:`n" oSC.Eval("Arr(0) & Arr(1) & Arr(2)")


The next example will execute some basic JScript:
Code:
oSC := ComObjCreate("ScriptControl")

; define the Language
oSC.Language := "JScript"

; define the JScript
script =
(
string = '';
obj = { 'Name':'AutoHotkey', 'URL':'www.AutoHotkey.com', 'Color':'Green' };
for (i in obj)
   string += i + ' = ' + obj[i] + '\n';
)

; execute the JScript
oSC.ExecuteStatement(script)

; extract a value from the JScript
MsgBox, 0, JScript Variable "string":, % oSC.Eval("string")

; extract an Object from the JScript
obj := oSC.Eval("obj")
MsgBox, 0, Elements from the JScript Object:, % "Name: " obj.Name "`nURL: " obj.URL


This next example will execute JScript, which will execute VBScript:
Code:
oSC := ComObjCreate("ScriptControl")

; define the Language
oSC.Language := "JScript"

; define the JScript
script =
(
oSC = new ActiveXObject('ScriptControl');
oSC.Language = "VBScript";

script = 'MsgBox "VBScript in JScript in AutoHotkey", 48, "Embedded ScriptControls"';
oSC.ExecuteStatement(script);
)

; execute the JScript -> which executes VBScript
oSC.ExecuteStatement(script)

NOTE: The following 3 scripts are equivalent:
Code:
; AHK:
WB := ComObjCreate("InternetExplorer.Application")
WB.Navigate("http://www.autohotkey.com/forum/viewtopic.php?t=61509")
WB.Visible := True
while, WB.Busy
   Sleep, 100
MsgBox, % "WebPage Loaded: " WB.Document.title

; VBScript:
Set WB = CreateObject("InternetExplorer.Application")
WB.Navigate "http://www.autohotkey.com/forum/viewtopic.php?t=61509"
WB.Visible = True
While WB.Busy
   WScript.Sleep 100
WEnd
MsgBox "WebPage Loaded: " & WB.Document.title

; JScript:
WB = new ActiveXObject("InternetExplorer.Application")
WB.Navigate("http://www.autohotkey.com/forum/viewtopic.php?t=61509")
WB.Visible = 1
while (WB.Busy)
   WScript.Sleep(100)
WScript.Echo("WebPage Loaded: " + WB.Document.title)

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on September 17th, 2011, 2:30 pm, edited 9 times in total.

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 1, 2, 3, 4, 5 ... 13  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, rrhuffy and 37 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