Results 1 to 23 of 23

Thread: [02/03] View Powerpoint Show in VB Form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Question [02/03] View Powerpoint Show in VB Form

    Hi,

    I am trying to view a powerpoint show in a form...

    I could make this work fine in VB6 but after bringing the code over to VS 2003 I have an issue with hWnd control.

    I know that hwnd has changed to .handle now, but it is still not working correctly!

    Code:
    Const APP_NAME = "Powerpoint"
        Const ppShowTypeSpeaker = 1
        Const ppShowTypeInWindow = 1000
        Const ppAdvanceOnTime = 2
    
        Public oPPTApp As Object
        Public oPPTPres As Object
    
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
        Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
        Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
        Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
        Private Function start_show()
            Dim screenClasshWnd As Long
            On Error Resume Next
    
            oPPTApp = CreateObject("Powerpoint.Application")
            oPPTPres = oPPTApp.Presentations.Open("c:\demo.ppt", , , False)
    
            With oPPTPres
                With .Slides
                    With .Range
                        With .SlideShowTransition
                            .AdvanceOnTime = True
                        End With
                    End With
                End With
                With .SlideShowSettings
                    .ShowType = ppShowTypeSpeaker
                    .AdvanceMode = ppAdvanceOnTime
                    With .Run
                        .width = pptbox1.Width
                        .height = pptbox1.Height
                    End With
                End With
                screenClasshWnd = FindWindow("screenClass", 0&)
                SetParent(screenClasshWnd, pptbox1.Handle.ToInt32)
            End With
        End Function
    I think the issue is to do with the hwnd parameters in the private declare functions, but I dont know what to change them to??

    Any ideas?

    Thanks

    ps.. pptbox1 is a groupbox (which i think is the same ad the frame in vb6)

    Jono

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] View Powerpoint Show in VB Form

    Windows API functions almost universally expect 32-bit values. In VB6 the Long type is 32 bits wide and the Integer type is 16 bits wide. In VB.NET the Long type is 64 bits wide and the Integer type is 32 bits wide. Where you used Longs in VB6 you should use Integers in VB.NET.

    That said, when you're dealing with handles in VB.NET you should use the IntPtr type, which is the type that the Control.Handle property returns.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Hi, thanks for the reply.

    I have changed all the longs, but there has been no difference!

    Any other things I can try?

    Thanks

    Jono

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] View Powerpoint Show in VB Form

    What actually happens when you run the code?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    It loads the presentation, but the presentation does not load into the groupbox as it should!!

    This worked fine in vb6!

    Jono

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] View Powerpoint Show in VB Form

    I wonder if you could say again that it worked in VB6?

    Show us your exact code so we can test it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Well obviously the VB.NET Code wont work in VB6....

    Here is the project so far

    There is also a powerpoint called demo.ppt in the zip - that is the file I am testing with!

    Jono
    Attached Files Attached Files

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] View Powerpoint Show in VB Form

    I realise that the VB.NET code won't work in VB6. I was implying that your saying over and over that this used to work in VB6 was irrelevant and unnecessary. I was also thinking that you'd post the relevant code directly, like in your first post.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Sorry I thought you ment you wanted to see the whole project!

    The code in the first post is pretty much what I am using, except I have changed the longs to integers as suggested.

    Jono

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Any idea on this?

    Thanks

    Jono

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Hello?

    Any help with this???

    Jono

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

    Re: [02/03] View Powerpoint Show in VB Form

    I see you have Option Strict Off which will make for the possibilities of more errors due to casting issues. But I browsed the code and you need to remove the "On Error Resume Next" VB 6 legacy code error handler as in .NET you should use a Try Catch error code block.

    The SetParent API is not declared correctly.

    Code:
    Option Explicit On
    Option Strict On
    
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
    	'Declare your constants as Integer instead.
    	Const APP_NAME  As String = "Powerpoint"
    	Const ppShowTypeSpeaker As Integer = 1
    	Const ppShowTypeInWindow As Integer = 1000
    	Const ppAdvanceOnTime As Integer = 2
    
    	<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
    	Private Shared Function FindWindow( _
    	 ByVal lpClassName As String, _
    	 ByVal lpWindowName As String) As IntPtr
    	End Function
    
    	<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="SetParent")> _
    	Private Shared Function SetParent( _
    	 ByVal hWndChild As IntPtr, _
    	 ByVal hWndNewParent As IntPtr) As Integer
    	End Function
    
    	Private Function start_show()
    		'Blah
    	End Sub
    End Class
    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

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Thanks for the advice RobDog888,

    I have tryed this but get this error:

    C:\...\Form1.vb(164): Value of type 'Integer' cannot be converted to 'System.IntPtr'.

    Which refers to the line:

    Code:
    SetParent(screenClasshWnd, pptbox1.Handle.ToInt32)
    it does not like the pptbox1.Handle.ToInt32 - is there something else I should put there?

    Also I get lots of errors if I put Option Strict On!

    Thanks

    Jono

  14. #14
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [02/03] View Powerpoint Show in VB Form

    Quote Originally Posted by jono_m
    C:\...\Form1.vb(164): Value of type 'Integer' cannot be converted to 'System.IntPtr'.

    Which refers to the line:

    Code:
    SetParent(screenClasshWnd, pptbox1.Handle.ToInt32)
    it does not like the pptbox1.Handle.ToInt32 - is there something else I should put there?
    I thought jmcilhinney mentioned that Control.Handle was an IntPtr. If this is true, then you shouldn't be converting it to an Int32. So you would use this instead:
    Code:
    SetParent(screenClasshWnd, pptbox1.Handle)
    Quote Originally Posted by jono_m
    Also I get lots of errors if I put Option Strict On!
    That means you're not using types, methods and classes correctly. You really should leave it on and fix the errors otherwise odd bugs that are almost impossible to track down can crop up due to typing issues.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    kasracer,

    Thanks for pointing that out... I must have mis-read his post!

    Ok.. that error is gone now, but the presentation still wont go into the control.

    I will go through and try to correct all errors generated by having option stricty on and see if that helps..

    Any other ideas would be good,

    Thanks

    Jono

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

    Re: [02/03] View Powerpoint Show in VB Form

    Just use "pptbox1.Handle" as I declared the API correctly with the argument of an IntPtr so no conversion is needed with the .ToInt32.
    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
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    I did that and i dont get an error now, however the powerpoint presentation still does not appear inside the groupbox!

    Jono

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

    Re: [02/03] View Powerpoint Show in VB Form

    Well thats because you were supressing it and didnt know if you even had an error.

    What is the error message?
    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
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Errors:

    1) C:\...\Form1.vb(141): Option Strict On requires all function and property declarations to have an 'As' clause.
    2) C:\...\Form1.vb(145): Option Strict On disallows late binding.
    3) C:\...\Form1.vb(148): Option Strict On disallows late binding.
    4) C:\...\Form1.vb(155): Option Strict On disallows late binding.
    5) C:\...\Form1.vb(167): Option Strict On disallows late binding.

    Code:
        Private Function start_show()    ' Error 1 
            Dim screenClasshWnd As IntPtr
    
            oPPTApp = CreateObject("Powerpoint.Application")
            oPPTPres = oPPTApp.Presentations.Open("c:\demo.ppt", , , False)  ' Error 2
    
            With oPPTPres 
                With .Slides     ' Error 3                
                   With .Range
                        With .SlideShowTransition
                            .AdvanceOnTime = True
                        End With
                    End With
                End With
                With .SlideShowSettings    ' Error 4
                    .ShowType = ppShowTypeSpeaker
                    .AdvanceMode = ppAdvanceOnTime
                    With .Run
                        .width = pptbox1.Width
                        .height = pptbox1.Height
                    End With
                End With
                screenClasshWnd = FindWindow("screenClass", 0&)
                SetParent(screenClasshWnd, pptbox1.Handle)
            End With
    
            oPPTPres.Saved = True  ' Error 5
        End Function
    How do i fix this??

    Thanks

    Jono

  20. #20
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [02/03] View Powerpoint Show in VB Form

    Well, for Error #1 I suggest taking a look at creating Functions in VB.Net. Basically, you're not returning anything but Functions in VB.net must return a value.

    Instead, I believe you can change Function to Sub and it should work as expected. That or you can add the As Type at the top and return the Type (if you're returning anything that is).

    Not sure about the others.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

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

    Re: [02/03] View Powerpoint Show in VB Form

    A function needs to always return something or its not a function. Change to a sub if your not returning anything.

    For the rest you need to create new object variables for them and use Reflection as Late Binding doesnt let you access objects and properties more then a single level down. After fixing #1 you may switch back to Option Strict Off to solve it.
    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

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    17

    Re: [02/03] View Powerpoint Show in VB Form

    Ok, getting there!

    The powerpoint will now display inside the groupbox, but it will not resize to fit so I only see part of the powerpoint!

    I have specified the width & height to be that of the groupbox in the code.. is there something I have missed out?

    Jono

    --- Edit

    I think I might have worked out why it wont resize to the groupbox..

    It looks like the powerpoint might read the sizes differently, I know that vb.net deals with sizes in pixels, does anyone know what that translates to in the powerpoint?

    Jono
    Last edited by jono_m; Mar 5th, 2008 at 03:52 PM.

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

    Re: [02/03] View Powerpoint Show in VB Form

    Its because you have changed the parenting of PowerPoint which is not designed to be run in a container object like another form or form with a groupbox.

    What you are missing is more API code to set the location and size/width as once its placed inside another container its coordinated become relative to the containing object.

    Use GetWindowPlacement and SetWindowPlacement to properly position and size PowerPoint inside your Groupbox.
    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

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