Jump to content

AutoIt3's future: Embedded ActiveX !


SvenP
 Share

Recommended Posts

Sven, what I've read indicates to me that embedding a Word control is hard to do, even in VB. I've not been able to find any code that shows how to do it. The closest I get every time demonstrates embedding a Word control in an Internet Explorer object (But on my system, that has a prompt about running an ActiveX control or some other irritating prompt). I'm curious as to whether or not you've found any code (in any language) demonstrating how to embed a Word control in a GUI. Alternatively, if anybody knows how to avoid getting the prompt from IE when trying to access a Word document from inside an embedded instance of IE, I would be satisfied with that method as well for embedding Word.

Link to comment
Share on other sites

  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Sven, what I've read indicates to me that embedding a Word control is hard to do, even in VB.  I've not been able to find any code that shows how to do it.  The closest I get every time demonstrates embedding a Word control in an Internet Explorer object (But on my system, that has a prompt  about running an ActiveX control or some other irritating prompt).  I'm curious as to whether or not you've found any code (in any language) demonstrating how to embed a Word control in a GUI.  Alternatively, if anybody knows how to avoid getting the prompt from IE when trying to access a Word document from inside an embedded instance of IE, I would be satisfied with that method as well for embedding Word.

<{POST_SNAPBACK}>

Valik,

Word is indeed a nasty bitch. For instance, it does not like the IOleDocumentSite interface, while other controls (like Excel and Forms 2.0) require this interface for in-place activation.

If I temporarily disable that interface in the source code, you could make a script that produces this:

#include <GUIConstants.au3>

$oWord=ObjCreate("Word.Document")

$oWord.activate

GUICreate ( "Embedded ActiveX Test", 800, 600, (@DesktopWidth-800)/2, (@DesktopHeight-600)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE  + $WS_CLIPCHILDREN )

$GUI_ActiveX=GUICtrlCreateObj ( $oWord, 30, 30 , 750 , 550 )

GUISetState ()   ;Show GUI

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

GUIDelete ()

However, it is not the solution. Using the script above, you have no control over the Word-Object, since the Word-Object is created internally in GUICtrlCreateObj().

I tried to patch GUICtrlRead() to retrieve an interface to the newly created Word object, but GUICtrlRead() can only return strings.

What I try to figure out is why Excel accepts in-place activation and Word doesn't WITHOUT using the API function OleCreate() or OleCreateFromFile().

Regards,

-Sven

EDIT: Edited the example, because other users thought that it was a working example.

Edited by SvenP
Link to comment
Share on other sites

Thats a bit confusing. You would think that if Word didn't like the interface and that removing it completely allowed it to work, then Word would do the COM thing and... you know, just not use the interface. Does Word maybe have an issue with the implementation of the interface? Have you tried writing some trace messages just to see what methods Word is calling on the interface to maybe see where/why it is having an issue? Also, are you implementing each interface as its own distinct class or multiply inheriting from several interfaces to implement a class? This might cause some weird oddities since COM objects are a different beast than "true" objects.

My main suggestion would be to add some debugging traces to see which methods Word calls and then invert the return values for those functions just to see if you can get Word to work and/or produce a useful error.

What are the interfaces a Word object needs implemented? And does it take anything more than just a basic, bare-bones return E_NOTIMPL/S_OK for most of those? I'd like to modify my DLL sometime to see about getting it working with Word just as an experiment.

Link to comment
Share on other sites

Thats a bit confusing.  You would think that if Word didn't like the interface and that removing it completely allowed it to work, then Word would do the COM thing and... you know, just not use the interface.  Does Word maybe have an issue with the implementation of the interface?  Have you tried writing some trace messages just to see what methods Word is calling on the interface to maybe see where/why it is having an issue?  Also, are you implementing each interface as its own distinct class or multiply inheriting from several interfaces to implement a class?  This might cause some weird oddities since COM objects are a different beast than "true" objects.

My main suggestion would be to add some debugging traces to see which methods Word calls and then invert the return values for those functions just to see if you can get Word to work and/or produce a useful error.

What are the interfaces a Word object needs implemented?  And does it take anything more than just a basic, bare-bones return E_NOTIMPL/S_OK for most of those?  I'd like to modify my DLL sometime to see about getting it working with Word just as an experiment.

<{POST_SNAPBACK}>

Valik,

I've continued this part of the discussion in the other forum.

Regards,

-Sven

Link to comment
Share on other sites

I ran SvenP's code right quick, and it works for the most part, however, (at least with Word 2003) the buttons only appear once I roll over the buttons with my mouse, and the main section does not appear at all

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

I ran SvenP's code right quick, and it works for the most part, however, (at least with Word 2003) the buttons only appear once I roll over the buttons with my mouse, and the main section does not appear at all

<{POST_SNAPBACK}>

Just updated to .54, and now autoit has a fatal error when trying to create the GuiObj.

guiobj_svenp.au3

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

Just updated to .54, and now autoit has a fatal error when trying to create the GuiObj.

<{POST_SNAPBACK}>

MSLx Fanboy,

The format GUICtrlCreateObj("string",..) was just a quick test for Word.

I have removed that syntax after I have discovered what I have done wrong.

Try the 'new' Word example file in the beta .ZIP file (directory: tests\ActiveX).

Regards,

-Sven

Link to comment
Share on other sites

Hi!

With the code of Sven, it's OK for me :

#include <GUIConstants.au3>
GUICreate ( "Embedded ActiveX Test", 800, 600, (@DesktopWidth-800)/2, (@DesktopHeight-600)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE  + $WS_CLIPCHILDREN )

$GUI_BT = GuiCtrlCreateButton   ("Terminer",     10, 550, 100,  30)

$oWord=ObjCreate("Word.Document")
$oWord.activate

$GUI_ActiveX=GUICtrlCreateObj ( $oWord, 30, 30 , 750 , 500 )

GUISetState ()  ;Show GUI

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $GUI_BT Then ExitLoop
Wend

GUIDelete ()
Link to comment
Share on other sites

Hi!

With the code of Sven, it's OK for me :

....

<{POST_SNAPBACK}>

Thanks for testing Michel,

For those who want to experiment with GUICtrlCreateObj: Keep in mind that not all OLE functions have been implemented. It behaves different from embedded Objects in 'regular' applications:

-The object is always activated. So clicking in/out of the object doesn't do anything.

-You can't resize the object using the mouse. Neither will the object resize when resizing the main window. Use GUICtrlSetPos instead.

-Some objects refuse to accept the given size and use their own (like mediaplayer).

-If the object has menus: they will NOT be integrated with the AutoIt GUI menu.

-Window styles, GUICtrlRead and GUICtrlGetState have no effect on objects. Use 'methods' or 'properties' on the Object instead.

I have NOT tested yet:

- Multiple objects inside one GUI.

- Drag-and-drop.

- Other GUICtrl functions like GUICtrlSendMsg, GUICtrlSetState, GUICtrlSetResizing, etc.

So their behaviour is unknown yet.

Regards,

-Sven

Link to comment
Share on other sites

XWord recieves a COM error and exits out.

XWord2 recieves a COM error, however, it displays GUI and ActiveX control anyways, and works (atleast it accepts text)...

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

XWord recieves a COM error and exits out.

XWord2 recieves a COM error, however, it displays GUI and ActiveX control anyways, and works (atleast it accepts text)...

<{POST_SNAPBACK}>

XWord2 ? There's no such file in AutoIt3.1.1.54.zip.

Are you sure you are using the latest version? Because there had been an old file called TestXWord2.au3, which is obsolete.

Regards,

-Sven

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...