COM Object Reference

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: COM Object Reference

03 Oct 2013, 04:09

Interesting..
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Menixator
Posts: 69
Joined: 30 Sep 2013, 04:10

Re: COM Object Reference

03 Oct 2013, 04:13

Related: Automating Foobar Using COM

[Mod edit: Fixed link.]
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: COM Object Reference

15 Jul 2014, 14:50

A remake of the index.
Index
Last edited by kon on 11 Jan 2015, 04:17, edited 2 times in total.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: COM Object Reference

06 Nov 2014, 18:42

COM Object: Publisher.Application
Purpose: Microsoft Publisher is an entry-level desktop publishing application from Microsoft, differing from Microsoft Word in that the emphasis is placed on page layout and design rather than text composition and proofing.
System Requirements: Microsoft Office Publisher
Documentation Link: Object model reference (Publisher 2013 developer reference)
Other Links: Save the active document as .jpg
Basic Code Example: This example will open Publisher, create a new document, draw a curve and a line, add some text, and SaveAs with two different formats (.jpg and .pub).

Code: Select all

; Constants
msoTrue := -1
pbPictureResolutionCommercialPrint_300dpi := 3
pbTextOrientationHorizontal := 1
VT_R4 := 4  ; 32-bit floating-point number

pbApp := ComObjCreate("Publisher.Application")      ; Create a Publisher application object and store a reference to it in the pbApp variable
pbApp.ActiveWindow.Visible := true                  ; Make the window visible

; Application.NewDocument Method (Publisher)
; http://msdn.microsoft.com/en-us/library/office/ff940013%28v=office.15%29.aspx
pbDoc := pbApp.NewDocument()                        ; Create a new document and store a reference to the object in the pbDoc variable

; Shapes Methods (Publisher)
; http://msdn.microsoft.com/en-us/library/office/dn338310%28v=office.15%29.aspx
pbDoc.Pages(1).Shapes.AddLine(100, 150, 500, 550)   ; Draw a line from the point (100, 150) to point (500, 550)

; Shapes.AddCurve Method (Publisher)
; http://msdn.microsoft.com/en-us/library/office/ff939838%28v=office.15%29.aspx
arrPoints := ComObjArray(VT_R4, 4, 2)
arrPoints[0, 0] := 100
arrPoints[0, 1] := 150
arrPoints[1, 0] := 240
arrPoints[1, 1] := 600
arrPoints[2, 0] := 370
arrPoints[2, 1] := 100
arrPoints[3, 0] := 500
arrPoints[3, 1] := 550
pbDoc.Pages(1).Shapes.AddCurve(arrPoints)           ; Draw a curve using the points specified by the array

; Shapes.AddTextbox Method (Publisher)
; http://msdn.microsoft.com/en-us/library/office/ff939294%28v=office.15%29.aspx
pbTextbox := pbDoc.Pages(1).Shapes.AddTextbox(pbTextOrientationHorizontal, 40, 60, 520, 65)  ; Create a textbox
; Story.TextRange Property (Publisher)
; http://msdn.microsoft.com/en-us/library/office/ff940334%28v=office.15%29.aspx
pbTextRange := pbTextbox.TextFrame.Story.TextRange  ; Store a reference to the range of text inside the textbox
pbTextRange.Text := "AutoHotkey is awesome!"
pbTextRange.Font.Bold := msoTrue
pbTextRange.Font.Size := 40
pbTextRange.Font.Name := "Arial"

; Page.SaveAsPicture Method (Publisher)
; http://msdn.microsoft.com/en-us/library/office/ff939984%28v=office.15%29.aspx
SavePath := A_ScriptDir "\MyTestFile.jpg"           ; Save the picture to the same directory as this script
pbDoc.Pages(1).SaveAsPicture(SavePath, pbPictureResolutionCommercialPrint_300dpi)

; Document.SaveAs Method (Publisher)
; http://msdn.microsoft.com/en-us/library/office/ff940221%28v=office.15%29.aspx
SavePath := A_ScriptDir "\MyTestDocument.pub"       ; Save the document to the same directory as this script
pbDoc.SaveAs(SavePath)
return
geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: COM Object Reference

07 Nov 2014, 08:32

Wouldn't this be better suited to a GitHub repository or something along those lines? Perhaps under the AhkScript group?
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: COM Object Reference

11 Jan 2015, 03:20

COM Object: Msxml2.XMLHTTP, a.k.a. XmlHttpRequest object.
Purpose: Making HTTP requests. Unlike UrlDownloadToFile, it doesn't require managing a temporary file. Unlike WinHttpRequest, it can notify us when the request is complete.
System Requirements: IE7+ and AutoHotkey v1.1.17+ to use onreadystatechange.
Documentation Link: XMLHttpRequest object
Basic Code Example:

Code: Select all

req := ComObjCreate("Msxml2.XMLHTTP")
; Open a request with async enabled.
req.open("GET", "https://autohotkey.com/download/1.1/version.txt", true)
; Set our callback function (v1.1.17+).
req.onreadystatechange := Func("Ready")
; Send the request.
req.send()
/*
; If you're going to wait, there's no need for onreadystatechange.
; Setting async=true and waiting like this allows the script to remain
; responsive while the download is taking place, whereas async=false
; will make the script unresponsive.
while req.readyState != 4
    sleep 100
*/
#Persistent

