Click here to Skip to main content
Click here to Skip to main content

Word Control for .NET

, 28 Jan 2003 GPL3
Rate this:
Please Sign up or sign in to vote.
Writing a control to use MS-Word in your own Application like a windows-form.
<!-- Download Links --> <!-- Article image -->

Sample Image - winwordcontrol.jpg

<!-- Add the rest of your HTML here -->


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 afterwards. 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 winwordcontrol.dll.  The steps are:

  1. Goto your Toolbox.

    Visual Studio Toolbox

  2. Click right. Select "Customize Toolbox".

    Toolbox Cutomizing

  3. Select the ".NET Components" tab.
  4. Select the winwordcontrol.dll using the file browse dialog. Click OK. After that you will find a new form in your toolbox called "winwordcontrol".

    Toolbox winwordcontrol/winwordcontrol

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:

winwordcontrolinstance.LoadDocument(<string path>); 
With LoadDocument 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 LoadDocument() can handle multiple calls without calling CloseControl() before.
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(
	int hWnd, 
	int X, 
	int Y, 
	int nWidth, 
	int nHeight, 
	bool bRepaint
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 FindWindow 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,
	this.Bounds.Width-20, this.Bounds.Height-20,
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 If you use this stuff or if you use just parts of it, I would appreciate if you mention my name. Wink | ;-)


  • 23.01.03 First release
  • 25.01.03 Update minor changes (performance enhancement)


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Matthias Hänel
Germany Germany
I am a developer with a Computer Science degree. I am programming Visual C ++ for over 7 year now and C# for about 3 years. If you want to know more about me please look at my homepage:

Comments and Discussions

AnswerRe: what is the handleName for Excel & Powerpoint? Pinmembergery12812-May-10 20:41 
GeneralRe: what is the handleName for Excel & Powerpoint? Pinmembergery1283-Aug-10 0:48 
QuestionSimilar control for Excel & Powerpoint Pinmembergery12810-May-10 3:45 
AnswerRe: Similar control for Excel & Powerpoint Pinmemberyltsa10-Aug-11 6:07 
Generalwinwordcontrol.dll without Office Pinmemberrarobbi3-Dec-09 6:24 
GeneralRe: winwordcontrol.dll without Office PinmemberRick Pingry30-Dec-09 15:41 
Questionlost form control after enter word doc. PinmemberMember 16519299-Sep-09 18:24 
AnswerRe: lost form control after enter word doc. PinmemberRick Pingry30-Dec-09 15:49 
I am doing some similar things by enclosing WORD in an ActiveX control that can be displayed on a web page. The original version of the control I am writing was written using the DSOFRAMER example provided by Microsoft, but like everyone using DSOFRAMER, we ran into lots of problems, so I started over using a technique similar to this one.
We ran into focus issues as well and found that we had to make sure to do a few things:
1. Change the style for the window to include WS_CHILD
2. Hook the application so we could get a callback on WORD's thread and set Word's parent window there as well as in the thread for your application.
3. Handle WM_SetFocus messages from the parent window and pass them down to the word window
4. Handle WM_PARENTNOTIFY messages with WM_LBUTTONDOWN as the inner message and call SetFocus on the WORD window (unless the WORD window or a child thereof already has focus).
I am working in C++ (My ActiveX component is written in MFC C++)
I am not quite sure how to do some of this stuff in C#, but it seems like you have access to the Win32 library, so it should be good. You just have to write you little hook DLL in C++.
Good Luck
GeneralStrange Fixes to Strange Problem PinmemberMember 361548728-May-09 17:23 
GeneralRe: Strange Fixes to Strange Problem Pinmemberweilidai200124-Jan-11 3:45 
GeneralRe: Strange Fixes to Strange Problem Pinmemberweilidai200124-Jan-11 3:51 
GeneralThanks! [modified] PinmemberMember #568413511-Mar-09 4:24 
GeneralHtml PinmemberMember 387334311-Mar-09 2:22 
GeneralIt doesn't work for Word 2003 Pinmemberfelixdisc3-Mar-09 8:02 
GeneralRe: It doesn't work for Word 2003 Pinmemberfelixdisc4-Mar-09 7:55 
GeneralAnother approach using standard .NET Webbrowser component PinmemberHoward Jachter13-Jan-09 14:59 
GeneralRe: Another approach using standard .NET Webbrowser component PinmemberBen Robbins4-Feb-09 22:27 
GeneralRe: Another approach using standard .NET Webbrowser component PinmemberHoward Jachter4-Feb-09 22:53 
GeneralRe: Another approach using standard .NET Webbrowser component PinmemberHoward Jachter4-Feb-09 23:02 
Questioncan i use this control in web form Pinmemberbhushannankar2-Jan-09 20:28 
Questionhow to disable all toolbar PinmemberMember 357101322-Sep-08 17:43 
AnswerRe: how to disable all toolbar Pinmemberwhylazy21-Oct-12 17:49 
QuestionCan't Find Winwirdcontroll in the list PinmemberJimilybibilybob19-Apr-08 9:57 
QuestionCommandBars Error Pinmemberswje8-Apr-08 0:19 
GeneralVC++.NET 2003 and word [modified] Pinmemberminad_78611-Sep-07 1:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 29 Jan 2003
Article Copyright 2003 by Matthias Hänel
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid