Re[7]: Скорость работы сборщика мусора
От: _gargon Украина  
Дата: 03.06.09 15:48
Оценка:
Здравствуйте, G0ga, Вы писали:

G>Здравствуйте, _gargon, Вы писали:


_>>Здравствуйте, G0ga, Вы писали:


G>>>Нет конечно и ссылка неравна NULL. Просто обращение к любому свойству окна вызывает System.Runtime.InteropServices.COMException.

_>>Можеш привести код присоединения нативного окна?

G>
G>public class ExternalApplication
G>{
G>#region "API usage declarations"

G>[DllImport("user32.dll")]
G>public static extern int FindWindow(string strclassName, string strWindowName);
G>[DllImport("user32.dll")]
G>public static extern int SetParent(int hWndChild, int hWndNewParent);
G>[DllImport("user32.dll")]
G>public static extern int GetParent(int hWndChild);
G>[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
G>public static extern bool SetWindowPos(
G>  int hWnd,               // handle to window
G>  int hWndInsertAfter,    // placement-order handle
G>  int X,                  // horizontal position
G>  int Y,                  // vertical position
G>  int cx,                 // width
G>  int cy,                 // height
G>  uint uFlags             // window-positioning options
G>);
G>[DllImport("user32.dll", EntryPoint = "MoveWindow")]
G>public static extern bool MoveWindow(
G>  int hWnd, 
G>  int X,
G>  int Y,
G>  int nWidth,
G>  int nHeight,
G>  bool bRepaint
G>);
G>[DllImport("user32.dll", EntryPoint = "ShowWindow")]
G>public static extern Int32 ShowWindow(
G>  Int32 hWnd,
G>  Int32 nCmdShow
G>);
G>public const int MF_BYPOSITION = 0x400;
G>public const int MF_REMOVE = 0x1000;
G>public const Int32 SW_HIDE = 0;
G>public const Int32 SW_RESTORE = 9;
G>public const Int32 SWP_DRAWFRAME = 0x20;
G>public const Int32 SWP_NOMOVE = 0x2;
G>public const Int32 SWP_NOSIZE = 0x1;
G>public const Int32 SWP_NOZORDER = 0x4;
G>#endregion

G>public static int wordWnd = 0;

G>internal static Word.ApplicationClass _WordApplication = null;
G>public static Word.ApplicationClass WordApplication
G>{
G>  get
G>  {
G>    if (ExternalApplication._WordApplication == null)
G>    {
G>      ExternalApplication._WordApplication = new Word.ApplicationClass();
G>      if (wordWnd == 0) wordWnd = FindWindow("Opusapp", null);
G>      ExternalApplication.SetParent(ExternalApplication.wordWnd, Thread.CurrentThread.ManagedThreadId);
G>      _WordApplication.ApplicationEvents4_Event_Quit += new Microsoft.Office.Interop.Word.ApplicationEvents4_QuitEventHandler(ExternalApplication.OnQuit);
G>    }
G>    return ExternalApplication._WordApplication;
G>  }
G>}
G>


G>
G>  this.WordApplication.Visible = true;
G>  this.WordApplication.DocumentBeforeClose += new Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(OnClose);
G>  this.WordApplication.ApplicationEvents2_Event_Quit += new Microsoft.Office.Interop.Word.ApplicationEvents2_QuitEventHandler(OnQuit);
G>  ExternalApplication.SetParent(ExternalApplication.wordWnd, this.Handle.ToInt32());
G>  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);
G>


Честно говоря мало, что понял, но что я понял:
В твоем приложении отображается окно (не главное), под которое ты создаеш вордовский документ и отображаеш его где-то в своем окне.
После закрытия твоего окна (не главного), в виде вызова метода Dispose, ты ни как не можеш заюзать вордовский ком-объект,
т.к. он какогото х кем то освободился?
Я правильно понимаю ?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.