7

I'm new to PowerPoint interop and I'm trying to draw red pen and yellow text marker (not shapes!!!) lines while in presentation mode.

UPDATE:

I can draw a line like this:

settings = presentation.SlideShowSettings; 
window = settings.Run(); 
window.View.DrawLine(startX, startY, endX, endY); 

But the line will always be black and thin. How can I select the red pen or yellow text marker for it?

Aside from the DrawLine method, I can select the pen for the user (mouse cursor becomes a pen instead of arrow) by setting:

window.View.PointerType = PpSlideShowPointerType.ppSlideShowPointerPen;
window.View.PointerColor.RGB = 255;

But how can I set it to text marker? yellow would be 65535, how do I get the text marker style (bigger pen, transparency) instead of the tiny solid pen?

Hinek
  • 9,519
  • 12
  • 52
  • 74
  • If there's only one slideshow window, wouldn't it be `SlideShowWindows[0]`? – qJake Oct 21 '11 at 15:03
  • I tried [0] but it resulted in an exception telling me I should pick an index between 1 and 1 ... so apparently it's not zero based ... – Hinek Oct 21 '11 at 15:35
  • Ppl, bounty is ending soon, is there really no way to do this? – Hinek Dec 06 '11 at 09:05

2 Answers2

3
  1. Create a WPF window that is transparent and topmost (EDIT: do not maximize window)

    <Window ... Background="#00000000" Topmost="True" ShowInTaskbar="False" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize">
    
  2. (NEW) Use GetWindowRect to get the location and size of the slide show window

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
    [StructLayout(LayoutKind.Sequential)]
    private struct RECT
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
    
  3. Place the transparent window over the PowerPoint slideshow window

    settings = presentation.SlideShowSettings;
    slideshowWindow = settings.Run();
    
    RECT rect = new RECT();
    GetWindowRect(new IntPtr(slideshowWindow.HWND), ref rect);        
    overlayWindow.Left = rect.Left; // EDIT: do not use slideshowWindow.Left, etc.
    overlayWindow.Top = rect.Top;
    overlayWindow.Width = rect.Width;
    overlayWindow.Height = rect.Height;
    
  4. Put a Canvas into the WPF window and add Polyline objects to it as needed. Text marker lines could be like this:

    line = new Polyline
    {
        Opacity = 0.8,
        Stroke = new SolidColorBrush(Colors.Yellow),
        StrokeThickness = 20
    };
    this.canvas.Children.Add(line);
    

    Add points to line.Points as needed. Call this.canvas.Children.Clear() to clear all your drawings.

It's a workaround but I'd say your best shot.

  • I tried it, but the overlay window always appears on the primary screen ... what am I missing? – Hinek Dec 06 '11 at 09:04
  • Sorry, it seems to have problems with the maximized window and the position of the slideshowWindow seems wrong. I edited my answer, this way it will work on any screen – Steffen Schindler Dec 07 '11 at 10:46
2

My sample application begins with creating an instance of a PowerPoint.Application class;

PowerPoint.Application PowerPointApplication = new PowerPoint.Application();

Then I set Visible property to msoTrue;

PowerPointApplication.Visible = Core.MsoTriState.msoTrue;

Then create a Presentation and Slide;

PowerPoint.Presentations PowerPointPresentationSet = PowerPointApplication.Presentations;

PowerPoint._Presentation PowerPointPresentation = PowerPointPresentationSet.Add();
PowerPoint.Slides PowerPointSlideSet = PowerPointPresentation.Slides;

PowerPoint._Slide PowerPointSlide = PowerPointSlideSet.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);

In my code, I created a Shape object;

PowerPoint.Shape PowerPointShape = PowerPointSlide.Shapes.AddLine(100, 100, 500, 500);

Then, I format it like this;

PowerPointShape.Line.Weight = 10;
PowerPointShape.Line.ForeColor.RGB = 65535;

PowerPointShape.Line.Transparency = 0.8f;

The point is, Opacity grows when Transparency property decreases.

You can set Line.Weight property to thinner or ticker the line, and you can set the value of Foreground.RGB property to change the color of line.

PS: I added these namespaces code files usings area;

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Core = Microsoft.Office.Core;

You can find working solution from this link; http://snipt.org/nsgk7

Engin Polat
  • 41
  • 1
  • 7
  • 1
    Yes, I did that too as a quick workaround, but I have 3 issues with that: 1. Drawing shapes instead of marker is really slow in a decent sized presentation (you can see the shapes created, the weight adjusted, the color set, etc.) 2. After this I have real shapes in my presentation, I would prefer the markers and the question if you want to keep or loose the annotation. And 3. If I use this in two presentations with different themes the shapes will look different (e.g. a round pen or a rectangular one) ... – Hinek Dec 02 '11 at 09:04
  • I edited the question to emphasize that I'm looking for the markers, not for shapes. But thanks for your answer. – Hinek Dec 02 '11 at 09:06