Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: [2008] Display powerpoint slides on form and run slides from form

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    [2008] Display powerpoint slides on form and run slides from form

    Please can someone point me to some code that will load powerpoint slides into a scrolling image container and allow me to control the presentation by double-clicking the slide image.

    If powerpoint is not installed on end users machine can we use Powerpoint viewer and automate it by code ?

    Thanks for any help.

  2. #2

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Thanks Deepak. This shows each slide one at a time. Is there any way I get get all the slides in a scrolling manner ?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    anyone?

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    If your end goal is simply to allow people to view PowerPoint slides, can you not point them to the freeware viewer MS provides, or bundle the installer in with your app?

    2003 version download site:
    http://www.microsoft.com/downloads/d...displaylang=en

    2007 version download site:
    http://www.microsoft.com/downloads/d...displaylang=en

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    I wouldn't have thought you could automate the viewer - it is a cut down version with (I suspect), the VBA and object model completely stripped down.

    Why automate what is provided there though. What are you trying to accomplish with this part of your app?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    I am trying to display a scrolling control with all powerpoint slides within my app.

    I will be installing PPViewer if PP is not available on end-users machine.

    Double-clicking the relevant powerpoint slide will display the slide maximized.

    CAn I open an instance of PPViewer ON my form ?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    anyone ?

  9. #9
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    The only way I can see you doing this programatically would be to open the file, loop through the sheets, perform a shreenshot on each and output this to a series of image container controls dynamically - this wouldn't be elegant, is prone to errors and would cause a terrible flicker on screen.

    I've just been through the PowerPoint object model, and .Net/COM toolbox items and can't see anything there at all.

    It is possible if you had VB6 still you could look at the ole control, but again I'd expect this would just show individual slides.

    I have managed to find you this though: http://www.aspose.com/categories/fil...a/default.aspx

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Quote Originally Posted by alex_read
    I have managed to find you this though: http://www.aspose.com/categories/fil...a/default.aspx
    I have never seen this product, thanks. I am really only looking for bringing in ppt slides read-only into my form. Heavens - $599 is quite a lot.

    Quote Originally Posted by alex_read
    The only way I can see you doing this programatically would be to open the file, loop through the sheets, perform a shreenshot on each and output this to a series of image container controls dynamically - this wouldn't be elegant, is prone to errors and would cause a terrible flicker on screen.

    I Am interested in your other solution, though. Convert slides into images and display in a vertically scrolling container. I'm willing to risk the flicker.

    Do you think you can help me with that ?

    I do know that if you can get slideno(x) from the array of slides, you can pass it to powerpointviewer's commandline interface and have it display only that slide. It's at the bottom of the MS-page.

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    Well you'd use something like this to enumerate the powerpoint slides and select each (show this individual slide on screen). Are you familiar with accessing office/PowerPoint libraries from .Net? If not goto the top of the Office forum on this site and Rob's got a section on it. This is VBA code but you'll need to qualify each call properly i.e. PowerPoint.Application.Presentations(1) etc.
    Code:
    If Not (ActivePresentation.Slides Is Nothing) Then
        Dim currentSlide As Slide
        For Each currentSlide In ActivePresentation.Slides
            ActivePresentation.Slides(currentSlide).Select
        Next
    End If
    For the print screen bit, you can look here http://vbnet.mvps.org/index.html?cod...tscreenapi.htm - I imagine there must be a graphic command for this in .Net, but I can't seem to fins one at the moment.

    Edit: found one! - http://www.vbforums.com/showthread.p...rint+screen%22 - this'll show you how to retreive the image also.

    For the final bit, you'd have maybe a panel control (is that in Windows forms - groupbox maybe [I'm a web developer]), then create image or picturebox controls at runtime. These are known as dynamic controls and there's a version of a label creation via code here: http://www.vbforums.com/showthread.p...namic+controls
    Last edited by alex_read; Jun 12th, 2008 at 08:04 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Thanks Alex. I have to operate under the pretext that end user may NOT have POwerpoint installed at their end.

    So I need some way to :
    * export ppt slides to image1, 2 etc without having to open an instance of PP :found something here on codeproject
    * import images into container
    * on image double click fire up powerpointviewer(slide(x))
    Last edited by Xancholy; Jun 12th, 2008 at 08:29 AM.

  13. #13
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    Well, you can try this. Edit: Removed additional attachment as this was written into the attachment within my other post further down this thread.

    If you look at the main Dump method in that codeproject file, he's instanciating powerpoint and running the slideshow from the COM library included with his project. I honestly don't know whether that will have any use to you if your user hasn't even got the reader on.

    I'd test this carefully on both a machine without powerpoint and on one with just the reader on it.

    To run this, create a new Windows application project, then from the Project > Add References menu, navigate to the COM tab of the dialog which appears. Select the Microsoft PowerPoint x.x object library. Finally - edit the filename of the powerpoint file at the top of this file and it should run ok.
    Last edited by alex_read; Jul 16th, 2008 at 06:57 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Alex, thanks and sorry for my delay in replying. The problem with referencing Powerpoint is for eg: in my case I have PowerPOint9 & Office2000. I'm sure your code will work for end users who have >Office2000.

    While I am still experimenting with your code, I still think I need to be able to export the powerpoint slides to images and then find a way to automate the viewer.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    I found this here
    Code:
    Imports Microsoft.Office.Core
    Imports Microsoft.Office.Interop
    Imports System.IO
    Imports System.Runtime.InteropServices
     
    Public Enum ExportImageType
      JPG
      BMP
      PNG
      GIF
    End Enum
     
    Public Class PowerPointExporter
     
      Public Shared Sub ExportPresentation(ByVal fileName As String, ByVal outputPath As String, ByVal imageType As ExportImageType, ByVal width As Integer, ByVal height As Integer)
     
        If Not File.Exists(fileName) Then
          Throw New FileNotFoundException(fileName)
        End If
     
        If Not Directory.Exists(outputPath) Then
          Throw New DirectoryNotFoundException(outputPath)
        End If
     
        Dim app As New PowerPoint.Application()
       ' app.Visible = MsoTriState.msoFalse
     
    'for Office 2003
        Dim presentation As PowerPoint.Presentation = _
          app.Presentations.Open(fileName, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoTrue)
     
    'for Office 2007
     '       Dim presentation As PowerPoint.Presentation = _
              app.Presentations.Open2007(FileName:=fileName, ReadOnly:=MsoTriState.msoTrue, WithWindow:=MsoTriState.msoTrue)
     
        For Each slide As PowerPoint.Slide In presentation.Slides
          Dim name As String = IIf(slide.Name.Trim().Length = 0, slide.SlideIndex, slide.Name)
          Dim outputFileName As String = Path.Combine(outputPath, name) & "." & imageType.ToString()
          slide.Export(outputFileName, imageType.ToString(), width, height)
          Marshal.ReleaseComObject(slide)
        Next slide
     
        Marshal.ReleaseComObject(presentation)
        Marshal.ReleaseComObject(app)
     
      End Sub
     
    End Class
    Sample usage:
    Code:
        Dim fileName As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Test.ppt")
    
        PowerPointExporter.ExportPresentation(fileName, "c:\temp", ExportImageType.JPG, 1024, 768)
    Last edited by Xancholy; Jun 16th, 2008 at 01:33 PM.

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2008] Display powerpoint slides on form and run slides from form

    But that will not work unless the workstations have PowerPoint installed on their machines which I believe you stated they dont.

    You could always export the slideshow as a pps or ppsx instead of a ppt or pptx.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Quote Originally Posted by RobDog888
    But that will not work unless the workstations have PowerPoint installed on their machines which I believe you stated they dont.
    True. That code will only work if they have 0-2003/7 installed.
    Quote Originally Posted by RobDog888
    You could always export the slideshow as a pps or ppsx instead of a ppt or pptx.
    Will pps show make a difference ?


    So I really still need something that converts ppt/pps to images and then I can automate the deployed ppt viewer.

    Any ideas ?

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2008] Display powerpoint slides on form and run slides from form

    pps = PowerPoint Slideshow.
    ppt = PowerPoint project file

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Quote Originally Posted by RobDog888
    pps = PowerPoint Slideshow.
    ppt = PowerPoint project file
    Really I did know that
    My Q was is there any difference between bringing pps slides into a form or ppt slides into a form.

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2008] Display powerpoint slides on form and run slides from form

    If you knew that then why try to load a ppt in a form? You should only be loading pps or ppsx. It will all depend on how you are going to handle the user having PP or not. If you are going to have them download and install the viewer too then you can always depend on using the viewer regardless and show pps files. Use SetParent on the Viewer to nest it in a vb form.

    You may also be export the ppt to a stand alone slide show by selecting the export to CD option and then distributing the supporting files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    There may be some misconception here. ppt vs pps is not really the issue is it ? pps opens PP in play mode while ppt opens PP in edit mode.

    My question is how to get ALL those slides to display onto a form. Sort of like powerpoint when it's in SlideSorter View.

    Quote Originally Posted by RobDog888
    If you are going to have them download and install the viewer too then you can always depend on using the viewer regardless and show pps files. Use SetParent on the Viewer to nest it in a vb form.
    If I setParent the viewer, will it display all the slides at once is the big question.

    Can you show me how to setParent the powerpointviewer.exe and I will give it a go.

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    The following command-lines are available for Powerpoint Viewer 2003

    Code:
    You can use command line switches to modify the way that PowerPoint 2003 Viewer runs. The command line switches for PowerPoint 2003 Viewer are as follows:
    •	/L - Use this switch to read a play list of PowerPoint presentations from a text file. For example, type the command Path\pptview.exe /L "Your_Play_List.txt" to view the PowerPoint presentations that are listed in the Your_Play_List.txt file.
    •	/S - Use this switch to start PowerPoint 2003 Viewer and not display the splash screen.
    •	/P - Use this switch to send the presentation to a printer, and print the file. For example, type the command Path\pptview.exe /P "Presentation.ppt" to print the Presentation.ppt file.
    •	/D - Use this switch to prompt the Open dialog box to appear when the slide show ends.
    •	/N# - Use this switch to open the presentation at a specified slide number. For example, type the command Path/pptview.exe /n5 "presentation.ppt" to open the presentation at slide 5.
    For 2007 Viewer

    I don't see an option to display all slides. But one can choose which slide number the viewer displays.

    Quote Originally Posted by Xancholy
    So I really still need something that converts ppt/pps to images and then I can automate the deployed ppt viewer.

    Any ideas ?

  23. #23
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    You may also be export the ppt to a stand alone slide show by selecting the export to CD option and then distributing the supporting files
    That one's interesting to know - didn't know that.

    Code:
    If I setParent the viewer, will it display all the slides at once is the big question. Can you show me how to setParent the powerpointviewer.exe and I will give it a go.
    SetParent is an API call which takes a given window handle and assigns it to a given parent window handle. Performing a search upon a search engine for vb and setparent yielded lots of samples. The suggestion above was for having your slideshow run in a pps file, then display this inside your form. You could perform the same with a ppt file, but you'd have the powerpoint application within your form and rather than that, the users should really use powerpoint directly in that scenario.

    I am trying to display a scrolling control with all powerpoint slides within my app.
    Related to that, the OP is trying to have a slideshow preview of all the slides upon his form - like on the left of a ppt file when you open it, it displays all of the slides to show.

    I don't see an option to display all slides. But one can choose which slide number the viewer displays.
    The OP did originally post a link to this one.

    in my case I have PowerPoint9 & Office2000. I'm sure your code will work for end users who have >Office2000.
    You have to tell us these bits of information as it can make all the difference to both our advice and code suggestions!
    This code is updated to use late binding using the COM PowerPoint library and export the screenshots to JPeg files as well as rendering them on a form in pictureboxes. However again test it thoroughly - some of the method calls may not be in previous versions of PowerPoint and may require tweaking and also, I'm still with Rob on this one, though this sample looks ok here and uses the PowerPoint libraries to automate PowerPoint on a machine without it installed, I honestly can't see the slide showing on screen without any form of viewer or application installed. I might be wrong and have a play with it by all means (attached), but I can't really see this happening myself.

    I'd point out and urge you to look at another thread - Klienma's got a great sample of the FindExecutable API call here: http://www.vbforums.com/showthread.php?t=323257 in his BrowserExec class which you could tweak to check whether the user can open a PowerPoint file or not - if not you could then start the installer of the viewer and either leave them with that, or embed a version within your form using the above SetParent API call advice.
    Attached Files Attached Files
    Last edited by alex_read; Jul 16th, 2008 at 01:15 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Thanks very much for your help on this Alex! In essence the code does what is required on systems with >Office 2000.

    If we were to break up this app:
    1. import slide images
    2. display slide images


    Your methodology of importing the slide images hinges on Powerpoint doing the work.

    My suggestion is : for step 1 we should turn to a non-POwerpoint solution, something likeShell's IEExtract image but I don't know enough to get it to work.

    Step 2 is fairly simple. Display all extracted images on form as you have done. Double-clicking image automates powerpoint viewer

    Quote Originally Posted by alex_read
    though this sample looks ok here and uses the PowerPoint libraries to automate PowerPoint on a machine without it installed, I honestly can't see the slide showing on screen without any form of viewer or application installed.
    My objective is for this to work on end user systems without Powerpoint by supplying the PP Viewer

    Once again thanks.

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Alex, are you still subscribed to this thread ? If so, how can I have the powerpoint slides appear in a vertically scrolling panel ?

  26. #26
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    The above attachment has been re-uploaded with support for the dynamic controls being added to a scrollable panel control. This still uses powerpoint or the viewer unfortunately as I'm not sure theres another non-expensive way to accomplish your task without it (I kept an eye on your other thread noted above too).

    The alterations required were as below. You will need to perform the 1st 2 in order for this sample to work on your computer/environment...
    1. To place a panel control on the form
    2. To set the Autoscroll property of the panel control to be true
    3. To alter the code from reading FormName.Controls.Add to Panel1.Controls.Add in order to bind each picturebox control to a parent of the panel rather than the form
    4. The left property of each picturebox control was easier to set and I altered this to a smaller number

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Thanks very much Alex.

    1. Instead of powerpoint instance opening fullscreen, Is there any way to host the powerpoint (small-sized) instance on maybe a form2 and capture slides from there ?

    2. Also is there a way to display a red border around the picturebox that was clicked ?

    3. Dunno if you noticed but for some reason the taskbar appears in the first couple (actually 3) of ppt snapshots.

    4. This code works for =>Powerpoint 2003. Is there any way we can make this compatible with all versions of PP ie:- PP97 to PP2007 ?
    Last edited by Xancholy; Jul 16th, 2008 at 08:45 AM.

  28. #28
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    Quote Originally Posted by Xancholy
    1. Instead of powerpoint instance opening fullscreen, Is there any way to host the powerpoint (small-sized) instance on maybe a form2 and capture slides from there ?

    3. Dunno if you noticed but for some reason the taskbar appears in the first couple (actually 3) of ppt snapshots.
    This has baffled me - no it doesn't happen on my computers at all, I'm using version 2003 pro - do you see this behaviour on the viewer or 2007 versions?? The code calls on powerpoint to run in full screen presentation mode which should take up the entire screen - taskbar and all. Does this work if no other programs or hungry processes are running?

    There is probably a way to grab the handle of the powerpoint window and make a screenshot of this, but as it won't be running in slideshow view, you'd be grabbing the left slide preview panel, all the menu and toolbars and status bars, the notes panel etc. of powerpoint and not just the slide content.

    You could try a loop to iterate through the slides collection and use the slide.export method instead. This was mentioned on one of your current threads or perhaps a link was given upon one of these threads to a page which noted the slide.export method. I'm not aware of this method and haven't written any samples with it, but it looks as though you can export pictures of the slides using that which may help you here.

    Quote Originally Posted by Xancholy
    2. Also is there a way to display a red border around the picturebox that was clicked ?
    You can use the Windows API for this. An example can be found at http://www.visual-basic.com.ar/vbsma.../smartedge.htm

    Quote Originally Posted by Xancholy
    4. This code works for =>Powerpoint 2003. Is there any way we can make this compatible with all versions of PP ie:- PP97 to PP2007 ?
    The code provided uses late binding so I'll be suprised if it doesn't work with 2007 also, I'm only using standard calls, I imagine it'd probably work for versions prior to 2003 also. Are you asking a question "will it be compatible", or have you tested this with 2007 and got some different behaviour? If so, what messages or behaviour can you see happening when run against a 2007 version?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  29. #29
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    Hi Xancholy!

    I finally managed to look at the PowerPoint slide image export method and coded up a sample for you. This bypasses the screenshot taking and therefore you won't get the taskbar display. I've noticed it also runs much quicker also. Again this does depend on Powerpoint or the viewer being installed first off - as previous dicussion mentions but this should be of help if you're still using the above code. Final note is that I'm posting the code direct as I'm running out of the amount of attachments I can upload here!

    With regard to Office 2003, I realise I left in a comment on the late binding which I should have removed. I altered this code to be late binding so this should work with 2003 and 2007 versions. The comment in question has now been removed.
    Code:
    Option Strict off
    Imports System.Runtime.InteropServices.Marshal
    Imports System.Diagnostics
    
    Public Class Form1
    
    #Region "ClassEnumerations"
    
        Private Enum localMSOTriState
            msoTrue = -1
            msoFalse = 0
        End Enum
    
        Private Enum localPpAlertLevel
            ppAlertsNone = 1
            ppAlertsAll = 2
        End Enum
    
        Private Enum localPpSlideShowAdvanceMode
            ppSlideShowManualAdvance = 1
            ppSlideShowUseSlideTimings = 2
            ppSlideShowRehearseNewTimings = 3
        End Enum
    
    #End Region
    
        Private Const _dynamicPictureBoxNamePrefix As String = "SlidePictureBox"
        Private Const _dodgyHardcodedPPTFileName As String = "C:\SampleFile.ppt"
        Private Const _dodgyHardcodedSlideImageSaveName As String = "C:\_ExportedPPTSlideImage"    
        Private _slideIndex as Integer 
        Private _totalSlideCount as Integer
                    
        ''' <summary>
        ''' Executes once the form is loaded into the application's form collection following instanciation but before rendering. Calls the OutputPowerPointFileSlides method.
        ''' </summary>
        ''' <param name="sender">Standard .Net delegate argument.</param>
        ''' <param name="e">Standard .Net delegate argument.</param>
        ''' <remarks>None.</remarks>
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            OutputPowerPointFileSlides(Me.Panel1, _DodgyHardcodedPPTFileName)
        End Sub
    
        ''' <summary>
        ''' Executed when one of the dynamically created pictureboxes are clicked.
        ''' </summary>
        ''' <param name="sender">Standard .Net delegate argument. Relates to the control clicked upon at runtime.</param>
        ''' <param name="e">Standard .Net delegate argument. Relates to the click which occurred upon the sender object/argument at runtime.</param>
        ''' <remarks>This handles the click event of all the dynamically created picturebox controls. Within the method, the sender argument is evaluated at runtime to interprate which specific picturebox was clicked upon.</remarks>
        Private Sub DynamicPictureBox_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim _slideIndexNumber As Integer = CType(CType(sender, PictureBox).Name.Replace(_dynamicPictureBoxNamePrefix, String.Empty), Integer)
            MessageBox.Show(String.Concat("Picture box number ", _slideIndexNumber.ToString, _
                                          " was clicked!", Environment.NewLine, Environment.NewLine, _
                                          "(Remember this is a zero-based sheet ID, PowerPoint recognises 1-based)"))
        End Sub
     
        ''' <summary>
        ''' Uses PowerPoint to export slides of a given file and output these via a series of dynamically created picturebox controls upon a specified form. 
        ''' </summary>
        ''' <param name="formPanelName">Name of the form panel control to add the picturebox controls to.</param>
        ''' <param name="PowerPointFileName">The path, name and extension of a PowerPoint file containing the slides to be exported and shown.</param>
        ''' <remarks>This method can be altered to accept a generic container control which would support forms or panels to contain the picturebox controls.</remarks>
        Private Sub OutputPowerPointFileSlides(ByVal formPanelName As panel, ByVal PowerPointFileName As String)
            Dim newPowerPointInstance As Object
            Try
                ' Instanciate PowerPoint. This uses late binding contrary to the earlier made comment.
                ' Note there's no file validation check or error handling yet - I'll leave that to you! ;c)
                ' First, Open the given PowerPoint file.
                newPowerPointInstance = CreateObject("PowerPoint.Application")
                With newPowerPointInstance
                    .ShowStartupDialog = localMSOTriState.msoFalse
                    .DisplayAlerts = localPpAlertLevel.ppAlertsNone
                    .Visible = localMSOTriState.msoTrue
                    .Presentations.Open(PowerPointFileName)
                End With
    
                ' Iterate through the slides collection of the currently open single presentation. 
                With newPowerPointInstance.Presentations(1).SlideShowSettings
                    for _slideIndex = 0 to newPowerPointInstance.Presentations(1).slides.count -1 
                        ' Export each powerpoint slide to a Jpeg image file upon the file system.
                        newPowerPointInstance.Presentations(1).slides(_slideIndex +1).export( _
                         string.Format("{0}{1}.jpg", _dodgyHardcodedSlideImageSaveName, _
                         _slideIndex.tostring), "JPG")
                    Next
                End With
    
            Catch ex As Exception
                    MessageBox.Show(ex.ToString)
            Finally
                ' Clean up code. Dispose of PowerPoint as it's no longer needed. Note there's 2 Try...Catch
                ' blocks within this single method. This is so PowerPoint can be disposed of as soon as possible
                ' with this code within the 1st Try block's Finally block.
                If Not (newPowerPointInstance Is Nothing) Then
                    If (newPowerPointInstance.Presentations.Count > 0) Then
                        newPowerPointInstance.Presentations(1).close()
                    End If
                    newPowerPointInstance.DisplayAlerts = localPpAlertLevel.ppAlertsAll
                    newPowerPointInstance.Quit()
                    ReleaseComObject(newPowerPointInstance)
                    newPowerPointInstance = Nothing
    
                    For Each PowerPointProcess As Process In Process.GetProcessesByName("POWERPNT")
                        PowerPointProcess.Kill()
                    Next
                End If
            End Try
        
            try
                ' With PowerPoint opened, the slides all exported to files then the PowerPoint instance terminated,
                ' we can start to tackle showing these slide files upon the screen. Firstly, instanciate a new 
                ' collection object which will contain picturebox objects.
                Dim newPictureBoxInstance As New List(Of PictureBox)
                Dim pictureBoxTopPos As Integer = 10
                _totalSlideCount = _slideIndex -1 
    
                ' Then performing a loop to iterate through each of the earlier exported slide images from 
                ' the given PowerPoint file. Notice there's no need for sizing or sleeping in this code.
                For _slideIndex = 0 To _totalSlideCount 
                    ' With each slide and therefore loop iteration encountered, create a new picturebox 
                    ' control. These controls are created at runtime and are known as dynamic controls.
                    newPictureBoxInstance.Add(New PictureBox)
                    With newPictureBoxInstance(_slideIndex)
                        .Left = 5
                        .Height = 150
                        .Width = 150
                        .Top = CType((_slideIndex * newPictureBoxInstance(_slideIndex).Height) + 10, Integer)
    
                        ' It's important to set the right size mode for the slide image to take up the picturebox height and 
                        ' width correctly. I also name each picturebox with an ending (zero-based) slide index number.
                        .SizeMode = PictureBoxSizeMode.Zoom
                        .Name = string.Concat(_dynamicPictureBoxNamePrefix, _slideIndex.ToString)
    
                        ' Add an onclick event handler - this tells the .Net framework at runtime to call the above 
                        ' DynamicPictureBox_OnClick method when the picturebox is clicked onto.
                        AddHandler newPictureBoxInstance(_slideIndex).Click, AddressOf DynamicPictureBox_OnClick
    
                        ' Call the below method to open the earlier exported PowerPoint slide file relating to the
                        ' current loop index, and add this file as the current dynamic picturebox's image to render 
                        ' upon the screen.
                        dim exportedSlideBitmap as New Bitmap(string.Format( _
                          "{0}{1}.jpg", _dodgyHardcodedSlideImageSaveName, _slideIndex.ToString))
                        newPictureBoxInstance(_slideIndex).Image = exportedSlideBitmap
                        
                        ' With the picturebox control instanciated and it's relevant properties set, we can add this
                        ' to the panel's controls collection and render this upon the screen.
                        formPanelName.controls.Add(newPictureBoxInstance(_slideIndex))
                    End With
                Next _slideIndex   
         
            Catch ex As Exception
                ' Simply show a messagebox upon the screen if an exception occurrs for this sample project.
                MessageBox.Show(ex.ToString)
            end try
        End Sub
    
    End Class

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  30. #30

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Alex, you've just outdone yourself. That is just excellent work, thanks.

    I am testing this at home using Office 2000. It is blazingly faster than your older code.

    To get it to work for POwerpoint2000 I had to comment out lines 70,71 as these methods are not available prior to 2003

    Code:
                    '.ShowStartupDialog = localMSOTriState.msoFalse
                    '.DisplayAlerts = localPpAlertLevel.ppAlertsNone
    A small change was made to correctly show the slide number clicked.

    Code:
            MessageBox.Show(String.Concat("Picture box number ", (_slideIndexNumber + 1).ToString, _
                                          " was clicked!", Environment.NewLine, Environment.NewLine, _
                                          "(Remember this is a zero-based sheet ID, PowerPoint recognises 1-based)"))
    What I see at my end is
    • an instance of Powerpoint opens full screen and in the taskbar to the 1st slide
    • Then all slides thumbnails appear on Form1's Panel1
    • No taskbar on thumbnails!


    Is it possible to Hide the instance of powerpoint altogether ?

    I used to be able to do this in VBA but I'll try and remember the code.

    I am in the process of testing it on a system without Office Installed - with just POwerpointViewer2007 installed.

    Just outstanding - you're breaking ground. Thanks again.
    Last edited by Xancholy; Jul 19th, 2008 at 09:35 AM.

  31. #31

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Here's something. Try using this in line 73- pp instance still opens but hides the presentation
    Code:
    .Presentations.Open(PowerPointFileName, WithWindow:=False)
    Commenting out line 72 prevents the instance of PP from appearing onscreen & in the taskbar but code works perfectly.

    Code:
    '.Visible = localMSOTriState.msoFalse
    Can this code work on systems without POwerpoint installed but with PowerpointViewer2007 installed ? No it can't. I tried it & it will generate exception "cannot create activex object' on line 68
    Code:
    newPowerPointInstance = CreateObject("PowerPoint.Application")
    Last edited by Xancholy; Jul 21st, 2008 at 08:51 AM.

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Alex, have you been able to take a look at powerpointviewer2007 ? Is there any way to embed it on our form and achieve the same results as above ?

  33. #33
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    Sorry just managed to get back around to this thread.

    I've tried searching the Internet for this but with no luck. I would try searching your hard drive for ppview or powerpointview - or perhaps right clicking the shortcut menu item pointing to the powerpoint viewer to look at what the name of the file is, then try using this within the CreateObject() call. This would definitely tell you whether you can code against the viewer or not and therefore whether that above sample works with the viewer rather than just the full version.

    I wouldn't mind knowing the answer to this also if you could post the result when you've tried it. I guess if the code library accessing features aren't possible with the viewer, the last resorts as I see it are to have a pre-requitsite of your program's install to be for the user to have powerpoint installed, or to use an expensive component such as the above which utilises the powerpoint file format.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Thanks Alex. Most of the components I have bought/tried still require powerpoint to exist on end user's machine.

    I have seen it done where powerpoint viewer is used instead of PP where it is not available and that's why I'm pursuing this.

  35. #35
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Re: [2008] Display powerpoint slides on form and run slides from form

    Hi Xancholy

    I'm working on a simular project/problem. Have you found any solution on how to use PowerPoint Viewer?

    Thanks

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Not yet Mads. Alex's solution works great when PP exists on end user system.

    I have not found any 3rd party solution that displays ppts when PP does not exist.

    Automating PP Viewer2007 to display slides is not a problem. Creating a slidesorter preview on a form using PP Viewer 2007 is my objective. Let me know if you find anything.

  37. #37
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: [2008] Display powerpoint slides on form and run slides from form

    Have either of you found what the PowerPoint viewer executable name is (which might differ between versions) as described above? Have either of you tried using this filename (possibly with the path also, in the format "C:\FileName.exe") with the above code at this line (in replace of the "PowerPoint.Application" string):
    Code:
    CreateObject("PowerPoint.Application")
    @Xancholy: You never actually said you'd tried this , I was waiting for a reply to see whether the CreateObject call works and therefore the viewer could be automated.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  38. #38
    New Member
    Join Date
    Jul 2008
    Posts
    2

    Re: [2008] Display powerpoint slides on form and run slides from form

    Hi again

    I found a solution to my problem... I don't know if this is something that might help you to Xancholy? But I managed to start the PP Viewer inside a form/panel and displaying a pps file...


    vb Code:
    1. Public Sub OpenPPViewerInForm()
    2.         Dim ppviewer As String = "C:\Program Files\Microsoft Office\PowerPoint Viewer\PPTVIEW.EXE"
    3.         Dim MyPSI As New ProcessStartInfo(ppviewer)
    4.         MyPSI.Arguments = " c:\Test\presentation.pps /S"
    5.         Dim MyProcess As Process = Process.Start(MyPSI)
    6.         MyProcess.WaitForInputIdle()
    7.         SetParent(MyProcess.MainWindowHandle, Panel1.Handle)
    8.     End Sub

  39. #39

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    Thanks very much for sharing Mads.

    Can anyone with more knowledge than me show us how to use Mads method to display ALL slides in a form.

  40. #40

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Display powerpoint slides on form and run slides from form

    One thing to note is that Powerpoint Viewer 2007 saves it's exe in
    Code:
    C:\Program Files\Microsoft Office\Office12\PPTVIEW.EXE
    I need to verify where it gets saved using Office 2000/2007. Anyone ?

    Code:
    Public Class Form1
    
        Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim ppviewer As String = "C:\Program Files\Microsoft Office\Office12\PPTVIEW.EXE"
            Dim MyPSI As New ProcessStartInfo(ppviewer)
            MyPSI.Arguments = "c:\mypowerpoint.ppt /s"
            Dim MyProcess As Process = Process.Start(MyPSI)
            MyProcess.WaitForInputIdle()
            SetParent(MyProcess.MainWindowHandle, Panel1.Handle)
        End Sub
    
    End Class
    In the above code the powerpoint viewer window shows up in the taskbar. Is there any way to avoid that happening ?

    Also is there a way to autosize the powerpoint slide so that it fits within Panel1 ?
    Last edited by Xancholy; Aug 1st, 2008 at 03:00 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width