Cannot create multiple instances of PowerPoint
I'm working on a project where I need to use PowerPoint from C#.net. Initially, I always created one single instance. As of today, I would like to have multiple instance running. I do that like so:
Type powerpointType = Type.GetTypeFromProgID("PowerPoint.Application");
object instance1 = Activator.CreateInstance(powerpointType);
object instance2 = Activator.CreateInstance(powerpointType);
but when I ask for the handle of both instances, by calling
hwnd = (int)powerpointType.GetProperty("HWND").GetValue(instance1, null);
then I get the same handle twice. My conclusion is that the application is started just once, and the TaskManager comfirms that: Only one process.
How come there is only 开发者_开发问答one instance of PowerPoint running, and how can I make it work?
Instead of multiple instances, why not reference the multiple open presentations in the single instance?
When a user "Quits a column," you can just close that one presentation, but leave PPT open, unless it is the last open presentation.
This link discusses how to use a new user account to create multiple instances of PowerPoint. It works fine if you're always running it off the same computer, but isn't particularly easy to distribute.
PowerPoint as well as Word shares the same instance. Excel on the other hand lets you have multiple instances. In order to have two instances running you need to start up the other instance as a different user.
Why do you need multiple instances? In order to show two presentations on two monitors?
Based on your comment to Mikael, there is another solution. This is VBA, but easily portable to C#. Just open the presentation (hidden) and export each slide as a PNG. Then you can have those PNGs display in your column.
Dim ap As Presentation
Set ap = Presentations.Open(FileName:="yourppt.pptx", WithWindow:=msoFalse)
Dim s As Slide
For Each s In ap.Slides
s.Export s.Name, "PNG"
Next
Then, when someone clicks something, the first one can close and your new PPT can show.
For 2007 users save a ppt(x) as a pdf
At least pdf can be opened as separate instances
You can save back as .doc (my version of Acrobat Pro is 9.5.2); the .doc is OK but not perfect, but a least I can cut and paste between the .doc and the .ppt(x) :-)
BTW - Word 2007 does open each document as a separate instance, at least in my installation, the install being done by our IT folks.
精彩评论