Prevent the creation of child processes from visible windows?

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

Is there any way to prevent PowerPoint from displaying Windows on the main desktop?

Additional Information:

I mainly use C #, COM PIA to interact with Office. But I'm not afraid to delve into C ++: P

I am running 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(); 
+4
source share
1 answer

You can use the CreateDesktop call to create an alternate desktop before calling the powerpoint process. This ensures that windows created with powerpoint are not visible. However, there are a few caveats here:

  • You will need to do this in an alternate thread; You do not want to change the desktop in your main GUI thread.
  • It is probably best to initialize PowerPoint once in a dedicated thread using an alternate desktop and save it in the same thread until you are done. This ensures that it will not be confused when called from multiple desktop computers.
  • If PowerPoint displays any dialog, the user will not be able to answer it unless you switch them to an alternative desktop to interact with PowerPoint.
  • If powerpoint is a server that is not running during the processing phase, bad things can happen (downloading Powerpoint to an alternate desktop, then the user tries to open Powerpoint manually, after which the main PowerPoint user interface is loaded onto an invisible alternate desktop). This is probably something you will need to check carefully. This problem can be prevented by creating an alternative Window Station , but since window stations are global processes, you will need to create an assistant child process to deal with powerpoint interactions in this case.

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

  • You need to find a reliable way to determine the window of interest (window class name?)
  • If PowerPoint is a server outside the process, a window appears in which your hook is active and may hide the incorrect execution dialog (i.e., that belongs to another process). To minimize this chance, check to see if there is a Powerpoint at the operating point (in this case, the program only binds to your own process), and if not, configure the hook only for the minimum time necessary to suppress the progress window.
  • Future releases of PowerPoint may break any method you use to determine which window of interest. There is little that can be done about it.
+3
source

Source: https://habr.com/ru/post/1341147/


All Articles