Ppt_Get (like Excel_Get or Word_Get)

Post your working scripts, libraries and tools
burque505
Posts: 691
Joined: 22 Jan 2017, 19:37

Ppt_Get (like Excel_Get or Word_Get)

18 Mar 2018, 17:50

Hi all, on the heels of Word_Get.ahk a similar function for Powerpoint. Please test, break, mangle, report :D
Thanks!

Ppt_Get.ahk
Spoiler
Here's an example script.

Code: Select all

#Include Ppt_Get.ahk

F7::  ; Press F7 to display Powerpoint's caption.
    pptApp := Ppt_Get()
    if !IsObject(pptApp)  ; If Ppt_Get fails it returns an error message instead of an object.
    {
        MsgBox, 16, Ppt_Get Error, % pptApp
        return
    }
    MsgBox, % "Caption: " pptApp.Caption
return
EDIT March 23, 2018: I'm posting jeeswg's code for this, which works on multiple versions. I've tested it on 64-bit PowerPoint 2013 & 2016, jeeswg tested it on PP 2007. Should work in 2010 without problems, but I haven't tested it yet. You'll probably want to change the function name in the example code above from PPT_Get() to PowerPoint_Get() when using jeeswg's code, or else change PowerPoint_Get to PPT_Get in jeeswg's code.

Code: Select all

;tested on PowerPoint 2007
PowerPoint_Get(vWinTitle:="ahk_class PP..?FrameClass", vNum:=1)
{
	static h := DllCall("kernel32\LoadLibrary", Str,"oleacc", Ptr)
	vTMM := A_TitleMatchMode
	if (vWinTitle = "ahk_class PP..?FrameClass")
		SetTitleMatchMode, RegEx
	hWnd := WinExist(vWinTitle)
	WinGetClass, vWinClass, % "ahk_id " hWnd
	SetTitleMatchMode, % vTMM
	if !(vWinClass ~= "PP..?FrameClass")
		return "Window class mismatch."
	ControlGet, hCtl, Hwnd,, % (vCtlClass := "mdiClass") vNum, % "ahk_id " hWnd
	if !hCtl
		ControlGet, hCtl, Hwnd,, % (vCtlClass := "paneClassDC") vNum, % "ahk_id " hWnd
	if ErrorLevel
		return "Error accessing the control hWnd."
	VarSetCapacity(IID_IDispatch, 16)
	NumPut(0x46000000000000C0, NumPut(0x0000000000020400, IID_IDispatch, "Int64"), "Int64")
	if !(DllCall("oleacc\AccessibleObjectFromWindow", Ptr,hCtl, UInt,-16, Ptr,&IID_IDispatch, PtrP,pAcc) = 0)
		return "Error calling AccessibleObjectFromWindow."
	oWin := ComObject(9, pAcc, 1)
	if !(ComObjType(oWin) = 9)
		return "Error wrapping the window object."
	Loop
		try return oWin.Application
		catch e
	if (SubStr(e.message, 1, 10) = "0x80010001")
		ControlSend, % vCtlClass vNum, {Esc}, % vWinTitle
	else
		return "Error accessing the application object."
}

Works on my Win7 64-bit system, AHK 1.1.28.00 64-bit
Regards,
burque505
Last edited by burque505 on 23 Mar 2018, 16:52, edited 1 time in total.
clina1j
Posts: 49
Joined: 22 Apr 2016, 18:39

Re: Ppt_Get (like Excel_Get or Word_Get)

22 Mar 2018, 13:32

Alright, so I gave it a try. It looked very promising and Excel_Get, and Word_Get work just fine. But Ppt_Get is giving the following error message
PPTGet Error.png
PPTGet Error.png (8.77 KiB) Viewed 573 times
I am using Windows 7, and Office 2010 on a 64 bit computer. And my company handles people healthcare information, so the security is PARANOID.
Any ideas?

PS, I just tripple check that Excel_Get and Word_Get work on my computer. I pasted the code for all three into a new script, and ran the example Caption script for all three programs, with brand new empty documents open up for each. I got the Captions for Word and Excel, and the same error message for PowerPoint.
burque505
Posts: 691
Joined: 22 Jan 2017, 19:37

Re: Ppt_Get (like Excel_Get or Word_Get)

22 Mar 2018, 18:36

For those using Office 2010, this will choke (thanks clina1j). PowerPoint 2010 uses a "paneClassDC" control, and 2013 - 2016 use "mdiClass". For those who have 2010, try the code by awel20 in this thread. I've only tested it on XP in a VM, but it works fine.
Regards,
burque505
User avatar
jeeswg
Posts: 5447
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Ppt_Get (like Excel_Get or Word_Get)

22 Mar 2018, 19:07

You can incorporate code like this to handle window and control class variants.

Code: Select all

q:: ;get PowerPoint window class and control hWnd
vTMM := A_TitleMatchMode
SetTitleMatchMode, RegEx
WinGet, hWnd, ID, % "ahk_class PP..?FrameClass"
WinGetClass, vWinClass, % "ahk_id " hWnd
SetTitleMatchMode, % vTMM

vNum := 1
ControlGet, hCtl, Hwnd,, % "mdiClass" vNum, % "ahk_id " hWnd
if !hCtl
	ControlGet, hCtl, Hwnd,, % "paneClassDC" vNum, % "ahk_id " hWnd
MsgBox, % vWinClass "`r`n" hCtl
return
burque505
Posts: 691
Joined: 22 Jan 2017, 19:37

Re: Ppt_Get (like Excel_Get or Word_Get)

22 Mar 2018, 19:17

That code definitely works, jeeswg, thanks. Let me experiment with plugging it into the original function.
Regards,
burque505
User avatar
jeeswg
Posts: 5447
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Ppt_Get (like Excel_Get or Word_Get)

22 Mar 2018, 20:06

I've updated my original function to incorporate the ideas above. You're welcome to use any code from it in your function. If you are able to test my function, that would be great. Cheers.

Excel_Get is AMAZING, could someone make a PowerPoint_Get? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 45#p207745
burque505
Posts: 691
Joined: 22 Jan 2017, 19:37

Re: Ppt_Get (like Excel_Get or Word_Get)

23 Mar 2018, 16:42

Thanks, jeeswg. I'm going to put your code in the OP.
Regards,
burque505
sixtyone
Posts: 3
Joined: 30 Jun 2018, 00:59

Re: Ppt_Get (like Excel_Get or Word_Get)

30 Jun 2018, 01:07

could someone make a AutoCAD_Get?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: hasantr, Spikea and 28 guests