Exemplo n.º 1
0
 public void Attach(IntPtr hwnd)
 {
     if (hwnd == IntPtr.Zero)
     {
         throw new ArgumentNullException("hwnd");
     }
     lock (_syncRoot)
     {
         if (_window != null)
         {
             throw new InvalidOperationException("Already attached!");
         }
         ErrorMessage = null;
         IsRendering  = false;
         _window      = CreateSubclassWindow(hwnd);
         _good.Clear();
         _isRunning           = true;
         _thread              = new Thread(RenderThreadProc);
         _thread.IsBackground = false;
         _thread.Start();
     }
 }
Exemplo n.º 2
0
        private SubclassWindow CreateSubclassWindow(IntPtr hwnd)
        {
            var window = new SubclassWindow(this);
            var failed = false;

            try
            {
                window.AssignHandle(hwnd);
                return(window);
            }
            catch (Exception ex)
            {
                failed       = true;
                ErrorMessage = string.Format("{0}: {1}", ex.GetType().Name, ex.Message);
                throw;
            }
            finally
            {
                if (failed)
                {
                    window.ReleaseHandle();
                }
            }
        }
Exemplo n.º 3
0
        public void Detach()
        {
            IsRendering = false;
            Thread         thread = null;
            SubclassWindow window = null;

            lock (_syncRoot)
            {
                window     = _window;
                _window    = null;
                thread     = _thread;
                _thread    = null;
                _isRunning = false;
            }
            // wait&release outside lock to avoid deadlock
            if (thread != null && thread.IsAlive)
            {
                thread.Join();
            }
            if (window != null)
            {
                window.ReleaseHandle();
            }
        }
Exemplo n.º 4
0
 public SubclassWindowRoot(SubclassWindow child)
 {
     _child = child;
 }