void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { //Log.DebugFormat("eventType={0}, hwnd={1}", eventType, hwnd); if (eventType == (int)NativeMethods.WinEvents.EVENT_OBJECT_NAMECHANGE && hwnd == m_AppWin) { // Putty xterm chdir - apply to title UpdateTitle(); } else if (eventType == (int)NativeMethods.WinEvents.EVENT_SYSTEM_SWITCHSTART) { this.isSwitchingViaAltTab = true; } else if (eventType == (int)NativeMethods.WinEvents.EVENT_SYSTEM_SWITCHEND) { this.isSwitchingViaAltTab = false; } else if (eventType == (int)NativeMethods.WinEvents.EVENT_SYSTEM_FOREGROUND && hwnd == m_AppWin) { // if we got the EVENT_SYSTEM_FOREGROUND, and the hwnd is the putty terminal hwnd (m_AppWin) // then bring the supperputty window to the foreground Log.DebugFormat("[{0}] HandlingForegroundEvent: settingFG={1}", hwnd, settingForeground); if (settingForeground) { settingForeground = false; return; } // This is the easiest way I found to get the superputty window to be brought to the top // if you leave TopMost = true; then the window will always be on top. if (this.TopLevelControl != null) { Form form = SuperPuTTY.MainForm; if (form.WindowState == FormWindowState.Minimized) { return; } DesktopWindow window = DesktopWindow.GetFirstDesktopWindow(); this.m_windowActivator.ActivateForm(form, window, hwnd); // focus back to putty via setting active dock panel ctlPuttyPanel parent = (ctlPuttyPanel)this.Parent; if (parent != null && parent.DockPanel != null) { if (parent.DockPanel.ActiveDocument != parent && parent.DockState == DockState.Document) { string activeDoc = parent.DockPanel.ActiveDocument != null ? ((ToolWindow)parent.DockPanel.ActiveDocument).Text : "?"; Log.InfoFormat("[{0}] Setting Active Document: {1} -> {2}", hwnd, activeDoc, parent.Text); parent.Show(); } else { // give focus back this.ReFocusPuTTY("WinEventProc-FG, AltTab=" + isSwitchingViaAltTab); } } } } }
void UpdateForeground() { // if we got the EVENT_SYSTEM_FOREGROUND, and the hwnd is the putty terminal hwnd (m_AppWin) // then bring the supperputty window to the foreground Log.DebugFormat("[{0}] HandlingForegroundEvent: settingFG={1}", m_AppWin, settingForeground); if (settingForeground) { settingForeground = false; return; } // This is the easiest way I found to get the superputty window to be brought to the top // if you leave TopMost = true; then the window will always be on top. if (this.TopLevelControl != null) { Form form = SuperPuTTY.MainForm; if (form.WindowState == FormWindowState.Minimized) { return; } DesktopWindow window = DesktopWindow.GetFirstDesktopWindow(); this.m_windowActivator.ActivateForm(form, window, m_AppWin); // focus back to putty via setting active dock panel ctlPuttyPanel parent = (ctlPuttyPanel)this.Parent; if (parent != null && parent.DockPanel != null) { if (parent.DockPanel.ActiveDocument != parent && parent.DockState == DockState.Document) { string activeDoc = parent.DockPanel.ActiveDocument != null ? ((ToolWindow)parent.DockPanel.ActiveDocument).Text : "?"; Log.InfoFormat("[{0}] Setting Active Document: {1} -> {2}", m_AppWin, activeDoc, parent.Text); parent.Show(); } else { // give focus back this.ReFocusPuTTY("WinEventProc-FG, AltTab=" + isSwitchingViaAltTab); } } } }