コード例 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            IntPtr handle1 = Classpub.FindWindow(null, "MessageBox1111");

            if (handle1 != IntPtr.Zero)
            {
                Classpub.PostMessage(handle1, Classpub.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                //MessageBox.Show("MessageBox");
            }
        }
コード例 #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            IntPtr handle1 = Classpub.FindWindow(null, "chuangkou1");

            if (handle1 != IntPtr.Zero)
            {
                Classpub.PostMessage(handle1, Classpub.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                //MessageBox.Show("chuangkou1", "MessageBox1111");
                //MessageBox.Show("postmessage 这里是跟随运行的窗口", "窗口");
            }
        }
コード例 #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            IntPtr handle1 = Classpub.FindWindow(null, "chuangkou2");

            if (handle1 != IntPtr.Zero)
            {
                Classpub.SendMessage(handle1, Classpub.WM_CLOSE, 0, 0);
                //MessageBox.Show("chuangkou2", "MessageBox1111");
                //MessageBox.Show("sendmessage 这里是跟随运行的窗口", "窗口");
            }
        }
コード例 #4
0
        private static void threadclient()
        {
            return;

            IntPtr handlehandle = handlethis;

            Socket newclient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            Console.Write("please input the server ip:");

            //string ipadd = Console.ReadLine();
            string ipadd = "127.0.0.1";

            Console.WriteLine();
            Console.Write("please input the server port:");
            //int port = Convert.ToInt32(Console.ReadLine());
            int port = 9050;

            IPEndPoint ie = new IPEndPoint(IPAddress.Parse(ipadd), port);//服务器的IP和端口

            try
            {
                newclient.Connect(ie);
            }
            catch (SocketException e)
            {
                Console.WriteLine("unable to connect to server");
                Console.WriteLine(e.ToString());
                return;
            }
            byte[] data = new byte[1024];


            int    recv;       //= newclient.Receive(data);
            string stringdata; //= Encoding.ASCII.GetString(data, 0, recv);

            //Console.WriteLine("recive1 " + stringdata);

            while (true)
            {
                //string input = "123";// Console.ReadLine();
                //if (input == "close")
                //{
                //    Classpub.PostMessage(handlethis, Classpub.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                //    break;
                //}
                //newclient.Send(Encoding.ASCII.GetBytes(input));
                data       = new byte[1024];
                recv       = newclient.Receive(data);
                stringdata = Encoding.ASCII.GetString(data, 0, recv);
                Console.Write(stringdata);
                if (stringdata.IndexOf("close") >= 0)
                {
                    Classpub.PostMessage(handlehandle, Classpub.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    break;
                }
                //Console.WriteLine("recive2 " + stringdata );
            }
            Console.WriteLine("disconnect from sercer");
            newclient.Shutdown(SocketShutdown.Both);
            newclient.Close();
        }