By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,365 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,365 IT Pros & Developers. It's quick & easy.

.Net and API Problem

P: n/a
JK
HI

I have a application which is developed using VB.6.0
The application contains a Frame and Button. when the user click the button
then the existing powerpoint(path hot coded) will open and fit into the
frame
Its working perfectly. i have given the code. but when i convert to .net
(both C# and VB.net) the power point application not fit into the
frame(groupbox or panel)
herewith i am giving the both vb and vb.net code plese help me.

VB CODE ( working properly)
************************************************** **************************
***********

Option Explicit
Const APP_NAME = "PowerPoint in VB window"
Const ppShowTypeSpeaker = 1
Const ppShowTypeInWindow = 1000
Dim oPPTApp As PowerPoint.Application
Dim oPPTPres As PowerPoint.Presentation
Dim oPPTPresViewer As PowerPoint.Presentation
Private StrFolderPath As String
Private StrFileName As String

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As Any) 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 Sub LoadPowerPoint()

Dim screenClasshWnd As Long
On Error Resume Next
Dim MyFile
Dim oSld As Slide
Dim sFileName As String
Dim test As Integer

'StrFolderPath = InStr(1, StrFileName, "\")
'test = InStr(1, StrFileName, "\")
If Right(StrFolderPath, 1) <> "\" Then
StrFolderPath = StrFolderPath & "\"
End If
'If LCase(Right(StrFileName, 4)) <> ".ppt" Then
' StrFileName = StrFileName & ".ppt"
'End If
StrFolderPath = "C:\Works\test\"
StrFileName = "C:\Works\test\test.ppt"
If Not oPPTApp Is Nothing Then
Set oPPTPres = oPPTApp.Presentations.Open(StrFileName, , , False)
'Set oPPTPresViewer = oPPTApp.Presentations.Open(StrFileName, , , False)
If Not oPPTPres Is Nothing Then
' oPPTPresViewer.SlideShowSettings.ShowType = ppShowTypeKiosk
' oPPTPresViewer.SlideShowSettings.Run.Left = 768
' oPPTPresViewer.SlideShowSettings.Run
With oPPTPres
With .SlideShowSettings
.ShowType = ppShowTypeKiosk
With .Run
.Width = Frame1.Width
.Height = Frame1.Height
.Left = Frame1.Left - 230
End With
End With
screenClasshWnd = FindWindow("screenClass", 0&)
SetParent screenClasshWnd, Frame1.hWnd
Call SetWindowText(FindWindow("screenClass", 0&), APP_NAME)
End With
' For Each oSld In oPPTPres.Slides
' sFileName = (StrFolderPath) & "Slide" & _
' oSld.SlideIndex & ".jpg"
' ' oSld.Export sFileName, "JPG", ImgLeft.Width, ImgLeft.Height
' Next oSld
oPPTApp.ShowWindowsInTaskbar = msoFalse
Else
MsgBox "Could not open the presentation.", vbCritical, APP_NAME
End If
Else
MsgBox "Could not instantiate PowerPoint.", vbCritical, APP_NAME
End If
End Sub

Private Sub Command1_Click()
Call LoadPowerPoint
End Sub

Private Sub Form_Initialize()
With Me
.ScaleMode = vbPoints
.Caption = APP_NAME
End With

End Sub

Private Sub Form_Load()
Screen.MousePointer = 11
Set oPPTApp = CreateObject("PowerPoint.Application")
Me.DrawWidth = 5
Screen.MousePointer = 0
End Sub
************************************************** **************************
**********************************

VB.NET CODE

Set parent not working. so when you click inside the form powerpoint
application will be hide

Option Strict Off

Option Explicit On

Imports System.Runtime.InteropServices

Imports Microsoft.Office.Interop

Imports Microsoft.Office.Core

Public Class MainForm

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Panel1 As System.Windows.Forms.Panel

Friend WithEvents Button1 As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Panel1 = New System.Windows.Forms.Panel

