Ppt_Get (like Excel_Get or Word_Get)
Posted: 18 Mar 2018, 17:50
Hi all, on the heels of Word_Get.ahk a similar function for Powerpoint. Please test, break, mangle, report
Thanks!
Ppt_Get.ahk
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.
Works on my Win7 64-bit system, AHK 1.1.28.00 64-bit
Regards,
burque505
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
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