发消息给东方财富同花顺

发消息给东方财富同花顺

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Diagnostics;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace sendmessage2
{
    public partial class Form1 : Form
    {
        [DllImport("user32", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int FindWindow([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpClassName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpWindowName);
        [DebuggerStepThrough]


        [DllImport("user32", EntryPoint = "PostMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int PostMessage(int hwnd, int wMsg, int wParam, ref int lParam);
        [DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        public static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int SetForegroundWindow(int hwnd);
        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int ShowWindow(int hwnd, int nCmdShow);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string jincheng = "mainfree"; //东方财富

            //jincheng = "hexin";  //同花顺
            Process[] processesByName = Process.GetProcessesByName(jincheng);
            if (processesByName.Length > 0)
            {
                Encoding aSCII = Encoding.ASCII;
                string s = "300451";
                if (textBox1.Text != "")
                {
                    s = textBox1.Text;
            }

                byte[] bytes = aSCII.GetBytes(s);
                string lpClassName = null;
                string op_title = processesByName[0].MainWindowTitle;
                int hwnd = FindWindow(ref lpClassName, ref op_title);
                ShowWindow(hwnd, 3);
                SetForegroundWindow(hwnd);
                int num2 = bytes.Length - 1;
                int lParam = 0;
                for (int i = 0; i <= num2; i++)
                {
                    
                     PostMessage(hwnd, 0x100, bytes[i], ref lParam);
                    SendMessage(hwnd, 0x100, bytes[i],   lParam);
                    Thread.Sleep(50);
                }
                PostMessage(hwnd, 0x100, 0xD, ref lParam);
            }
            else
            {
                MessageBox.Show("没有启动!");
            }
        }
    }
}


暂无留言,赶快评论吧

欢迎留言