Me.Button1 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Panel1

'

Me.Panel1.Location = New System.Drawing.Point(40, 24)

Me.Panel1.Name = "Panel1"

Me.Panel1.Size = New System.Drawing.Size(440, 296)

Me.Panel1.TabIndex = 37

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(176, 352)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 38

Me.Button1.Text = "Button1"

'

'MainForm

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(1016, 725)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.Panel1)

Me.MinimizeBox = False

Me.Name = "MainForm"

Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n

Me.Text = " PowerPoint Presentation"

Me.ResumeLayout(False)

End Sub

#End Region

Const APP_NAME As String = "PowerPoint in VB window"

Const GW_CHILD = 5

Dim mOldParent As Long

' PowerPoint Constants

Const ppShowTypeSpeaker As Integer = 1

Const ppShowTypeInWindow As Integer = 1000

Dim oPPTApp As PowerPoint.Application

Dim oPPTPres As PowerPoint.Presentation

Dim oPPTPresViewer As PowerPoint.Presentation

Private StrFolderPath As String

Private StrFileName As String

Dim windowHandle As IntPtr

Private ObjWindow As PowerPoint.SlideShowWindow
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal
hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal
ByValwCmd As Long) As Long

Private Sub LoadPowerPoint()

On Error Resume Next

Dim MyFile As Object

Dim oSld As PowerPoint.Slide

Dim sFileName As String

Dim test As Short

Dim screenClasshWnd As New IntPtr(0)

Dim hWndChild As IntPtr

StrFileName = "C:\Works\test\bin\Debug\test.ppt"

Dim IntVersionNo As Integer =
Convert.ToInt32(Math.Round(Convert.ToDouble(oPPTAp p.Version.ToString())))

If Not oPPTApp Is Nothing Then

oPPTPres = oPPTApp.Presentations.Open(StrFileName, , , False)

If Not oPPTPres Is Nothing Then

With oPPTPres

With .SlideShowSettings

..ShowType = PowerPoint.PpSlideShowType.ppShowTypeKiosk

ObjWindow = .Run

ObjWindow.Width = Panel1.Width

ObjWindow.Height = Panel1.Height

ObjWindow.Left = Panel1.Left

ObjWindow.Top = Panel1.Top

End With

End With

Select Case IntVersionNo

Case 8

'For PPT97:

screenClasshWnd = FindWindow("PP97FrameClass", Nothing)

Case 9

'For PPT2K:

screenClasshWnd = FindWindow("PP9FrameClass", Nothing)

Case 10

'For XP:

screenClasshWnd = FindWindow("PP10FrameClass", Nothing)

Case 11

'For 2003:

screenClasshWnd = FindWindow("PP11FrameClass", Nothing)

End Select

hWndChild = Me.Handle

SetParent(screenClasshWnd, hWndChild)

Me.Activate()

oPPTPres.SlideShowSettings.Run()

oPPTApp.ShowWindowsInTaskbar = MsoTriState.msoFalse

Else

MsgBox("Could not open the presentation.", MsgBoxStyle.Critical, APP_NAME)

End If

Else

MsgBox("Could not instantiate PowerPoint.", MsgBoxStyle.Critical, APP_NAME)

End If

End Sub

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

oPPTApp = New PowerPoint.Application

Me.TopMost = False

End Sub

Private Sub MainForm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

Dim IsCancel As Boolean = e.Cancel

On Error Resume Next

System.Windows.Forms.Application.DoEvents()

If Not oPPTPres Is Nothing Then

oPPTPres.Close()

End If

If Not oPPTPresViewer Is Nothing Then

oPPTPresViewer.Close()

End If

oPPTPres = Nothing

oPPTPresViewer = Nothing

If Not oPPTApp Is Nothing Then

oPPTApp.Quit()

End If

oPPTApp = Nothing

e.Cancel = IsCancel

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

LoadPowerPoint()

End Sub

End Class


Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.