473,473 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

.Net and API Problem

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
0 2793

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.