Здравствуйте, _gargon, Вы писали:
_>Здравствуйте, G0ga, Вы писали:
G>>Нет конечно и ссылка неравна NULL. Просто обращение к любому свойству окна вызывает System.Runtime.InteropServices.COMException.
_>Можеш привести код присоединения нативного окна?
public class ExternalApplication
{
#region "API usage declarations"
[DllImport("user32.dll")]
public static extern int FindWindow(string strclassName, string strWindowName);
[DllImport("user32.dll")]
public static extern int SetParent(int hWndChild, int hWndNewParent);
[DllImport("user32.dll")]
public static extern int GetParent(int hWndChild);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public 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")]
public static extern bool MoveWindow(
int hWnd,
int X,
int Y,
int nWidth,
int nHeight,
bool bRepaint
);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern Int32 ShowWindow(
Int32 hWnd,
Int32 nCmdShow
);
public const int MF_BYPOSITION = 0x400;
public const int MF_REMOVE = 0x1000;
public const Int32 SW_HIDE = 0;
public const Int32 SW_RESTORE = 9;
public const Int32 SWP_DRAWFRAME = 0x20;
public const Int32 SWP_NOMOVE = 0x2;
public const Int32 SWP_NOSIZE = 0x1;
public const Int32 SWP_NOZORDER = 0x4;
#endregion
public static int wordWnd = 0;
internal static Word.ApplicationClass _WordApplication = null;
public static Word.ApplicationClass WordApplication
{
get
{
if (ExternalApplication._WordApplication == null)
{
ExternalApplication._WordApplication = new Word.ApplicationClass();
if (wordWnd == 0) wordWnd = FindWindow("Opusapp", null);
ExternalApplication.SetParent(ExternalApplication.wordWnd, Thread.CurrentThread.ManagedThreadId);
_WordApplication.ApplicationEvents4_Event_Quit += new Microsoft.Office.Interop.Word.ApplicationEvents4_QuitEventHandler(ExternalApplication.OnQuit);
}
return ExternalApplication._WordApplication;
}
}
this.WordApplication.Visible = true;
this.WordApplication.DocumentBeforeClose += new Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(OnClose);
this.WordApplication.ApplicationEvents2_Event_Quit += new Microsoft.Office.Interop.Word.ApplicationEvents2_QuitEventHandler(OnQuit);
ExternalApplication.SetParent(ExternalApplication.wordWnd, this.Handle.ToInt32());
ExternalApplication.SetWindowPos(ExternalApplication.wordWnd, this.Handle.ToInt32(), 0, 0, this.Bounds.Width, this.Bounds.Height, ExternalApplication.SWP_NOZORDER | ExternalApplication.SWP_NOMOVE | ExternalApplication.SWP_DRAWFRAME | ExternalApplication.SWP_NOSIZE);