Jump to content
Mark Williams

Controlling MS Word Window from Delphi form

Recommended Posts

I create an instance of Word using TWordApplication:

WordApp := TWordApplication.Create(frmWord);
WordApp.ConnectKind := ckNewInstance;

The Word app is owned by my form. TFrmWord is basically just a form with a toolbar, which is designed to sit above the Word app. FrmWord needs:

  • to be visible when the Word app it has created is visible.
  • minimize when the Word app is minimized.
  • Move when the Word app is moved.
  • Resize when the Word app is resized

 

And vice versa for the Word app (ie any movement, resizing, minmimizing etc needs to be relected back to my form).

 

Basically, I am trying to get this to work as if my form and the Word instance are one form. Before anyone suggests, I have tried OLEContainers. They are, of course, buggy, but there are other problems:

  • It is problematic with the Word ribbon when more than one container's open.
  • It has horrific refresh problems when the OLEContainer is moved on to a second monitor.
  • If the user opens a word side panel (eg search or help) and then closes it the Word object does not refresh with the result that there is blank space where the panel used to be and detecting this and trying to refresh is difficult.
  • There were a number of other problems, which I can't remember now, but so many as I gave up the ghost.

 

So I worked with SetWindowPos and timer's instead. It took weeks of trial and error to do what I want it to do and in the end I had it working reasonably well. However, it seems that in a recent Windows update the way SetWindowPos works has changed. Apparently, MS has decided to place further restrictions on one app trying to pop itself on top of another active app. I can understand why, but it has caused problems for the way I have tried to marry up my form and the Word app. Before I spend weeks more time trying to figure out how now to do this, I thought it was worth a post to see if anyone can think of a simpler way of achieving this.

Share this post


Link to post

I wouldn't feel very confident about my chances of making this design work. Personally I'd be looking for a different solution. 

Share this post


Link to post

Completely agree with @David Heffernan here. From what I imagine your app is like, you would have easier (and more user friendly) results looking into writing a Word plugin instead.

  • Like 1

Share this post


Link to post
10 hours ago, aehimself said:

Completely agree with @David Heffernan here. From what I imagine your app is like, you would have easier (and more user friendly) results looking into writing a Word plugin instead. 

I don't have any experience with Office plugins. I thought about it at the time and it looked difficult and I seem to remember there were certain things I thought I would be unable to do using a plugin. I considered having a look at Add-in Express, but I'm keen to avoid reliance on third party tools as far as possible. I think I'll have a look at it and see if it can do what I want.

 

Share this post


Link to post
Guest

I used Add-in Express a long time ago. My experience (way back, be advised) was not 100% especially regarding licensing. I would like to remember that i got the tasks done. But i have since tried not to rely on Office installations as they change rapidly. For example, i had some plug-in to Outlook in order to enable users to send personal mail of any design for multiple recipients. Before the plugin i had a solution where you would pick up a draft from outlook (locally) and my application would "simply" put the recipients name and send a copy of that mail. Then users complained, it was not "intuitive" to have to mail some stuff from one application and other stuff from another (mine). So plugins. I do not remember the specific trials and tribulations, but i ended up writing a service that speaks to Exchange through EWS* each hour so now users have pertinent addresses and mailing lists continuously updated in their Exchange-Outlook solution. Imagine my relief when the client, not too long after that solution was implemented, told me they would start using the outlook web-version (and later Office365).

 

I know you task is completely different, i'm just mumbling about a similar experience with the hope that it helps.

 

Regards and good luck

 

* AtoZ CrossTalk is used on the server - but that is just because Delphi could back then not handle the intricacies of the EWS protocol.

 

/D

Share this post


Link to post
3 hours ago, Mark Williams said:

I don't have any experience with Office plugins. I thought about it at the time and it looked difficult and I seem to remember there were certain things I thought I would be unable to do using a plugin. I considered having a look at Add-in Express, but I'm keen to avoid reliance on third party tools as far as possible. I think I'll have a look at it and see if it can do what I want.

 

AddIn express is superb

Share this post


Link to post
Guest
4 hours ago, David Heffernan said:

AddIn express is superb

That is very good to know, thank you David. I have a feeling that i will be asked or will identify the need for Office-plugins in the foreseeable future.

I am very interested about stable solutions and experiences in the whole "technology". I will start another more pertinent thread when, and if, i get the time to look more closely.

Share this post


Link to post

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

×