Ready() {
    global req
    if (req.readyState != 4)  ; Not done yet.
        return
    if (req.status == 200 || req.status == 304) ; OK.
        MsgBox % "Latest AutoHotkey version: " req.responseText
    else
        MsgBox 16,, % "Status " req.status
    ExitApp
}
I started looking into this because using WinHttpRequest in synchronous mode causes the script to hang until the request completes, but it turns out you can get around that by opening the request in asynchronous mode and calling WinHttpRequest.WaitForResponse(). The advantages of XMLHTTP are that the API is well known to many web developers, and the events (like onreadystatechange) are compatible with AutoHotkey.
Last edited by lexikos on 30 Oct 2016, 18:46, edited 1 time in total.
Reason: Update URL
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: COM Object Reference

11 Jan 2015, 13:15

Hello asynchronous downloads!
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: COM Object Reference

17 Jul 2015, 19:08

Any idea what the maximum size that can be stored in this? I read through some of the documentation however I was playing around and was storing a lot more characters than what I saw in the documentation.
sinkfaze wrote:COM Object: WScript.Shell
Purpose: Exchange variables between scripts
System Requirements: General
Documentation Link: WshEnvironment Object
Other Links: Environment Variables
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
User avatar
Joe Glines
Posts: 770
Joined: 30 Sep 2013, 20:49
Location: Dallas
Contact:

Re: COM Object Reference

18 Jul 2015, 11:09

Joetazz wrote:Any idea what the maximum size that can be stored in this? I read through some of the documentation however I was playing around and was storing a lot more characters than what I saw in the documentation.


I reached a max of 524,285 charchters on my 64 bit version of Windows 7
Sign-up for the 🅰️HK Newsletter

ImageImageImageImage:clap:
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey :ugeek:
YouTube

:thumbup: Quick Access Popup, the powerful Windows folders, apps and documents launcher!
guesto

Re: COM Object Reference

10 Apr 2016, 14:32

sinkfaze wrote:COM Object: ImageMagickObject COM+ Object
Purpose: ImageMagick® is a software suite to create, edit, and compose bitmap images.
System Requirements: ImageMagickObject COM+ Object
Documentation Link:
Other Links: http://www.imagemagick.org/script/binar ... hp#windows
Basic Code Example:
I have installed ImageMagick with the COM option in the installer (the checkbox about VBS something, don't remember exactly). I can run the ImageMagickObject .vbs test script that comes with ImageMagick. But I can't get it to work in AHK. The sample script generated "Invalid class string" error on this line

Code: Select all

oI :=	ComObjCreate("ImageMagickObject.MagickImage.1")
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: COM Object Reference

07 Mar 2019, 18:35

GeekDude wrote:
07 Nov 2014, 08:32
Wouldn't this be better suited to a GitHub repository or something along those lines? Perhaps under the AhkScript group?
I agree with GeekDude, looking through this resource (which I've seen a million times now) is great, however the format is not-so-great. Would be awesome if this was all in one post at very top of this thread (Initital Post) - I'm going to create my own resource that compiles all these COM objects. Is this the most "official" AHK-related resource for a COM Object Reference?? In other words, is there another place where I could go to grab similar information of COM Objects that can be controlled via AHK?? I see this resource above by kon (in spoiler below) - but is this the complete list, or are there others?

I'll post a link out to my resource once created so others can use / share / add to it.
kon wrote:
15 Jul 2014, 14:50
A remake of the index.
Index
-TL
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: COM Object Reference

09 Mar 2019, 08:14

This is one by Mickers on the old forums it has helped me in the last year and have bookmarked it. Dont know if you already knew about it.

https://autohotkey.com/board/topic/69033-basic-ahk-l-com-tutorial-for-excel/
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: COM Object Reference

26 Feb 2021, 18:14

Thanks for this @Tigerlily, means I can now link to one post to share it with people at work as we slowly get our heads around using COM.
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: COM Object Reference

26 Feb 2021, 22:37

COM Object: Outlook.Application
Purpose: Change view of current folder
System Requirements: MS Outlook (MS Office)
Documentation Link:
Other Links:
Basic Code Example: This example will change the current view to "Active" (must have a view called Active or it will fail).

Code: Select all


;-------------------------------------------------------------
;Active

OutlookActions_ViewActive() ;Navigate to OL Inbox via Navigation Menu / OL VBA Script
{
try objOL := ComObjActive("Outlook.Application")
catch e
{
   MsgBox Failed to get a handle to OL
   return
}
   
objNS := objOL.GetNamespace("MAPI")
CurrentFolderIs := objOl.ActiveExplorer.CurrentFolder.Name

try objFolder := CurrentFolderIs

catch e
{
   MsgBox Failed to find folder...
   return
}

objOl.ActiveExplorer.CurrentView := "Active"   ;show all active emails
}
return

;-------------------------------------------------------------

____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: COM Object Reference

27 Feb 2021, 16:16

@submeg

Always happy to help (:

Cheers,
tigerlilz
-TL

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble, TheNaviator and 135 guests