Hello,
This is a programming challenge.
Language = VB.NET
I'm writing an application in VB.NET uses an MDI window.
I want to open up PowerPoint any other office applications as children
of the MDI window.
I'd like to be able to interface with the Office Windows as if they
are VB.NET Form.
------
What I'm looking for:
It would be PERFECT if I could actually use a VB.NET class
System.windows.Forms.Form to reference the existing PowerPoint Window.
So I could use all of the VB.NET Properties
and Functions, just as if the PowerPoint Window were a form I created.
Perfect Solution Example: PowerPointForm.MdiParent = MDIForm
Next-to-Perfect Solution Example:
dim ppApp as Microsoft.Office
Dim ppApp As New PowerPoint.Application
ppApp.Activate()
'SetMDIChild (ByVal hWndMDIChild As Long, ByVal hWndNewMDIParent As Long) as long
SetMDIChild (ppApp.HWND, MDIForm.Handle.ToInt32) as long
------
Where I'm at:
Currently, I've searched google and MSDN and VB.NET Studio and I've
found that VB.NET
supports Interop Services for their Office applications.
I've added references to
"Microsoft Excel 5.0 Object Library",
"Microsoft PowerPoint 11.0 Object Library",
"Microsoft Word 11.0 Object Library", and
"Office".
File : C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\office.dll
I now have access to Namespaces:
Microsoft.Office.Core
Microsoft.Office.Interop.PowerPoint
Microsoft.Office.Interop.Word
I am currently using the SetParent() windows API to set my MDI
Window as the parent for the Powerpoint application. The PowerPoint
Application is then OWNED by the MDIForm, but is not an MDI Child ...
I think.
' --- Start Code --------
Private Declare Function SetParent Lib "user32.dll" _
(ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Dim ppApp As New PowerPoint.Application
ppApp = CreateObject("PowerPoint.Application")
ppApp.Activate()
SetParent(ppApp.HWND, MDIForm.Handle.ToInt32)
' --- End Code --------
Now this all works well, but I STILL don't know how to set an existing
window as a child of my MDI window.
VB.NET supports
System.Windows.Forms.Form.isMDIContainer() as boolean ' To set a form
as a possible MDI Parent
System.Windows.Forms.Form.IsMdiChild() as boolean ' to set a form as an MDI Child
System.Windows.Forms.Form.MdiParent as Form ' to set the MDI
parent of a form
System.Windows.Forms.Form.MdiChildren as Form() ' to list the MDI
children of the MDIContainer
I looked for windows API such as:
SetMDIChild (ByVal hWndMDIChild As Long, ByVal hWndNewMDIParent As Long) as long
But I couldn't find any.
I've experimented with different ways to initialize the
PowerPoint/Word Applications, such as
' ----- Start Process Code ---------
Dim PathToPowerPoint As String = "C:\Program Files\Microsoft
Office\OFFICE11\POWERPNT.EXE"
Dim proc As New Process
'What file to run
proc.StartInfo.FileName = PathToPowerPoint
'Set the windows Style: optional
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal
' Just cause?
proc.StartInfo.UseShellExecute = True
'Start the new process
proc.Start()
' ----- End Code ---------
Then we can access the window handle with: proc.MainWindowHandle :
SetParent(proc.MainWindowHandle.ToInt32, MDIForm.Handle.ToInt32) ...
I tried this first, and then discovered that VB.NET supports interop
services for their Office Applications and I've been experimenting
with that since. |