Embed MS Office document in GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Embed MS Office document in GUI

12 Feb 2017, 16:29

Hi, I'd like to embed Office documents in a GUI.

I found this code at:

https://autohotkey.com/board/topic/2915 ... anks-sean/
and
https://autohotkey.com/board/topic/2915 ... ntry186621

I'm using AutoHotkey_L, and the COM commands below throw errors.
I thought about downloading COM_L, but all the links are broken (including in the broken links reporting page) and it probably won't work anyway since COM is now built in.
I downloaded the old com.ahk lib and it didn't work, and I didn't really expect it to.

Can anyone point me in the right direction? Thanks!


GoSub, GuiOpen
pweb := COM_AtlAxCreateControl(WinExist(), A_Temp . "\test.xls")
pxlb := COM_Invoke(pweb, "Document") ; Excel Workbook
pxls := COM_Invoke(pxlb, "Worksheets", 1) ; Excel Worksheet
Return

GuiOpen:
Gui, +Resize +LastFound
Gui, Show, w800 h600 Center, Excel
COM_AtlAxWinInit()
Return
GuiClose:
Gui, Destroy
COM_Invoke(pxlb, "Save")
COM_Release(pxls)
COM_Release(pxlb)
COM_Release(pweb)
COM_AtlAxWinTerm()
ExitApp
;
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Embed MS Office document in GUI  Topic is solved

13 Feb 2017, 08:32

You can use dsoframer.ocx

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

EnsureRegistered()

Gui, Add, ActiveX, w800 h600 vfc, DSOFramer.FramerControl
Gui, Show

fc.Menubar := false
fc.Toolbars := false
fc.Titlebar := false

; fc.Open(A_ScriptDir "\test.xlsx")
fc.CreateNew("Excel.Sheet")

fc.ActiveDocument.Sheets(1).Range("A1").Value := "test"
return

GuiClose:
ExitApp

EnsureRegistered() {
	try {
		ComObjCreate("DSOFramer.FramerControl")
	} catch {
		RunAsAdmin()
		RunWait, regsvr32 /s dsoframer.ocx, %A_ScriptDir%
	}
}

RunAsAdmin() {
	full_command_line := DllCall("GetCommandLine", "str")

	if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
	{
	    try
	    {
	        if A_IsCompiled
	            Run *RunAs "%A_ScriptFullPath%" /restart
	        else
	            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
	    }
	    ExitApp
	}
}
DSOFramer functions
:arrow: Download
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Embed MS Office document in GUI

13 Feb 2017, 08:53

thank you , tmplinshi
this for PDF-file / or also for MP4

Code: Select all

;_ ActiveX PDFx
xxa=Shell.Explorer                  ;- IExplorer
;xxa=Mozilla.Browser                ;- firefox no success
F1=C:\test.pdf
stringreplace,f1,f1,\,/,all
F2:="file:///" . F1
Gui Add, ActiveX, w980 h750 vWB1,%xxa%
WB1.Navigate(F2)
Gui, Show,x0 y0 w1024 h768, TEST-PDF
return

Guiclose:
exitapp
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Embed MS Office document in GUI

13 Feb 2017, 12:30

