473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Automating the close of an individual MS Word window

We have a requirement to initiate more than one instance of an
application using the filenames. (the example below will start two
instances of MS Word).

The problem is that we need to close each word document individually,
but this does not appear possible using the Process object. When I
run the example below the process object "p" can be viewed using Quick
Watch however process object p2 is displayed as undefined. This
appears to be because the second word document is opened under the
same Word process as the first word document. So when p.kill() is
called it kills off both word documents (not what we want).

-Code----------------------------------------------
ProcessStartInfo startInfo = new ProcessStartInfo("a.doc");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process p = Process.Start(startInfo);
.....
ProcessStartInfo startInfo2 = new ProcessStartInfo("b.doc");
startInfo2.WindowStyle = ProcessWindowStyle.Minimized;
Process p2 = Process.Start(startInfo2);
...
p.Kill();
...
p2.Kill();
-End Code----------------------------------------------

This works ok when I try it with text files since windows opens two
instances of notepad.

I have a way around it using the InteropServices (User32.dll) to find
the window handles and then issuing a windows message i.e.

int iHandle1 = FindWindow("OpusApp", "a.doc - Microsoft Word");
int iHandle2 = FindWindow("OpusApp", "b.doc - Microsoft Word");
int ret1 = SendMessage(iHandle1, WM_CLOSE, 0x00000000, 0x00000000);
int ret2 = SendMessage(iHandle2, WM_CLOSE, 0x00000000, 0x00000000);

However this has at least two drawbacks.
1. Have to use the 32 bit windows api calls via InteropServices (not
ideal)
2. For the FindWindow call we have to cater specifically for word
documents by passing the class name ("OpusApp") and the additional
text " - Microsoft Word" in the title of the window.

Has anyone come across this issue before or do you have any
suggestions.

Regards
Gavin
Nov 17 '05 #1
0 1608

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web...
4
by: moose | last post by:
OK Popup window? No problem PDF in popup? No problem But what about a couple of Close Window buttons? Imagine a "Close Window" button at the top of the popup page. Then the PDF which can...
9
by: ScooterMX | last post by:
I have a <a href="javascript:top.window.close()"><img src="exit.gif"></a> tag on my page that closes itself when you click on it. What I NEED is for it to put up a confirmation message that...
18
by: Roger Withnell | last post by:
I open a new window from the current window to display maps. Several maps of different sizes can be displayed. The function is given the size of the map and adjusts the window size accordingly....
7
by: xzzy | last post by:
I need to automate a report in a different database (and thank yous to Terry Kreft for pointing me in the right direction). below is the code with the one line that does not work, marked: 'Does...
1
by: John Davy | last post by:
I am trying to set up a mail merge by automation using a text file as the data source but I keep getting the message "Requested object is not available" and the debugger stops on the...
10
by: mc | last post by:
I've know that Microsoft don't currently recommend this process, what I'm trying to find out is why? This is a feature that I've used (with Classic ASP) in the past with a great deal of success....
37
by: Jan Tovgaard | last post by:
Hey everyone:) We have a critical problem, which I can see that other people also has ran into. In Internet Explorer 7 it is no longer possible to do a window.close after opening a window,...
2
by: chutney | last post by:
Dear all, please excuse the fact that this is not an explicit problem I have, but more of a general query. I have an Access database (2003) with a load of contact details in it. Including various...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.