LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bringing MS Word application to the front and detecting when it is closed

Using LV to open and work with MS applications is not a problem.  I can create a new document & save it.. edit it, insert pictures, sing a song, do just about anything..... except...  😞
 
I need to bring the Word application to the Front and keep it there until it (Word) is closed by an Operator.
Upon closing the LV application needs to detect that it is closed and trigger an event (more actions).
 
My questions are:
 
1.  How do you bring the MS Word to the Front and keep it there.  I'm using an Event Structure, and there are no events occurring after the document is completed...  However, about mid-way through the document, the Front Panel (VI) goes to the Front..  I have set FP.IsFrontMost to FALSE before / after editing the MS Word document... It just doesn't want to stay at the front.
 
2.  After the Operator looks at the report, he closes it.  Closing the report must trigger an event.   Is there an easier way than registering a User Event and then triggering on that?  If this is the way to go, I would need help with User Events...
 
 
Thanks,
 
RayR
0 Kudos
Message 1 of 19
(3,684 Views)
Doesn't setting the "Visible" property bring the app to the front? If not (wouldn't be too surprising given the reliability of MS apps), you can use the lvwutil functions to bring the window to the front.

As far as keeping it in the front, I'm not sure I understand. Are you saying you don't want the user to be able to change to another application like opening Notepad, or something?

The ActiveX interface for Word allows you to register a callback for the "Quit" event. However, I could not get this to work. Please refer to my earlier statement regarding the reliability of MS apps. I did, however, get it to work using .NET. Attached is an example that just displays a dialog when Word is quit. Note that you need to install the Primary Interop Assemblies to allow the interface between .NET and Office apps to work. See an example here. If you have Office 2003 all you need to do is re-run the installer, select "customized" options and select ".NET programmability" support (or something to that effect) for Word. See attached pic.
Message 2 of 19
(3,659 Views)
Thanks smercurio,
 
You are confirming the path that I was following.  Here are more details.