Thanks to both. No joy yet. Tmplinshi, when I run your code everything that is "fc.*" throws an error.
I already have dsoframer.ocx registered on my system from another program, but tried re-registering it also (though EnsureRegistered() didn't throw an exception).
When I refresh the webpage that displays, I get this message: "Make sure the web address http://dsoframer.framercontrol is correct".
I do feel the code is close to working, though.
I have test.xlsx in the script dir, of course.

Garry, thank you, I'm having trouble with that one too, of a different nature: the PDF downloads with a dialog box (Open or Save), both of which work but neither of which show the pdf in the GUI. Save calls up the file dialog, and Open just opens it in Acrobat.

Thanks again, I look forward to more input.
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Embed MS Office document in GUI

13 Feb 2017, 13:14

@burque505 , I have the same problem with PDF when I use Mozilla.Browser , Shell.Explorer works for me , maybe see settings in browser for extensions
tmplinshi's script works for me , but I use Open-Office and Microsoft-Office asks me for Product Key ... I can refuse , then with restricted functions ( I want only read )
Last edited by garry on 13 Feb 2017, 14:35, edited 1 time in total.
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Embed MS Office document in GUI

13 Feb 2017, 14:06

Thanks, Garry. I wonder what I'm doing wrong with tmplinishi's script? I just copied and pasted it.
Maybe my version of dosframer.ocx doesn't work with AHK, but it works fine with the application it came with. I'll look for a 64-bit version (my OS is 64-bit) and see if maybe that's the problem.
I appreciate your input.
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Embed MS Office document in GUI

13 Feb 2017, 14:10

Just found a reference on the web saying dsoframer.ocx doesn't support Office 2010. I'm using Office 2016, maybe that's the problem.
:crazy: Or not. I downloaded and installed the official sample pack, and the samples work fine. I also copied that dsoframer.ocx over to the script directory, still no luck.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Embed MS Office document in GUI

14 Feb 2017, 00:31

My environment:
  • AutoHotkey v1.1.24.05 Unicode 32-bit
  • Office 2016
  • Windows 64-bit
Doesn't work on 64-bit AHK.

Try add following code to the top of the script.

Code: Select all

If (A_PtrSize = 8) {
	MsgBox, 48,, Please use 32-bit AutoHotkey
	ExitApp
}
RunAsAdmin()
RunWait, regsvr32 /s dsoframer.ocx, %A_ScriptDir%
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Embed MS Office document in GUI

14 Feb 2017, 01:39

Here is a way to Registration-Free by using manifest file.

dsoframer.manifest:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><file name="dsoframer.ocx" hashalg="SHA1"><comClass clsid="{00460182-9E5E-11D5-B7C8-B8269041DD57}" tlbid="{00460180-9E5E-11D5-B7C8-B8269041DD57}" description="DSO Framer Control Object"></comClass><typelib tlbid="{00460180-9E5E-11D5-B7C8-B8269041DD57}" resourceid="1" version="2.2" helpdir=""></typelib></file><comInterfaceExternalProxyStub name="_FramerControl" iid="{00460181-9E5E-11D5-B7C8-B8269041DD57}" tlbid="{00460180-9E5E-11D5-B7C8-B8269041DD57}" proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"></comInterfaceExternalProxyStub></assembly>

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

If (A_PtrSize = 8) {
	MsgBox, 48,, Please use 32-bit AutoHotkey
	ExitApp
}

RegCOM("dsoframer.manifest")

Gui, Add, ActiveX, w800 h600 vfc, {00460182-9E5E-11D5-B7C8-B8269041DD57}
Gui, Show

fc.Menubar := false
fc.Toolbars := false
fc.Titlebar := false

; fc.Open(A_ScriptDir "\test.xlsx")
fc.CreateNew("Excel.Sheet")

fc.ActiveDocument.Sheets(1).Range("A1").Value := "test"
return

GuiClose:
ExitApp

RegCOM(ManifestFile) {
	VarSetCapacity(actctx, 34, 0)
	NumPut(34, actctx, 0, "UInt")
	NumPut(&ManifestFile, actctx, 8, "UInt")

	hActCtx := DllCall("CreateActCtx", "ptr", &actctx, "ptr")
	if (hActCtx = INVALID_HANDLE_VALUE := -1) {
		throw, "INVALID_HANDLE_VALUE"
	}

	DllCall("ActivateActCtx", "ptr", hActCtx, "ptr*", cookie)
}
:arrow: Download
Last edited by tmplinshi on 04 Apr 2017, 02:52, edited 1 time in total.
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Embed MS Office document in GUI

14 Feb 2017, 13:12

:bravo: :dance: tmplinshi, you are the greatest!
It was in fact me running a 64-bit AHK. The 32-bit version I swapped in runs both versions you provided perfectly.
Fantastic. Wonderful. And thanks for working .ocx, of course.
Regards and the highest of praise,
Burque505.
hughman
Posts: 18
Joined: 17 Jun 2014, 09:39

Re: Embed MS Office document in GUI

16 Aug 2018, 02:52

tmplinshi wrote:Here is a way to Registration-Free by using manifest file.
Excuse me, this verison doesn't work for me. My environment is winXP sp3 chs, ahk_l u32.
It seems that the classid and progid still can't be recognized by ahk.
The activex control in the GUI becomes IE ( maybe dsoframer is based on IE?)
What's wrong? Can u help me?
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Embed MS Office document in GUI

16 Aug 2018, 03:17

@hughman Are you using the lastest version of AHK? If not try updating first.
hughman wrote:The activex control in the GUI becomes IE ( maybe dsoframer is based on IE?)
No, any invalid components name will become "IE". e.g. : Gui, Add, ActiveX, w300 h300, test
hughman
Posts: 18
Joined: 17 Jun 2014, 09:39

Re: Embed MS Office document in GUI

17 Aug 2018, 23:27

tmplinshi wrote:@hughman Are you using the lastest version of AHK? If not try updating first
I get it. if ahk is located in another computer of LAN, it failed.But the local ahk can make it run. Is it posdible to be solved?
btw: Do you have a solution for x64 system? the dsoframer seems too old.
at last, thanks for you good idea and help.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Embed MS Office document in GUI

18 Aug 2018, 10:35

hughman wrote:btw: Do you have a solution for x64 system? the dsoframer seems too old.
You can use 32-bit AHK on x64 system.

To use dsoframer on 64-bit AHK, you will need 64-bit version of dsoframer.ocx, but such version doesn't exist on the internet.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Nerafius, RandomBoy and 188 guests