首页 > 其他分享 >通达信自动交易软件

通达信自动交易软件

时间:2022-11-24 23:56:12浏览次数:74  
标签:IntPtr Console string static int hWnd 通达信 自动 软件

1、要善用spy++

2、不同的控件主要靠GetDlgCtrlID去区分

3、要获得另一个进程的焦点窗口(GetFocus)需要调用AttachThreadInput

4、尽量少用keybd_event模拟键盘输入,主要是该函数不能保证按键消息一定能被特定进程接收到。取而代之的是SendMessage(hwnd, WM_IME_CHAR, ...)。而模拟回车按下要用PostMessage (hFocus, WM_KEYDOWN, VK_RETURN, 0),SendMessage不知为何不起作用

5、通达信在按下第一个数字键后会弹出键盘精灵,此时焦点窗口会转移到键盘精灵上,要重新调用GetFocus一次

6、GetWindow(hMainWnd, GW_ENABLEDPOPUP)可以获得当前的弹出窗口句柄

7、PostMessage(hPopup, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), NULL),模拟“确定”键被按下

8、EnumChildWindows函数可以枚举一个窗口的所有子窗口

 

复制代码

class ThreadHandler
{
    #region P/Invoking and constants definition
    const uint WM_GETTEXT = 0x000D;

    [DllImport("user32.dll")]
    static extern IntPtr SetFocus(IntPtr hWnd);

    [DllImport("user32.dll")]
    private static extern int GetWindowThreadProcessId(IntPtr hWnd, uint lpdwProcessId = 0);

    delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
    [DllImport("user32.dll")]
    static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn,
        IntPtr lParam);

    [DllImport("user32.dll")]
    static extern bool AttachThreadInput(int idAttach, int idAttachTo, bool fAttach);

    [DllImport("kernel32.dll")]
    static extern int GetCurrentThreadId();

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, StringBuilder lParam);

    #endregion

    public readonly string ProcessName, WindowName;
    protected readonly int TargetThreadID, CurrentThreadID;
    protected readonly IntPtr TargetWindowHandle;

    public ThreadHandler(string processName, string windowName)
    {
        CurrentThreadID = GetCurrentThreadId();
        ProcessName = processName;
        WindowName = windowName;

        object[] objs = GetWindowThread(processName, windowName);
        if (objs == null)
        {
            throw new ArgumentException("Could not find the specified process/window.");
        }

        TargetThreadID = (int)objs[0];
        TargetWindowHandle = (IntPtr)objs[1];
    }

    public ThreadHandler(string processName)
    {
        CurrentThreadID = GetCurrentThreadId();
        ProcessName = processName;

        var processes = Process.GetProcessesByName(ProcessName);
        if (processes.Length == 0)
        {
            throw new ArgumentException("Could not find the specified process.");
        }
        var appProc = processes[0];

        WindowName = appProc.MainWindowTitle;
        TargetThreadID = GetWindowThreadProcessId(appProc.MainWindowHandle);
        TargetWindowHandle = appProc.MainWindowHandle;
    }

    public bool AttachThreadInput()
    {
        return AttachThreadInput(CurrentThreadID, TargetThreadID, true);
    }

    public bool DetachThreadInput()
    {
        return AttachThreadInput(CurrentThreadID, TargetThreadID, false);
    }

    public void SetFocus()
    {
        SetFocus(TargetWindowHandle);
    }

    static object[] GetWindowThread(string processName, string windowName)
    {
        var processes = Process.GetProcessesByName(processName);
        if (processes.Length > 0)
        {
            //Fill a list of handles
            var handles = new List<IntPtr>();
            foreach (ProcessThread thread in processes[0].Threads)
                EnumThreadWindows(thread.Id,
                    (hWnd, lParam) => { handles.Add(hWnd); return true; }, IntPtr.Zero);

            //Create a stringbuilder to function as storage unit
            StringBuilder nameBuffer = new StringBuilder(64);
            foreach (var hWnd in handles)
            {
                //And finally compare the caption of the window with the requested name
                nameBuffer.Clear();
                SendMessage(hWnd, WM_GETTEXT, nameBuffer.Capacity, nameBuffer);
                if (nameBuffer.ToString() == windowName)
                {
                    return new object[2] { GetWindowThreadProcessId(hWnd), hWnd };
                }
            }
        }
        return null;
    }
}

