This control allows you to use MS Word 2000 in your own projects such as a windows form. Of course
that's a little "dirty trick". But if you have some documentation to display and you want to use Word
for it, here is the solution.
I was working on an internal research project and we developed a tool to teach C++,
and there was a problem about how to display the exercises. The main problem was, I had difficult formulas
in these descriptions so the only possible solution was to convert the files to PDF or to another
file format. With PDF I had a problem, because I couldn't edit the documents
So, I was looking for an ActiveX or .NET control for MS Word. Finally, I couldn't find one.
So I decided to write one for .NET.
How to use the control?
It's almost too easy to use the form. You just need to add a link to the
The steps are:
- Goto your Toolbox.
- Click right.
Select "Customize Toolbox".
- Select the ".NET Components" tab.
- Select the
winwordcontrol.dll using the file browse dialog. Click OK.
After that you will find a new form in your toolbox called "
Drag and drop it just like any other form.
The only thing you should know is how to control it.
At this moment, there are four methods:
you can load all files Word can handle. Please
specify the complete path!
This is the only method that is probably useful for everyone.
All the other methods are not necessary for normal use.
This method closes the actual document.
This is mostly not necessary because
can handle multiple calls without calling
Preloading. This method should be used if you don't want to wait
in the main program until Word is finished starting.
Reactivates all the Menubars.
The control will automatically start Word if it's not already open and it will display the document.
How does this work?
The basic idea is to instantiate the Word application, as everybody knows, with:
wordInstance = new Word.Application();
Now we have the Word application in a separate window. How do we get this window in our control?
The answer is ... Win32 API.
We need to import some API functions from user32.dll as shown here:
public static extern int FindWindow(string strclassName, string strWindowName);
static extern int SetParent(int hWndChild, int hWndNewParent);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
static extern bool SetWindowPos(
int hWnd, // handle to window
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags // window-positioning options
[DllImport("user32.dll", EntryPoint = "MoveWindow")]
static extern bool MoveWindow(
const int SWP_DRAWFRAME = 0x20;
const int SWP_NOMOVE = 0x2;
const int SWP_NOSIZE = 0x1;
const int SWP_NOZORDER = 0x4;
This is the most complicated part... because it's NOT documented at all.
We need a Pointer to the Word window, so we use
to find it.
What's the name of the window? - "Opusapp"
Actually, I don't know what this name means, but it works perfectly.
wordWnd = FindWindow( "Opusapp", null);
So, now we can define our control as a parent to Word:
SetWindowPos(wordWnd, this.Handle.ToInt32(), 0, 0,
SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME );
Everything else should be pretty easy and it is well documented in the official documentation for the Word namespace.
Points of Interest
You may be interested in my other projects.
Please visit my private homepage www.intercompu.de.
If you use this stuff or if you use just parts of it, I would
appreciate if you mention my name. ;-)
- 23.01.03 First release
- 25.01.03 Update minor changes (performance enhancement)