示例#1
0
文件: Form1.cs 项目: mxiao666/CPShell
        private void timer1_Tick(object sender, EventArgs e)
        {
            IntPtr    active  = GetForegroundWindow();
            ArrayList keyList = new ArrayList();

            foreach (string key1 in m_window.Keys)
            {
                keyList.Add(key1);
            }
            foreach (string key in keyList)
            {
                WindowConnection winConnection = (WindowConnection)m_window[key];
                if (winConnection.hWnd == active)
                {
                    if (winConnection.hWnd != m_lastWin)
                    {
                        m_lastWin = winConnection.hWnd;
                    }
                    tabControl1.SelectedTab = winConnection.tabPage;
                }
                else if (IsWindow(winConnection.hWnd) == 0)
                {
                    m_lastWin = IntPtr.Zero;
                    tabControl1.TabPages.Remove(winConnection.tabPage);
                    m_window.Remove(key);
                }
            }
        }
示例#2
0
文件: Form1.cs 项目: mxiao666/CPShell
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            WindowConnection win   = getLastWindow();
            string           param = "";

            if (win != null)
            {
                if (win.connection.password.Trim() != "")
                {
                    param = String.Format("scp://{0}:\"{1}\"@{2}:{3}",
                                          win.connection.username,
                                          win.connection.password,
                                          win.connection.ip,
                                          win.connection.port
                                          );
                }
                else
                {
                    param = String.Format("scp://{0}@{1}:{2}",
                                          win.connection.username,
                                          win.connection.ip,
                                          win.connection.port
                                          );
                }
                if (win.connection.keyfile.Trim() != "")
                {
                    param = param + " /privatekey=" + win.connection.keyfile;
                }
                string  installPath = @"WinSCP.exe";
                Process process     = Process.Start(installPath, param);
            }
        }
示例#3
0
文件: Form1.cs 项目: llnuaa/CPShell
 private void resizeConnection()
 {
     this.splitContainer2.Visible = false;
     try
     {
         ArrayList keyList = new ArrayList();
         foreach (string key1 in m_window.Keys)
         {
             keyList.Add(key1);
         }
         foreach (string key in keyList)
         {
             WindowConnection winConnection = (WindowConnection)m_window[key];
             if (IsWindow(winConnection.hWnd) != 0)
             {
                 ShowWindow(winConnection.hWnd, 1);
                 ShowWindow(winConnection.hWnd, 3);
             }
         }
     }
     catch (Exception)
     {
     }
     this.splitContainer2.Visible = true;
 }
示例#4
0
文件: Form1.cs 项目: llnuaa/CPShell
        private void splitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WindowConnection winConnection = getLastWindow();

            if (winConnection != null)
            {
                if (this.splitContainer2.Panel2Collapsed)
                {
                    //unv-> ver
                    this.splitContainer2.Panel2Collapsed = false;
                }
                try
                {
                    if (winConnection.panel == "panel1")
                    {
                        SetParent(winConnection.hWnd, this.splitContainer2.Panel2.Handle);
                        winConnection.panel = "panel2";
                    }
                    else
                    {
                        SetParent(winConnection.hWnd, this.splitContainer2.Panel1.Handle);
                        winConnection.panel = "panel1";
                    }
                    resizeConnection();
                }
                catch (Exception exp) {
                }
            }
        }
