WinForm 2.0 hosting Word 2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I used to have DSOFramer.ocx and I can very well host the Word 2003 when I
coded with VB.NET 2003. And the form had only 2 button other than hosting
Word.
First button for exit and second button was to save into SQL Server 2000.

Now I am mostly coding with VB.NET 2005 and I would like to learn if there
is a way to host Word 2003 in WindowsForm 2.0 (VB.NET 2005)?

Same ocx (DSOFramer.ocx ) will not work on VB.NET 2005. Does Microsoft have
any component for this problem?

Thank you for reading my post.

Rgds,
Niyazi
 
Niyazi,

If you start Word from yourApplication using the system.diagnostics.process
class

Then Set your application as Word.exe owner process
Use the API function Setparent
be sure to call API ShowWindow against Word.exe hwnd once it is in your form
so that it resizes, aligns and redraws.

You should now have the application sitting on your form like a control.

Now with it being a child window, I am not sure if you can access it's
WinProc or not but I am sure there is way overiding its close action.
 
Hi,

No Problem, happy new year:

This is only half the problem sovled, the easy half (This will make Word a
child window of your application) the harder bit, judging by what you are
saying, is you will need to "HOOK" the word window to intercept its close
messages.
There are plently of examples and code to do this but it is beyond what I
can help with as I am still new to .NET

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

hostWordApplication(Me)

End Sub

'--This loads Word 2000 (you may have to change FindWindow("OpusAPP",
vbNullString) to match the 'classwindow name of newer or older versions of
Word (I only have version 10 so can't test)
Module HostWord

Public Const SW_SHOWNORMAL = 1

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
(ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String,
ByVal lpsz2 As String) As Integer

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer,
ByVal wCmd As Integer) As Integer

Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer,
ByVal hWndNewParent As Integer) As Integer

Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer,
ByVal nCmdShow As Integer) As Integer

Public Word_Apllication As New Process

Sub hostWordApplication(ByVal frm As Form)

With Word_Apllication

..StartInfo.UseShellExecute = False

..StartInfo.FileName = "C:\Program Files\Microsoft
Office\Office10\WinWord.exe"

..Start()

End With

Dim WordHwnd As Integer

Application.DoEvents()

Do Until WordHwnd <> 0

'* wait for word to create it main window class

Application.DoEvents()

WordHwnd = FindWindow("OpusAPP", vbNullString)

Loop

'* set our form as its parent

SetParent(WordHwnd, frm.Handle)

frm.Text = WordHwnd.ToString

End Sub

End Module

Wish I could be more help

Regareds,

Michael.
 
Back
Top