Пример #1
0
        /// <summary>
        /// 消息处理
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == MSG_SHOWDIALOG)
            { // 显示对话框
                Form helper = null;

                // 从界面获取最新的IP地址,并检查
                IPAddress ip;
                string    strServer = this.db_ip_textBox.Text.Trim();
                if (IPAddress.TryParse(strServer, out ip) == false)
                {
                    this.Show();
                    this.WindowState = FormWindowState.Normal;

                    this.db_ip_textBox.Focus();
                    this.db_ip_textBox.SelectAll();
                    MainForm.ErrorMessage("数据库服务器地址为空或者格式不正确!");
                    return;
                }

                MySqlSetting.m_strDataSource = strServer;
                MainForm.m_tagTFSWindowInfo.m_strGroupName = this.group_name_comboBox.Text.Trim();
                if (MainForm.m_emFormType == FormType.Checkin)
                {
                    if (MainForm.m_tagTFSWindowInfo.m_hContentCtrl == IntPtr.Zero)
                    {
                        return;
                    }

                    helper = new CheckinHelperForm();
                }
                else if (MainForm.m_emFormType == FormType.Review)
                {
                    if (MainForm.m_tagTFSWindowInfo.m_hContentCtrl == IntPtr.Zero ||
                        MainForm.m_tagTFSWindowInfo.m_hIDCtrl == IntPtr.Zero ||
                        MainForm.m_tagTFSWindowInfo.m_hCheckinCtrl == IntPtr.Zero ||
                        MainForm.m_tagTFSWindowInfo.m_hCheckinDateCtrl == IntPtr.Zero)
                    {
                        return;
                    }

                    helper = new ReviewHelperForm();
                }

                WinAPI.Rect rect = new WinAPI.Rect();
                WinAPI.GetWindowRect(helper.Handle, out rect);
                int x  = (int)m.WParam - (rect.Right - rect.Left) / 2;
                int y  = (int)m.LParam - (rect.Bottom - rect.Top) / 2;
                int cx = rect.Right - rect.Left;
                int cy = rect.Bottom - rect.Top;
                WinAPI.SetWindowPos(helper.Handle, IntPtr.Zero /*HWND_TOP*/, x, y, cx, cy, 0x0040 /*SWP_SHOWWINDOW*/);

                helper.Show();
                WinAPI.SetActiveWindow(helper.Handle);
                WinAPI.SetForegroundWindow(helper.Handle);
            }
        }
Пример #2
0
        /// <summary>
        /// 按键处理线程函数
        /// </summary>
        private static void KeyboardThreadProc()
        {
            IntPtr hWnd = WinAPI.GetForegroundWindow();

            if (hWnd == IntPtr.Zero)
            {
                return;
            }

            // 获取窗口Title
            var strTitle = new StringBuilder(1024);

            WinAPI.GetWindowText(hWnd, strTitle, strTitle.Capacity);

            string          strPatternCheckIn = @"签入 - 源文件";
            string          strPatternReview  = @".+号变更集的详细信息 - 源文件";
            MatchCollection collCheckIn       = Regex.Matches(strTitle.ToString(), strPatternCheckIn);
            MatchCollection collReview        = Regex.Matches(strTitle.ToString(), strPatternReview);

            if ((collCheckIn.Count != 0 || collReview.Count != 0) &&
                MainForm.m_hMainForm != IntPtr.Zero)
            {
                if (collCheckIn.Count != 0 &&
                    MainForm.m_emFormType == FormType.Review)
                { // 签入窗口不能打开Review画面
                    return;
                }
                if (collReview.Count != 0 &&
                    MainForm.m_emFormType == FormType.Checkin)
                { // Review窗口不能打开签入画面
                    return;
                }

                // TFS窗口信息解析
                int iFlag = collCheckIn.Count;
                MainForm.m_iControlIdx = 0;
                WinAPI.CallBack callBackEnumChildWindows = new WinAPI.CallBack(ChildWindowProcess);
                WinAPI.EnumChildWindows(hWnd, callBackEnumChildWindows, iFlag);

                // 计算位置,准备显示对话框
                WinAPI.Rect rect = new WinAPI.Rect();
                WinAPI.GetWindowRect(hWnd, out rect);
                IntPtr x = (IntPtr)(rect.Left + (rect.Right - rect.Left) / 2);
                IntPtr y = (IntPtr)(rect.Top + (rect.Bottom - rect.Top) / 2);

                // 发送消息,由主界面显示对话框
                WinAPI.PostMessage(MainForm.m_hMainForm, MSG_SHOWDIALOG, x, y);
            }
        }