本文介绍了在C#中获取Powerpoint的运行实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Win XP中使用C#自动执行Powerpoint的特定正在运行的实例.

请提供必要的帮助.
下面的代码在逐行运行调试时工作正常,但在没有调试的情况下不工作
TmrPPTAppClsMon.Stop();
bool blnTmrStts = TmrPPTAppClsMon.Enabled;
//pptApp = null;

pptApp = null;

Thread.Sleep(1000);


试试
{

//这意味着该对象已经被分配了一个值
if(iPPTPrcID!= -1){返回; }

Process [] prcArrPPT = Process.GetProcessesByName("POWERPNT");
//等到PPT应用程序启动
while(Process.GetProcessesByName("POWERPNT").Length!= 1){Thread.Sleep(500); }

对象obj = null;

obj = System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPoint.Application");


pptApp =(PowerPoint.Application)obj;


GetWindowThreadProcessId(pptApp.HWND,出iPPTPrcID);
pptApp.PresentationOpen + =新的Microsoft.Office.Interop.PowerPoint.
EApplication_PresentationOpenEventHandler(Presentation_Open);

pptApp.SlideSelectionChanged + =新的Microsoft.Office.Interop.PowerPoint.
EApplication_SlideSelectionChangedEventHandler(SlideSelection_Changed);

pptApp.PresentationClose + =新的Microsoft.Office.Interop.PowerPoint.
EApplication_PresentationCloseEventHandler(Presentation_Close);

pptApp.PresentationSave + =新的Microsoft.Office.Interop.PowerPoint.
EApplication_PresentationSaveEventHandler(Presentation_Open);

foreach(pptApp.Presentations中的PowerPoint.Presentation PrstnItm)
{
while(Process.GetProcessesByName("POWERPNT").Length!= 1){Thread.Sleep(500); }
Presentation_Open(PrstnItm);
}






}

Automating a specific running instance of Powerpoint using C# in Win XP.

Kindly do the needful help.
Below code working fimne when run debug line by line .but without debug it is not working
TmrPPTAppClsMon.Stop();
bool blnTmrStts = TmrPPTAppClsMon.Enabled;
//pptApp = null;

pptApp = null;

Thread.Sleep(1000);


try
{

//It means that the object is already assigned a value
if (iPPTPrcID != -1) { return; }

Process[] prcArrPPT = Process.GetProcessesByName("POWERPNT");
//Wait till the PPT Application initiates
while (Process.GetProcessesByName("POWERPNT").Length != 1) { Thread.Sleep(500); }

Object obj = null;

obj = System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPoint.Application");


pptApp = (PowerPoint.Application)obj;


GetWindowThreadProcessId(pptApp.HWND, out iPPTPrcID);
pptApp.PresentationOpen += new Microsoft.Office.Interop.PowerPoint.
EApplication_PresentationOpenEventHandler(Presentation_Open);

pptApp.SlideSelectionChanged += new Microsoft.Office.Interop.PowerPoint.
EApplication_SlideSelectionChangedEventHandler(SlideSelection_Changed);

pptApp.PresentationClose += new Microsoft.Office.Interop.PowerPoint.
EApplication_PresentationCloseEventHandler(Presentation_Close);

pptApp.PresentationSave += new Microsoft.Office.Interop.PowerPoint.
EApplication_PresentationSaveEventHandler(Presentation_Open);

foreach (PowerPoint.Presentation PrstnItm in pptApp.Presentations)
{
while (Process.GetProcessesByName("POWERPNT").Length != 1) { Thread.Sleep(500); }
Presentation_Open(PrstnItm);
}






}

推荐答案


这篇关于在C#中获取Powerpoint的运行实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 20:49