smercurio_fc wrote:
Doesn't setting the "Visible" property bring the app to the front? No... I placed it in two locations, and it didn't help..  Here is the scenario.  LV populates a blank ms word document.  The document is up-front until graphs are placed into the document.  Trying to bring the document up-front again has been an exercise in futility..
If not (wouldn't be too surprising given the reliability of MS apps),  Not surprising at all.  I'm impressed every time ms xp starts up in the morning.  I am converting to MACs.  I hope there will be many followers.. 😉  
you can use the lvwutil functions to bring the window to the front.  I will try that.  Alternatively, I may try minimizing the LV Front Panel until the application detects that word has been closed. 

As far as keeping it in the front, I'm not sure I understand. Are you saying you don't want the user to be able to change to another application like opening Notepad, or something?  Only word will be opened on the PC during the test.  So LV will be running, and word when a report is generated.  Opening (and monitoring) other applications is beyond the scope of this project..  at this time.. 🙂 

The ActiveX interface for Word allows you to register a callback for the "Quit" event.  Yes... This is where I got stuck.  I need to understand this application event a bit better.  I will swap my code with the one you rcreated and see if windoze or word is intelligent enough to trigger such an event.  I'm not a betting man, and I would never bet on anything that gate's boys will code..  The last ms product that impressed me was DOS 3.2.  Ok... Win-2000 was respectable.  I'll stop here.. 😄
 
However, I could not get this to work.  LOL!!  LOL!!  😄  no comments..  LOL!!  ***shaking my head while laughing***
Please refer to my earlier statement regarding the reliability of MS apps. LOL!!  LOL!!  😄  no comments..  LOL!!  ***shaking my head while laughing***
I did, however, get it to work using .NET. Aiye caramba!!!  Is it just me or is this getting complicated for such as a simple task??  I need a MonsterEnergy drink..  Not sure if they sell them in Canada.
 
Attached is an example that just displays a dialog when Word is quit. Thanks! It looks very much like what I was implementing, but didn't work..
Note that you need to install the Primary Interop Assemblies to allow the interface between .NET and Office apps to work. Maybe this is the problem.. I will need to check to see if the client can garantee that this will be installed on the target PC.  As I said, is this getting complicated for such as a simple task??  I will check to see if I installed it.  I have office 2000 installed on this PC.  I do have office 2003 {will switch to Open Office..  office 2007 is not compatible with earlier versions unless you download a patch for older versions.  So much for a standardized world!  You'd think that in 2007 Engineers would have some sense of standardization?  oh... I forgot... msuff doesn't really design anything... just hack and get people to buy more memory.  My bad.. 😞  Sorry to drift..  Probably remind you of Ben!!  LOL!!!  😄  LOL!!!!! LOL!!!  😄  I'm getting myself into trouble, aren't I?}
 
See an example here. If you have Office 2003 all you need to do is re-run the installer, select "customized" options and select ".NET programmability" support (or something to that effect) for Word. See attached pic. I can't remember if office 2000 had dot net back then.  Oh well..  I may just have to upgrade word..  --- sigh -- I hate installing newer versions over stuff that works..  Especially msuff products..    



There is an alternative to a all of the above..  That would be to create a pdf document and simply close word.  Then monitor the opened pdf display...  But that's another ball of wax.  😄
 
So, in order to use the "Quit" callback event, do I have to install the dot Net programmability (in the target app)?  I guess, the answer is "no", but if it doesn't work, not installing it does not help..  thus pushing the answer to "yes"...  -- sigh --
 
I will try a few things and report back.
 
RayR 
0 Kudos
Message 3 of 19
(3,636 Views)

 Here is a link to the C++ version (ActiveX) of what you proposed with dotNet.

I will review this to see if I missed anything.  Then try dotNet.

0 Kudos
Message 4 of 19
(3,633 Views)
There is a "WindowDeactivate" event that I will investigate..  🙂
 


Message Edited by JoeLabView on 01-23-2008 09:03 AM
0 Kudos
Message 5 of 19
(3,629 Views)
Hmm, just a thought without coding. Maybe you can insert Word in an ActiveX Container on a LV FP. Then all you need to check for the LV FP to be closed...

Felix
Message 6 of 19
(3,627 Views)
Unfortunately, Office 2000 didn't have "official" Primary Interop Assemblies. You could roll your own, but that's way out there.

The idea of using an ActiveX container is an intriguing one, and it might actually work. Excellent suggestion.
Message 7 of 19
(3,611 Views)
Update: Well, I found out why I wasn't able to get the callback to work. Even though I was quitting out of Word, I had Outlook open, and it's set up to use Word as the editor. So, even though I had quit out of the Word process that LabVIEW had started, I didn't actually "quit" out of Word. I recoded the example to use ActiveX, and as long as I didn't have Outlook running, the LabVIEW callback displayed the dialog when Word quit. Attached are the VIs using ActiveX. Note that the dialog box is displayed when you click the close box, so Word is waiting for the LabVIEW dialog to be dismissed before finally quitting.
Download All
Message 8 of 19
(3,608 Views)
 
 
WHAT!!???!!!
 
yes.. I understand.. but what!!!??? 
 
Now what kind of  (stupid) microbe programming is that??  <<referring to microsuff of course>> Like I said... I understand... but closing Word should trigger that event regardless of outlook..
They must have happy smoke inside those windoze!!
 
Sorry... I just had to rant..  a little...
 
Thanks for finding that one.  I never made the association.  I will try it.. Many thanks...
 
I will try with & without outlook opened.  ... and report back..  --- sigh ---
 
Just thinking aloud..  Maybe an html document would be a solution...  maybe..  just thinking aloud..  I'm sure they implemented some crazy stuff with the browser... maybe..  😉


Message Edited by JoeLabView on 01-23-2008 12:26 PM
0 Kudos
Message 9 of 19
(3,606 Views)

Thanks guys..

I think this will work.  Even with outlook active as long as ms word is not the editor..

Will let you know how it goes.

RayR



Message Edited by JoeLabView on 01-23-2008 01:29 PM
0 Kudos
Message 10 of 19
(3,597 Views)