0

Here I have a powerpoint 2010 presentation. On one slide there is an embedded Windows media Player OCX Control. As a simple GUI, I placed 3 buttons labeled Play, Pause, Stop on the same slide.

Using Perl's Win32::OLE module, I want to test if the click event on "Play" plays the file in the embedded windows media player.

Raising the Click event with the mouse, it does.

Using code below, it does not work. Why?

note "Slide $i: " . $slide->{Name};
# switch to "full-screen presentation mode"
PowerpointHelpers::launch_slideshow_from_slide($ole->ActivePresentation, $i);
sleep 3;

#does not work
$btnplay->{OLEFormat}->Object()->btnPlay_Click();

sleep 3;
# return to slide edit-mode
# PowerpointHelpers::exit_show($ole);

This is the VBA procedure that is supposed to run:

Public Sub btnPlay_Click()

    Init
    PlayVideo (Player.URL)

End Sub

As you can see this just calls two custom functions that play an avi file. It does work correctly in interactive use. but not via VBA automation .

Meanwhile, I have tried quite a few variations of the line

 $btnplay->{OLEFormat}->Object()->btnPlay_Click();

but none work.

Here is a dump of the $btnplay object:

OLE object's properties:
Accelerator .............................
AutoSize ................................ 0
BackColor ............................... 8421504
BackStyle ............................... 1
Caption ................................. Video abspielen
Enabled ................................. 1
Font .................................... [IFont]
ForeColor ............................... 0
Height .................................. 28.375
Left .................................... 18.75
Locked .................................. 0
MouseIcon ............................... <undef>
MousePointer ............................ 0
Name .................................... btnPlay
Picture ................................. <undef>
PicturePosition ......................... 7
TakeFocusOnClick ........................ 1
Top ..................................... 382.875
Visible ................................. 1
Width ................................... 124.75
WordWrap ................................ 0
ZOrderPosition .......................... 9
9
  • How did you add the ocx file to embed windows media player? May 10, 2011 at 7:48
  • I added it manually in Powerpoint's edit mode, via the Developer Menu/Controls Ribbon/More Controls Icon (Click on Hammer-and-Wrench Icon), choosing "Windows Media Player".
    – knb
    May 10, 2011 at 9:12
  • As this is an activex control, you can look at the properties and change the name of it to mvpDemo (for example). On the button click, you can write code such as mvpDemo.controls.pause or mvpDemo.controls.play. Does that help? May 10, 2011 at 9:37
  • I don't want to interact with the "native" play/pause/stop buttons of the WMP command bar. They are too small for the touchscreen apllication I am writing. Therefore I have added three much larger Command Buttons. I want to fire the Click events associated with these buttons. Imagine an empty slide with a single CommandButton control, and a simple event handler sub mybotton_Click() "MsgBox 'Hello'" End Sub. I want to call this event handler from perl. See also stackoverflow.com/questions/4500335/…
    – knb
    May 10, 2011 at 9:48
  • On the click of the bigger buttons, write code such as mvpDemo.controls.play? Do you find anything wrong with it? On the other question, isn't it already answered & accepted? May 10, 2011 at 9:52

2 Answers 2

1

This works!

my $s = $ole->ActivePresentation->SlideShowWindow->View->Slide;

$s->Application->Run('btnPlay_Click', '');
0

This does not work, it is here for completeness. I was referring to this code in the comments.

This is my perl code, where I attempt to call the btnPlay_Click event handler directly:

my $s = $ole->SlideShowWindows(1)->View->Slide;
PowerpointHelpers::_dump_ole_obj($s, 1);

Win32::OLE->Option(Warn => 3);
$s->btnPlay_Click();  ### DOES NOT WORK (for me)
Win32::OLE->Option(Warn => 0);

Error Output of btnPlay_Click();

Win32::OLE(0.1709) error 0x80020003: "Member not found"
    in METHOD/PROPERTYGET "" at 06-mediaplayer--button-clicks-ok.t line 127

slide object: Output of _dump_ole_obj

OLE object's properties:
Application ............................. [_Application]
Background .............................. [ShapeRange]
BackgroundStyle ......................... 0
ColorScheme ............................. [ColorScheme]
Comments ................................ [Comments]
CustomLayout ............................ [CustomLayout]
CustomerData ............................ [CustomerData]
Design .................................. [Design]
DisplayMasterShapes ..................... -1
FollowMasterBackground .................. 0
HasNotesPage ............................ -1
HeadersFooters .......................... [HeadersFooters]
Hyperlinks .............................. [Hyperlinks]
Layout .................................. 1
Master .................................. [_Master]
Name .................................... Slide7
NotesPage ............................... [SlideRange]
Parent .................................. [_Presentation]
PrintSteps .............................. 1
Shapes .................................. [Shapes]
SlideID ................................. 262
SlideIndex .............................. 24
SlideNumber ............................. 24
SlideShowTransition ..................... [SlideShowTransition]
Tags .................................... [Tags]
ThemeColorScheme ........................ [ThemeColorScheme]
TimeLine ................................ [TimeLine]
sectionIndex ............................ 1

More Funcnames:
Cut()
Duplicate()
Export()
GetTypeInfo()
Invoke()
MoveToSectionStart()
QueryInterface()
Release()
SectionNumber()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.