Exemplo n.º 1
0
        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Tbcon.Text       = "Hello World!";
            TbSenderNum.Text = "1000";
            TbInterval.Text  = "10";

            try
            {
                // 获取目标窗口句柄
                IntPtr ParenthWnd;
                ParenthWnd = FindWindow(null, Win_Name);
                // Zero 表示已初始化为零的指针或句柄的只读字段。
                if (ParenthWnd != IntPtr.Zero)
                {
                    MessageBox.Show("窗口:" + Win_Name +
                                    "\n句柄:" + ParenthWnd.ToInt64().ToString() +
                                    "\n找到窗口,点击确定开始下一步", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    checkH = ParenthWnd;
                }
                else
                {
                    MessageBox.Show("没有找到窗口,是不是输错字了?");
                    Environment.Exit(0);
                }
            }
            catch (Exception es)
            {
                new StreamWriter(new FileStream("Wrong.log", FileMode.OpenOrCreate, FileAccess.Write)).Write(es.ToString());
            }
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                /*
                 * 哈哈哈哈哈哈我写的什么东西
                 * 靠文件传值可还行哈哈哈哈哈哈哈哈哈哈哈(神经病
                 * (算了算了以后再改
                 */


                //从form2那里拿到对话框的句柄
                Form form = new Form2();
                form.ShowDialog();

                /*
                 * FileStream fileStream = new FileStream("log.txt", FileMode.Open, FileAccess.Read);
                 * StreamReader streamReader = new StreamReader(fileStream);
                 * Form2text = streamReader.ReadLine();
                 * streamReader.Close();
                 */
                form.Dispose();
                //判断form2



                IntPtr ParenthWnd;
                //获取目标窗口句柄
                ParenthWnd = FindWindow(null, Form2text);
                //判断这个窗体是否有效
                if (ParenthWnd != IntPtr.Zero)
                {
                    MessageBox.Show("窗口:" + Form2text +
                                    "\n句柄:" + ParenthWnd.ToInt64().ToString() +
                                    "\n找到窗口,点击确定开始下一步", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    checkH = ParenthWnd;
                }

                else
                {
                    MessageBox.Show("没有找到窗口,是不是输错字了?");
                    Environment.Exit(0);
                }
                if (isFirst)
                {
                    MessageBox.Show("禁止使用此软件用作任何形式的违法行为,您必须严格遵守当地法律!" +
                                    "\n开始前请将输入法切换成英文,开启回车发送消息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    isFirst = false;
                }
            }
            catch (Exception es)
            {
                new StreamWriter(new FileStream("Wrong.log", FileMode.OpenOrCreate, FileAccess.Write)).Write(es.ToString());
            }
        }