示例#1
0
            public override int SubClassProc(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, IntPtr dwRefData)
            {
                switch ((uint)msg)
                {
                case (uint)WM.SIZE:
                    var args = new SubClassingWindowEventArgs(lParam);
                    if (!_closing)
                    {
                        OnCallBackEvent(args);
                    }
                    break;

                case (uint)WM.SETFOCUS:
                    if (!_closing)
                    {
                        User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Hwnd, Hwnd);
                    }
                    break;

                case (uint)WM.KILLFOCUS:
                    if (!_closing)
                    {
                        User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Hwnd, IntPtr.Zero);
                    }
                    break;
                }
                return(base.SubClassProc(hWnd, msg, wParam, lParam, uIdSubclass, dwRefData));
            }
示例#2
0
        private void ShutdownAddIn()
        {
            var currentDomain = AppDomain.CurrentDomain;

            try
            {
                _logger.Log(LogLevel.Info, "Rubberduck is shutting down.");
                _logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events...");
                VBENativeServices.UnhookEvents();

                _logger.Log(LogLevel.Trace, "Broadcasting shutdown...");
                User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0));

                _logger.Log(LogLevel.Trace, "Releasing dockable hosts...");
                Windows.ReleaseDockableHosts();

                if (_app != null)
                {
                    _logger.Log(LogLevel.Trace, "Initiating App.Shutdown...");
                    _app.Shutdown();
                    _app = null;
                }

                if (_kernel != null)
                {
                    _logger.Log(LogLevel.Trace, "Disposing IoC container...");
                    _kernel.Dispose();
                    _kernel = null;
                }

                _isInitialized = false;
                _logger.Log(LogLevel.Info, "No exceptions were thrown.");
            }
            catch (Exception e)
            {
                _logger.Error(e);
                _logger.Log(LogLevel.Warn, "Exception is swallowed.");
                //throw; // <<~ uncomment to crash the process
            }
            finally
            {
                _logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
                currentDomain.AssemblyResolve    -= LoadFromSameFolder;
                currentDomain.UnhandledException -= HandlAppDomainException;
                _logger.Log(LogLevel.Trace, "Done. Initiating garbage collection...");
                GC.Collect();
                _logger.Log(LogLevel.Trace, "Done. Waiting for pending finalizers...");
                GC.WaitForPendingFinalizers();
                _logger.Log(LogLevel.Trace, "Done. Shutdown completed. Quack!");
                _isInitialized = false;
            }
        }
示例#3
0
 private static int EnumCallback(IntPtr hwnd, IntPtr lparam)
 {
     User32.SendMessage(hwnd, WM.RUBBERDUCK_SINKING, IntPtr.Zero, IntPtr.Zero);
     return(1);
 }
            public override int SubClassProc(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, IntPtr dwRefData)
            {
                switch ((uint)msg)
                {
                case (uint)WM.WINDOWPOSCHANGED:
                    var containerHwnd = GetParent(hWnd);
                    if (containerHwnd != _containerHwnd)
                    {
                        _containerHwnd = containerHwnd;
                        _windowState   = GetWindowState(_containerHwnd);
                    }
                    break;

                case (uint)WM.CONTEXTMENU:
                    if (_windowState == ToolWindowState.Undockable)
                    {
                        DisplayUndockableContextMenu(hWnd, lParam);
                    }
                    break;

                case (uint)WM.COMMAND:
                    switch (wParam.ToInt32())
                    {
                    case (int)WM.RUBBERDUCK_UNDOCKABLE_CONTEXT_MENU:
                        ToggleDockable(_vbeHwnd);
                        break;
                    }
                    break;

                case (uint)WM.SIZE:
                    var args = new SubClassingWindowEventArgs(lParam);
                    if (!_closing)
                    {
                        OnCallBackEvent(args);
                    }
                    break;

                case (uint)WM.SETFOCUS:
                    if (!_closing)
                    {
                        User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Hwnd, Hwnd);
                    }
                    break;

                case (uint)WM.KILLFOCUS:
                    if (!_closing)
                    {
                        User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Hwnd, IntPtr.Zero);
                    }
                    break;

                case (uint)WM.DESTROY:
                    if (_menuHandle != IntPtr.Zero)
                    {
                        if (!NativeMethods.DestroyMenu(_menuHandle))
                        {
                            _logger.Fatal($"Failed to destroy the menu handle {_menuHandle}");
                        }
                    }
                    break;
                }
                return(base.SubClassProc(hWnd, msg, wParam, lParam, uIdSubclass, dwRefData));
            }