复制代码

复制代码

static void Main(string[] args)
    {
        Console.WriteLine("Please input the name of the process to hook: ");
        string pName = Console.ReadLine();
        Console.WriteLine("Input the name of a specific window, or leave blank: ");
        string pWnd = Console.ReadLine();
        ThreadHandler threadHandler;
        try
        {
            if(!String.IsNullOrWhiteSpace(pWnd))
                threadHandler = new ThreadHandler(pName, pWnd);
            else
                threadHandler = new ThreadHandler(pName);
        }
        catch
        {
            Console.WriteLine("Error: " + pName +" does not seem to be running.");
            Console.ReadKey();
            return;
        }

        if (!threadHandler.AttachThreadInput())
        {
            Console.WriteLine("Error: The application tried to attach its Input Processing Mechanism to " + threadHandler.ProcessName + ", but failed.");
            Console.ReadKey();
            return;
        }
        Console.WriteLine("Input Processing Mechanism correctly attached to " + threadHandler.ProcessName + ".");
        threadHandler.SetFocus();
        InputSimulator.SimulateTextEntry("test"); //InputSimulator is a seemingly famous SendInput wrapper. Replacing this line with the code for a keystroke also doesn't work.
        Console.ReadLine();
        Console.WriteLine("Detaching Input Processing Mechanism.");
        threadHandler.DetachThreadInput();
    }

复制代码

标签:IntPtr,Console,string,static,int,hWnd,通达信,自动,软件
From: https://www.cnblogs.com/lidabo/p/16923882.html

相关文章

  • 通达信 缠论分笔、分段DLL插件使用说明
    1将TDXchan.dll文件复制到C:\zd_zsone\T0002\dlls。这是通达信股票软件的安装目录,根据你的当前环境调整。进入安装目录发现没有dlls文件夹时,可以自己创建。2绑定DL......
  • JavaWeb+SVN+Maven+Tomcat +jenkins实现自动化部署
       在日常开发项目中常见的开发模式是使用代码库来存放我们的项目例如:SVN、Git、CVS等,采用Maven来进行项目管理而需要在测试和发布项目的时候需要手动打包然后部署到服......
  • vxe-table接口动态数据赋值后不能自动展开的bug
    知道你来看,肯定是遇到这个bug了,先上答案。vxe-table出来多久我没去看,但是他更新的挺快,功能确实强大,但是bug也是真多哈。按照官网的api,只要调用reload方法重新加载就行,但......
  • 中国自动驾驶,不能只靠「搭积木」
    中国车,靠「堆料」解决所有问题已成常态。从「大而不强」的燃油车时代,到「强而不精」的新能源汽车,中国造车业的天花板已被彻底颠覆。除了汽车动力系统的更替外,技术层面的......
  • 麒麟桌面系统自动化方案 pyautogui+pythonnet
    麒麟系统模拟鼠标的点击、滑动等操作,键盘输入等操作pyautogui的安装见上篇文章可以通过pythonnet封装python脚本,实现点击和输入等操作做到自动化鼠标移动void......
  • idea使用groovy脚本自动生成数据库实体
    importcom.intellij.database.model.DasTableimportcom.intellij.database.util.Caseimportcom.intellij.database.util.DasUtilimportjava.time.LocalDateimportjava.......
  • 5步法助力自动化转型
    手动测试人员应该权衡测试自动化相对于手动测试的好处,并且即可开始行动。下面我介绍一下从手动测试到自动化测试转换的5步指南。步骤1:查找合适的自动化测试用例测试自动......
  • 案例3_自动跳转首页和DOM_概述
    案例3_自动跳转首页:分析:1.显示页面效果<p>2.倒计时读秒效果实现2.1定义一个方法,获取span标签,修改span标签体内容,时间--2.2定义一个定时器,1秒执行一次该方法3.在方法......
  • mac上好用的软件
    录屏:omi录屏专家 控制鼠标和触摸板上的滑动方向scrollreverser、 播放器VLC 历史剪贴板clipy 显示器亮度控制,可控制外接显示器monitorcontrol......
  • 在Windows系统中自动安装Ruby环境的批处理
    12345678910111213141516171819202122232425262728293031323334@echoThisbatchwillinstallRuby3.1.2almostau......