问一句,你是调用还是直接嵌入?下面是直接嵌入的,你改改,这是我以前用到的
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WinWordControl
{
public class DocumentInstanceException : Exception
{}
public class ValidDocumentException : Exception
{}
public class WordInstanceException : Exception
{}
public class WinWordControl : System.Windows.Forms.UserControl
{
[DllImport("user32.dll")]
public static extern int FindWindow(string strclassName, string strWindowName);
[DllImport("user32.dll")]
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爃Wnd,
int X,
int Y,
int爊Width,
int爊Height,
bool燽Repaint
);
const int SWP_DRAWFRAME = 0x20;
const int SWP_NOMOVE = 0x2;
const int SWP_NOSIZE = 0x1;
const int SWP_NOZORDER = 0x4;
private Word.Document document;
private static Word.ApplicationClass wd = null;
public static int wordWnd = 0;
private static string filename = null;
private static bool deactivateevents = false;
///
/// needed designer variable
///
private System.ComponentModel.Container components = null;
public WinWordControl()
{
InitializeComponent();
}
///
/// cleanup Ressources
///
protected override void Dispose( bool disposing )
{
CloseControl();
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// !do not alter this code! It's designer code
///
private void InitializeComponent()
{
//
// WinWordControl
//
this.Name = "WinWordControl";
this.Size = new System.Drawing.Size(440, 336);
this.Resize += new System.EventHandler(this.OnResize);
}
#endregion
///
/// Preactivation
/// It's usefull, if you need more speed in the main Program
/// so you can preload Word.
///
public void PreActivate()
{
if(wd == null) wd = new Word.ApplicationClass();
}
///
/// Close the current Document in the control --> you can
/// load a new one with LoadDocument
///
public void CloseControl()
{
/*
* this code is to reopen Word.
*/
try
{
deactivateevents = true;
object dummy=null;
document.Close(ref dummy, ref dummy, ref dummy);
document.Application.Quit(ref dummy, ref dummy, ref dummy);
deactivateevents = false;
}
catch
{
}
}
///
/// catches Word's close event
/// starts a Thread that send a ESC to the word window ;)
///
///
///
private void OnClose(Word.Document doc, ref bool chancel)
{
if(!deactivateevents)
{
chancel=true;
}
}
///
/// catches Word's open event
/// just close
///
///
private void OnOpenDoc(Word.Document doc)
{
OnNewDoc(doc);
}
///
/// catches Word's newdocument event
/// just close
///
///
private void OnNewDoc(Word.Document doc)
{
if(!deactivateevents)
{
deactivateevents=true;
object dummy = null;
doc.Close(ref dummy,ref dummy,ref dummy);
deactivateevents=false;
}
}
///
/// catches Word's quit event
/// normally it should not fire, but just to be shure
/// safely release the internal Word Instance
///
private void OnQuit()
{
//wd=null;
}
在浏览器中,最大化播放窗口,都是用的重新打开一个窗口,你也可以这样。