从创建可见窗口prevent子进程?进程、窗口、prevent

2023-09-03 00:36:47 作者:爱笑的智障

我想使用办公自动化(PIA)某些 .PPTX 文档转换成其他格式。然而,PowerPoint中坚持表示,即使在主窗口隐藏一个进度条。

有没有什么办法可以prevent PowerPoint无法显示过任何Windows主桌面?

额外信息:

我主要是使用C#,COM PIA为Office互操作。但我不怕挖成C ++:P

我开始使用PIA这样的PowerPoint

  VAR应用=新PowerPoint.Application();
。VAR PPT =约presentations.Open(my.pptx);

//此行会显示一个进度对话框
ppt.SaveAs(out.pdf
    PowerPoint.PpSaveAsFileType.ppSaveAsPDF,
    MsoTriState.msoTrue);

app.Quit();
 

解决方案

您可以使用的 CreateDesktop 调用调用PowerPoint演示过程之前创建备用桌面。这将确保由PowerPoint创建的窗口是不可见的。但是,也有一些需要注意的地方在这里:

您需要做的这一个备用线;你不想改变桌面上的主界面线程 这也可能是最好的PowerPoint初始化一次,在一个专门的线程与替代台式机,并保持在同一个线程,直到你终止。这将确保它不会从多个桌面被称为混淆。 如果PowerPoint中弹出任何形式的对话框中,用户将无法除非您将它们切换到备用桌面与PowerPoint互动来回答吧。 如果PowerPoint中的进程外的服务器,不好的事情可能发生(备用桌面上的PowerPoint加载,然后用户尝试手动打开PowerPoint,在这无形的备用桌面上点PowerPoint的主界面负载)。这可能是一些你需要仔细测试。这个问题可能是避免由创建备用窗口站为好,但由于窗口站的过程中,全球性的,你需要生成一个辅助子进程来处理在这种情况下使用PowerPoint的互动。 我打开程序只有进程没有窗口

您也可以尝试使用 Windows消息钩确定创建窗口时,并保持不可见。这也有一些需要注意的地方:

您必须找到确定的感兴趣窗口的某种可靠的方式(窗口类名?) 如果PowerPoint中的进程外的服务器,会出现一个窗口,你的钩子是活动的,可能会隐藏错误的进度对话框(例如,一个属于另一个进程)。为了尽量减少这种机会,测试以查看是否简报是在进程(在这种情况下,程序的钩只影响自己的过程),并且如果没有,安排钩子仅是活动的的必要时间,以晚饭的最小量preSS进度窗口。 在未来的PowerPoint版本可能会打破无论您使用的方法来识别感兴趣的窗口。有一点你可以做这个。

I'm trying to use Office Automation (PIA) to convert some .pptx documents into some other formats. However, PowerPoint insists on showing a progress bar even the main window is hidden.

Is there any way I can prevent PowerPoint from ever displaying any Windows to the main desktop?

Extra information:

I am mainly using C#, COM PIA for Office interop. But I'm not afraid to dig into C++ :P

I start PowerPoint using PIA like this

var app = new PowerPoint.Application();
var ppt = app.Presentations.Open("my.pptx");

// This line will show a progress dialog
ppt.SaveAs("out.pdf",
    PowerPoint.PpSaveAsFileType.ppSaveAsPDF,
    MsoTriState.msoTrue);

app.Quit();

解决方案

You can use the CreateDesktop call to create an alternate desktop before invoking the powerpoint process. This will ensure that windows created by powerpoint are not visible. However, there are a number of caveats here:

You will need to do this in an alternate thread; you do not want to change the desktop on your main GUI thread It's probably best to initialize powerpoint once, on a dedicated thread with an alternate desktop, and keep it on that same thread until you terminate. This ensures it won't be confused by being called from multiple desktops. If powerpoint pops up any kind of dialog, the user will not be able to answer it unless you switch them to the alternate desktop to interact with powerpoint. If powerpoint is an out-of-process server, bad things may happen (powerpoint loads on alternate desktop, then user tries to open powerpoint manually, at which point powerpoint's main UI loads on the invisible alternate desktop). This is probably something you'll need to test carefully. This problem may be avoidable by creating an alternate Window Station as well, but as window stations are process-global, you'd need to spawn a helper child process to deal with interactions with powerpoint in this case.

You could also try using a Windows Message Hook to determine when the window is created and keep it invisible. This also has a number of caveats:

You'll have to find some reliable way of identifying the window of interest (window class name?) If powerpoint is an out-of-process server, there will be a window in which your hook is active and might hide the wrong progress dialog (ie, one belonging to another process). To minimize this chance, test to see if powerpoint is in-process (in which case program the hook to only affect your own process), and if not, arrange for the hook to only be active for the minimum amount of time necessary to suppress the progress window. Future powerpoint releases may break whatever method you use to identify the window of interest. There's little you can do about this one.
 
精彩推荐
图片推荐