示例#5
0
文件: Form1.cs 项目: mxiao666/CPShell
        private void layoutButton_Click(object sender, EventArgs e)
        {
            try
            {
                int index  = 0;
                int count  = m_window.Keys.Count;
                int width  = 0;
                int height = 0;
                switch (count)
                {
                case 2:
                    width  = this.Width - this.treeView1.Width - 10;
                    height = (this.Height - this.toolStrip1.Height - this.tabControl1.Height - 28) / 2;
                    foreach (string key1 in m_window.Keys)
                    {
                        WindowConnection windowData = (WindowConnection)m_window[key1];
                        ShowWindow(windowData.hWnd, 1);
                        MoveWindow(windowData.hWnd, 0, index * height, width, height, true);
                        index++;
                    }
                    break;

                case 3:
                    width  = (this.Width - this.treeView1.Width - 10) / 2;
                    height = (this.Height - this.toolStrip1.Height - this.tabControl1.Height - 28) / 2;
                    foreach (string key1 in m_window.Keys)
                    {
                        WindowConnection windowData = (WindowConnection)m_window[key1];
                        ShowWindow(windowData.hWnd, 1);
                        MoveWindow(windowData.hWnd, index % 2 * width, index / 2 * height, (index / 2 + 1) * width, height, true);
                        index++;
                    }
                    break;

                case 4:
                    width  = (this.Width - this.treeView1.Width - 10) / 2;
                    height = (this.Height - this.toolStrip1.Height - this.tabControl1.Height - 28) / 2;
                    foreach (string key1 in m_window.Keys)
                    {
                        WindowConnection windowData = (WindowConnection)m_window[key1];
                        ShowWindow(windowData.hWnd, 1);
                        MoveWindow(windowData.hWnd, index % 2 * width, index / 2 * height, width, height, true);
                        index++;
                    }
                    break;

                default:
                    foreach (string key1 in m_window.Keys)
                    {
                        WindowConnection windowData = (WindowConnection)m_window[key1];
                        ShowWindow(windowData.hWnd, 1);
                    }
                    break;
                }
            }
            catch (Exception exp)
            {
            }
        }
示例#6
0
文件: Form1.cs 项目: llnuaa/CPShell
        private void copyActive(object sender, EventArgs e)
        {
            WindowConnection windowdata = (WindowConnection)m_window[tabControl1.TabPages[tabControl1.SelectedIndex].Text];

            if (windowdata != null)
            {
                createNewConnection(windowdata.connection);
            }
        }
示例#7
0
文件: Form1.cs 项目: llnuaa/CPShell
        private void closeActive(object sender, EventArgs e)
        {
            WindowConnection windowdata = (WindowConnection)m_window[tabControl1.TabPages[tabControl1.SelectedIndex].Text];

            if (windowdata != null)
            {
                SendMessage(windowdata.hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
            }
        }
示例#8
0
文件: Form1.cs 项目: mxiao666/CPShell
 private void tabControl1_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedIndex != -1)
     {
         WindowConnection windowData = (WindowConnection)m_window[tabControl1.TabPages[tabControl1.SelectedIndex].Text];
         if (windowData != null)
         {
             SetForegroundWindow(windowData.hWnd);
             m_lastWin = windowData.hWnd;
         }
     }
 }
示例#9
0
文件: Form1.cs 项目: mxiao666/CPShell
 private WindowConnection getLastWindow()
 {
     try
     {
         foreach (string key1 in m_window.Keys)
         {
             WindowConnection windowData = (WindowConnection)m_window[key1];
             if (windowData.hWnd == m_lastWin)
             {
                 return(windowData);
             }
         }
     }
     catch (Exception exp)
     {
     }
     return(null);
 }
示例#10
0
文件: Form1.cs 项目: llnuaa/CPShell
        private bool isOnePanelBlank(string panel1, string panel2)
        {
            bool panel1Blank = true;
            bool panel2Blank = true;

            try
            {
                ArrayList keyList = new ArrayList();
                foreach (string key1 in m_window.Keys)
                {
                    keyList.Add(key1);
                }
                foreach (string key in keyList)
                {
                    WindowConnection winConnection = (WindowConnection)m_window[key];
                    if (winConnection.panel == panel1)
                    {
                        panel1Blank = false;
                    }
                    else if (winConnection.panel == panel2)
                    {
                        panel2Blank = false;
                    }
                }
            }
            catch (Exception)
            {
            }
            if (panel1 == "")
            {
                return(panel2Blank);
            }
            else if (panel2 == "")
            {
                return(panel1Blank);
            }
            if (panel1Blank || panel2Blank)
            {
                return(true);
            }
            return(false);
        }
示例#11
0
文件: Form1.cs 项目: llnuaa/CPShell
 private void movePanel2ToPanel1()
 {
     try
     {
         ArrayList keyList = new ArrayList();
         foreach (string key1 in m_window.Keys)
         {
             keyList.Add(key1);
         }
         foreach (string key in keyList)
         {
             WindowConnection winConnection = (WindowConnection)m_window[key];
             if (winConnection.panel == "panel2")
             {
                 SetParent(winConnection.hWnd, this.splitContainer2.Panel1.Handle);
                 winConnection.panel = "panel1";
             }
         }
     }
     catch (Exception)
     {
     }
 }
