SuperPutty.ApplicationPanel.UpdateTitle C# (CSharp) Method

UpdateTitle() private method

private UpdateTitle ( ) : void
return void
        private void UpdateTitle()
        {
            ctlPuttyPanel panel = (ctlPuttyPanel)this.Parent;
            int length = NativeMethods.SendMessage(m_AppWin, NativeMethods.WM_GETTEXTLENGTH, 0, 0) + 1;
            StringBuilder sb = new StringBuilder(length + 1);
            NativeMethods.SendMessage(m_AppWin, NativeMethods.WM_GETTEXT, sb.Capacity, sb);
            string controlText = sb.ToString();
            string parentText = panel.TextOverride;

            switch ((SuperPutty.frmSuperPutty.TabTextBehavior)Enum.Parse(typeof(frmSuperPutty.TabTextBehavior), SuperPuTTY.Settings.TabTextBehavior))
            {
                case frmSuperPutty.TabTextBehavior.Static:
                    this.Parent.Text = parentText;
                    break;
                case frmSuperPutty.TabTextBehavior.Dynamic:
                    this.Parent.Text = controlText;
                    break;
                case frmSuperPutty.TabTextBehavior.Mixed:
                    this.Parent.Text = parentText + ": " + controlText;
                    break;
            }
            
            // putty/kitty tab became inactive
            if (!panel.inactive && controlText.EndsWith("TTY (inactive)")){
                Icon icon = null;
                string imageKey = (SuperPuTTY.Images.Images.ContainsKey("dead")) ? "dead" : null;
                try
                {
                    Image img = SuperPuTTY.Images.Images[imageKey];
                    Bitmap bmp = img as Bitmap;
                    if (bmp != null)
                    {
                        icon = Icon.FromHandle(bmp.GetHicon());
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error getting icon for dead tab", ex);
                }
                panel.inactive = true;
                panel.Icon = icon;                
                panel.AdjustMenu();  
                panel.Pane.Refresh();
            }
            else if (panel.inactive && !controlText.EndsWith("TTY (inactive)"))
            {
                panel.inactive = false;
                panel.Icon = SuperPuTTY.GetIconForSession(panel.Session);                
                panel.AdjustMenu();
                panel.Pane.Refresh();
            }
        }