Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded word doc in widows form

Status
Not open for further replies.

Denster

Programmer
Apr 9, 2001
198
GB
After much trial and error trying to get all the functionality of word into a windows form, decided the best approach is the api calls and parenting an instance of word to a panel control. Its more or less working but getting weird redraw issues and also having to close and reopen the active document for it to show at all
Heres a brief on the code
Code:
Private _wordHandle As IntPtr
Public Const GWL_STYLE = (-16)
Public Declare Function FindWindow Lib "User32.Dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function SetParent Lib "User32.Dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Long
Public Declare Function MoveWindow Lib "User32.Dll" (ByVal hwnd As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer
 
Dim parentHandle As IntPtr       
Dim doc As Word.Document
_wordInstance = CreateObject("Word.Application")
doc = _wordInstance.Documents.Open("c:\test\autotest.dot", False, False)
_wordHandle = FindWindow("OpusApp", _wordInstance.ActiveWindow.Caption & " - Microsoft Word")
parentHandle = uxWordContainer.Handle
SetParent(_wordHandle, parentHandle)
MoveWindow(_wordHandle, 0, 0, uxWordContainer.Width, uxWordContainer.Height, 1)
'Shouldnt need this but wont show without it
_wordInstance.Documents.Close(False)
_wordInstance.Documents.Open("c:\test\autotest.dot", False, False)

Im wondering if I need to do something else with the instance of word - any ideas?

 
In VB6 this was relatively straightforward.

Microsoft dropped support for OLE in .Net, however they did provide some sample (unsupported) code to allow programmers some limited sort of OLE for versions prior to (and I think including VB 2005). I used it quite often, however I believe that after some changes they made in .Net 2008, they dropped this code completely. At least I've not been able to find the webpage that had the code, and unfortunately with various machine changes etc. since I last used it, I can't find a copy of the code. I should also mention that the provided code was not without its problems, including sometimes freezing the hosted app when the host program was resized.
 
Ok thanks - You would think over the years Microsoft would want to make things easier for developers, not harder!
 
I've remembered what the name of the control was - DsoFramer

I've had a quick look and as I thought Microsoft have dropped it, but if you look more thoroughly that I have just done you might be able to find an alternative location. It's also possible that someone on CodeProject or CodePlex has written an alternative. It might also still be possible to embed Office applications in the WebBrowser control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top