How to activate opened presentation? - c#

Hi
Could some one help me for this problem:
How to activate a presentation window by using its name?
foreach (PPT.Presentation ppt in ppApp.Presentations)
{
if (ppt.Name == strTargetFileName)
{
//Then activate this ppt. How to do this?
}

You can launch a PowerPoint with Process.Start:
Process.Start(#"c:\users\foo\Documents\Bar.ppt");
If you need to actually launch it in slideshow mode, you can do:
Process.Start("powerpnt", "/s \"C:\\Users\\Foo\\Documents\\Bar.ppt\"");

You should find window handle first with FindWindow function and when activate it with SetForegroundWindow function. Check this page, sample code there performs actually what you are looking for

first add a reference ( rigth click solution explorer to Microsoft PowerPoint XX Object)
using MSPPOINT = Microsoft.Office.Interop.PowerPoint;
define a instance of the object
MSPPOINT._Application pwpApp = new MSPPOINT.Application();
MSPPOINT._Presentation pwpDoc = null;
pwpApp.Activate();
pwpDoc = pwpApp.Presentations.Open(#"D:\Temp\Document.pptx", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
//enter code here
and do something with him..
Good Luck !

Related

TestStack/White API

I'm trying to automate an application using TestStack/White API (Which is based on Microsoft's UI Automation library).
The problem is the following:
At a certain point of automation, I have to deal with an "Dialog" window, which looks to be a separate process, if i look at "Windows Task Manager". But no matter how i try to access the "Dialog Window" (Class, ID, Text, ControlType, etc.) I'm not able to access it.
You can find the UISpy image and code below...
Using UISpy - Dialog Information
using (var DISCLAIMER_App = Application.Attach(#"PathToExecutable"))
using (var DISCLAIMER_Window = DISCLAIMER_App.GetWindow(SearchCriteria.ByClassName("#32770"), InitializeOption.NoCache))
{
var IAccept_button = DISCLAIMER_Window.Get<Button>(SearchCriteria.ByText("I accept"));
IAccept_button.Click();
}
# I've tried also Application.Launch, Application.AttachOrLaunch.
# I also looked to be sure that the Dialog window is a separated process and doesn't belong to any parent window.
Any suggestions?
Found the Solution, had to use "ProcessStartInfo()" and pass the return data to "Application.AttachOrLaunch()":
var psi = new ProcessStartInfo(#"PathToExecutable");
using (var DISCLAIMER_App = Application.AttachOrLaunch(psi))
Source: http://techqa.info/programming/tag/white?after=24806697

Extract Text from a running Program's Window Title without process.MainWindowTitle

I'm trying to extract text from a Creo 2.0 Window Title. The text will be used to create a folder titled the same as the part number that is opened and in the Window Title. The issue I have is that I can iterate through, and find all the Window Titles of open applications using process.MainWindowTitle, but for some reason, Creo doesn't have a Main Window Title. It also doesn't have the text using any other "process." functions. I figure that the information has to be somewhere if it's in the title bar like other normal programs, but I'm just not going at it the right way. Is there another process using C# that I can use to try and accomplish this?
Let me know if I need to give any other information. Thank you for the help!
It may not necessarily be available via the Process object. Explorer.exe, for example, has the current folder name in the title bar but this is not the MainWindowTitle. Another option is to use UI Automation to inspect the UI and report the window's title. Depending on which version of .Net you are targeting, you can reference UiaComWrapper (which has more information and better perf, I believe) or UIAutomationClient and UIAutomationTypes. A short sample that prints all window titles:
using System;
using System.Diagnostics;
using System.Windows.Automation;
static void Main(string[] args)
{
var windows = AutomationElement.RootElement.FindAll(TreeScope.Descendants,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
foreach(AutomationElement window in windows)
{
var props = window.Current;
var proc = Process.GetProcessById(props.ProcessId);
Console.WriteLine("{0} {1} {2}", props.ProcessId, proc.ProcessName, props.Name);
}
}
Note that you need to run this elevated if you want to get information on elevated processes.

Which Command Item is activated on the Command bar

I am working with Add-Ins in ArcMap using VS2010 and C#. I have a question in regards to ArcObjects ICommandBar and ICommandItem classes. I've looked at these and have been able to produce code, that on button click, will select or activate a specified command item. So I know somethings about command bars. My question is how would I go about determining which command Item is active on a Command Bar? I didn't see any helpful mehtods in which to do so. Any help on this would be greatly appreciated.
UID thisID = new UID();
thisID.Value = "esriArcMapUI.SelectTool";
IDocument ThisDoc = ArcMap.Application.Document;
ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars;
CommandBars.Find(thisID);
ICommandItem myItem = CommandBars.Find(thisID) as ICommandItem;
if (myItem.Execute() == true)
{
messagebox.show("My select element tool is selected");
}
I finally found an answer to my problem, with help from #DJKRAZE. I was making this a little harder than it was and thinking about it way too hard. The code below can be used to return the currently selected tool in ArcMap (In my case I am returning the tooltip of the currently selected tool in my diagnostic window).
public static ICommandItem CurrentTool()
{
IApplication _myApp = ArcMap.Application;
string getToolTip = _myApp.CurrentTool.Tooltip;
System.Diagnostics.Debug.Write("Current Tool Tip is: " + getToolTip);
return _myApp.CurrentTool;
}
I call this function on a button click. So, When I launch ArcMap, I select a tool from the toolbar. I look into my diagnostic window and I'm able to see the tool tip for the selected tool. I will need to tweak a few things for my own benefit, but this would be the answer I am looking for. Hope this can be of some help to any one else.

c# detect an open web browser

I am writing a program that searches certain web pages before closing. I would like my program to open a NEW WINDOW using the DEFAULT BROWSER. I can have my program focus the newest window instance, and then it will close that instance once it is done.
I have been staring at WebBrowser.Navigate and System.Diagnostics.Process.Start(target) all day but I cant find the sweet spot with either of them.
WebBrowser.Navigate always opens IE, I have been looking in the API and can't find a way to change the program used. Does anyone else see something that I dont? Is there a way to change the application used?
System.Diagnostics.Process.Start(target) opens in a new tab, not a new window like navigate does. However none of the overloaded functions from the API have a way of saying "create a new instance or window".
this is my issue, they both have pieces that I want, but I cant figure out how to get the pieces I need for either one.
I would be extremely grateful for you help. I have been looking for hours now and I can seem to come to a solution.
code sample for Jester:
Process defaultbrowser = new Process();
defaultbrowser.StartInfo.CreateNoWindow = true;
defaultbrowser = Process.Start(target);
int waitTime = Convert.ToInt32(numericUpDown2.Value);
System.Threading.Thread.Sleep(waitTime*1000);
defaultbrowser.CloseMainWindow();
defaultbrowser.Close();
furthermore my Close() function is causing a runtime error that says;
System.NullReferenceException: Object reference not set to an instance
of an object.
which seems silly because too me the above code makes me think that my defaultbrowser is an instance of a process, which is then supposed to be able to call the non-static function "close()".
ok If I got your problem right you are looking for a way to open a web page in the "default" browser.
That can be done by simply make a new process like:
Process.Start("http://google.com");
If you would like to control witch browser gets used you can do it by passing the web address to the browser's exe file as a parameter:
System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments");
To start the process in the new window pass a ProcessInfo object to the Process.Start
And set the CreateNoWindow
more info on that
Hey To check if it's loaded wherever, do:
if(browser.ReadyState == WebBrowserReadyState.Complete) {
// It's Open!
}
You should use System.Diagnostics.Process like that:
Process Chrome = new Process(); //Create the process
Chrome.StartInfo.FileName = #"C:\Program Files\Google\Chrome\Application\chrome.exe"; // Needs to be full path
Chrome.StartInfo.Arguments = ""; // If you have any arguments
Chrome.Start();

Powerpoint 2010 Multiple Instances

I have seen numerous posts on this subject here, but none seem to answer this issue directly. I want to control two instances of Powerpoint running on a second monitor.
The ideal solution looks like this:
PowerPoint.Application PPTViewer1 = new PowerPoint.Application();
PowerPoint.Application PPTViewer2 = new PowerPoint.Application();
I can do this manually, simply by starting two instances of PowerPoint, loading the presentation, and starting the slide show from each instance. I can toggle back and forth between the two slide shows manually, with each being brought to the front as expected.
So... how do I do this programatically using VSTO and C#?? Like others before me, I see that the Interop.PowerPoint interface will create only the single instance. If that were not the case, then I could achieve the results I am looking for easily enough.
Additionally, I am not looking for a third party component for this task.
Any help is appreciated.
Thanks in advance.
It may appear that you're running multiple instances of Powerpoint, but you're not. It only allows one instance of itself. If you see two instances of Powerpnt.exe in the task list, as sometimes happens, it means that something's gone wrong and left a zombie in memory.
May not be totally ideal but here is a reference that suggested to start an instance as a different user (Note that this site is for PowerPoint 2007).
runas /user:username "C:\Program Files\Microsoft Office\Office12\POWER PNT.EXE"
Each instance of the Powerpoint COM object shares the same fullscreen display window. I know of no method to switch which presentation has that window
The solution is to host the Powerpoint display in your own window
This therefore allows you to scale the window and show multiple presentations on one monitor, or move it from one monitor to another?
e.g.
var display1 = new FullScreenDisplay(); // A form with BorderStyle = None
display1.Show();
application1 = new PowerPoint.Application();
presentation1 = application1.Presentations.Open2007(....);
var slideShowSettings1 = presentation1.SlideShowSettings;
slideShowSettings1.ShowType = PowerPoint.PpSlideShowType.ppShowTypeSpeaker;
var slideShowWindow1 = slideShowSettings1.Run();
IntPtr hwnd1 = (IntPtr)slideShowWindow1.HWND;
SetParent(hwnd1, display1.Handle);
var display2 = new FullScreenDisplay();
display2.Show();
application2 = new PowerPoint.Application();
presentation2 = application2.Presentations.Open2007(....);
var slideShowSettings2 = presentation2.SlideShowSettings;
slideShowSettings2.ShowType = PowerPoint.PpSlideShowType.ppShowTypeSpeaker;
var slideShowWindow2 = slideShowSettings2.Run();
IntPtr hwnd2 = (IntPtr)slideShowWindow2.HWND;
SetParent(hwnd2, display2.Handle);
display1.BringToFront(); // to show slideshow 1
// or
display2.BringToFront(); // to show slideshow 2
// To advance a slide
presentation1.SlideShowWindow.View.Next();
// or
presentation2.SlideShowWindow.View.Next();
// To exit, note order!
presentation2.SlideShowWindow.View.Exit();
presentation1.SlideShowWindow.View.Exit();
Application.Exit();
This is a hack, and may not work in future versions of Powerpoint?
You also need this import
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

Categories

Resources