示例#12
0
文件: Form1.cs 项目: llnuaa/CPShell
        private void timer1_Tick(object sender, EventArgs e)
        {
            IntPtr    active  = GetForegroundWindow();
            ArrayList keyList = new ArrayList();

            foreach (string key1 in m_window.Keys)
            {
                keyList.Add(key1);
            }
            foreach (string key in keyList)
            {
                WindowConnection winConnection = (WindowConnection)m_window[key];
                if (winConnection.hWnd == active)
                {
                    if (winConnection.hWnd != m_lastWin)
                    {
                        m_lastWin = winConnection.hWnd;
                    }
                    tabControl1.SelectedTab = winConnection.tabPage;
                }
                else if (IsWindow(winConnection.hWnd) == 0)
                {
                    m_lastWin = IntPtr.Zero;
                    tabControl1.TabPages.Remove(winConnection.tabPage);
                    m_window.Remove(key);
                }
            }
            if (!this.splitContainer2.Panel2Collapsed)
            {
                if (isOnePanelBlank("panel1", "panel2"))
                {
                    movePanel2ToPanel1();
                    this.splitContainer2.Panel2Collapsed = true;
                    resizeConnection();
                }
            }
        }
示例#13
0
文件: Form1.cs 项目: mxiao666/CPShell
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            TreeNode node = this.treeView1.SelectedNode;

            if (node == null)
            {
                return;
            }
            ConnectionData puttyData = (ConnectionData)m_server[node.Text];

            if (puttyData != null)
            {
                createNewConnection(puttyData);
                return;
            }

            WindowConnection windowData = (WindowConnection)m_window[node.Text];

            if (windowData != null)
            {
                SetForegroundWindow(windowData.hWnd);
                m_lastWin = windowData.hWnd;
            }
        }
示例#14
0
文件: Form1.cs 项目: mxiao666/CPShell
        private void createNewConnection(ConnectionData puttyData)
        {
            string param = String.Format("-{0} -l {1} -P {2} {3}",
                                         puttyData.protocol.ToLower(),
                                         puttyData.username,
                                         puttyData.port,
                                         puttyData.ip);

            if (puttyData.protocol == "SSH" && puttyData.password.Trim() != "")
            {
                param = param + " -pw " + puttyData.password;
            }
            if (puttyData.keyfile.Trim() != "")
            {
                param = param + " -i " + puttyData.keyfile;
            }

            string  installPath = @"putty.exe";
            Process process     = Process.Start(installPath, param);

            process.WaitForInputIdle();

            // 嵌入到parentHandle指定的句柄中
            IntPtr appWin = process.MainWindowHandle;

            SetParent(appWin, this.panel2.Handle);
            MoveWindow(appWin, 0, 0, 1024, 600, true);
            ShowWindow(appWin, 3);

            string windowName = (++m_windowIndex) + " - " + puttyData.name;

            TabPage tabPage = new System.Windows.Forms.TabPage();

            tabPage.Location = new System.Drawing.Point(0, 0);
            tabPage.Name     = windowName + "_1";
            tabPage.Padding  = new System.Windows.Forms.Padding(2);
            tabPage.Size     = new System.Drawing.Size(511, 0);
            tabPage.TabIndex = 1;
            tabPage.Text     = windowName;
            tabPage.UseVisualStyleBackColor = true;
            this.tabControl1.TabPages.Add(tabPage);

            WindowConnection winConnection = new WindowConnection(windowName, puttyData, appWin, tabPage);

            m_window[windowName] = winConnection;
            m_lastWin            = appWin;

            if (puttyData.quickType == null)
            {
                return;
            }

            if (puttyData.quickType != "Input Command")
            {
                AfterLogin after = new AfterLogin(appWin,
                                                  puttyData.quickType,
                                                  this.m_quickDatas,
                                                  puttyData.waitTime);
                Thread nonParameterThread = new Thread(new ThreadStart(after.run));
                nonParameterThread.Start();
            }
            else if (puttyData.command != null && puttyData.command.Trim() != "")
            {
                AfterLogin after = new AfterLogin(appWin,
                                                  puttyData.command,
                                                  puttyData.waitTime);
                Thread nonParameterThread = new Thread(new ThreadStart(after.run));
                nonParameterThread.Start();
            }
        }