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 definitionconst 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);#endregionpublic 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 handlesvar 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 unitStringBuilder 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);elsethreadHandler = 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();}

以上代码尚不能工作,

You should be able to use SetFocus to give focus to the control you are sending the keystrokes to.

SendMessage and PostMessage can also be used to send keystrokes, but it's BAD PRACTICE and should be avoided.

Check out System.Windows.Forms.SendKeys for information on sending keystrokes though the Forms class in .NET.

In a lot of cases, if you don't need the keystrokes themselves, you can just change the text on a window using SendMessage with WM_SETTEXT if this is what you're looking to do.

http://answer.techwikihow.com/334694/sendinput-working-attaching-thread-input-target-process.html

转载于:https://www.cnblogs.com/zeroone/p/3713026.html

通达信自动交易软件 z相关推荐

  1. python 通达信自动下载收盘和财务数据

    python 通达信自动下载收盘和财务数据,自动启动通达信,鼠标自动操作: 通达信直接从官网下载免费版,可下载财务数据. 自动识别屏幕尺寸(目前为1440x900.1920x1080.1366*768 ...

  2. 通达信自动交易系统接口安装方式

    通达信自动交易系统接口安装方式 1方式一 1yum安装 yum install -y keepalived 2查看版本 rpm -qa|grep keepalived rpm -qc keepaliv ...

  3. 通达信自动交易系统接口定义

    通达信自动交易系统接口定义,接口是⼀个或多个方法签名的集合,任何类型的方法集中只要拥有与之对应的全部方法,就表示它"实现"了该接口,无须在该类型上显式添加接口声明.所谓对应方法,是 ...

  4. 通达信自动交易接口设置止损程序解析

    通达信自动交易接口设置止损程序并不是很难,对于交易者来说,还是需要去学习一些编程知识,像交易中的止损程序,可以这样去编写和输入你的止损策略:  (1)# 设置买卖止损值     def set_sto ...

  5. 通达信自动交易接口怎么显示大宗流入?

    通达信自动交易接口怎么显示大宗流入?原因主要是两个: 一.受沪港通直接利好的AH折价股.稀缺标的股前期已被资金大幅炒高,利好兑现出货正式A股市场短炒资金的一贯风格. 二.以创业板为代表的中小高成长类个 ...

  6. [ahk]通达信股票交易软件持仓数据获取(招商证券、中银国际、通达信官方版等测试可用)

    新版通达信持仓获取方式,得启动通达信,点击资金股份,再按热键F9,脚本如下,运行环境请去ahk英文官网下载 Current Version. ; Tested with AHK v1.1.31.00 ...

  7. 通达信自动提示穿头破脚K线组合形态(含指标公式源码)

    内容提要:本文主要介绍了穿头破脚K线组合形态的概念以及穿头破脚通达信指标公式的两种写法. 阳康归来,今天给大家介绍一个比较应景的K线组合形态--穿头破脚. 一.穿头破脚介绍 穿头破脚K线组合形态由两根 ...

  8. 通达信自动提示启明星、黄昏星K线组合形态(含指标公式源码)

    内容提要:本文主要介绍了启明星(早晨之星)和黄昏星(黄昏之星)K线组合形态的概念以及启明星和黄昏星通达信指标公式的写法,并设置K线颜色,添加文字标记. 一.启明星(也称早晨之星) 启明星K线组合形态是 ...

  9. 代码下移快捷键_收藏细看!最全面的通达信快捷键一览

    壹.通达信网上交易软件快捷键分为四种 数字键:比如1,61,81,10,91等 点系列键:比如.101,.201,.301.... .909等 功能键:比如F1,F2... 空格键,减号键,TAB等 ...

最新文章

  1. 云南大学信息学院c语言实验七,云南大学软件学院C语言程序
  2. Chapter11-RMAN Backups
  3. 图解 Numpy,原来数据操作这么简单!
  4. class文件的产生过程
  5. 【laravel5.4】迁移文件的生成、修改、删除
  6. 面试必谈的哈希,.Net 程序员温故而知新
  7. Cookie / Session 的机制与安全
  8. Eclipse启动SpringCloud微服务集群的方法
  9. 为何System Idle Process 进程占用了大量有CPU资源
  10. 五个转义气符html,【转】前端开发攻城师绝对不可忽视的五个HTML5新特性
  11. 复旦nlp实验室 nlp-beginner 任务三:基于注意力机制的文本匹配
  12. 未来教育计算机二级office评分有问题,未来教育计算机二级-未来教育计算机二级msoffice题库评分 – 手机爱问...
  13. 分布式系统之Quorum机制
  14. ARPG角色扮演页游《明朝江湖》全套代码
  15. 安装 Windows 7 VM虚拟机
  16. 一个公式竟然破解了年轻人的行为“密码”
  17. 2022年贵州省高新技术企业认定奖励补贴及申报条件
  18. php filter_sanitize_number_int,PHP中的FILTER_SANITIZE_NUMBER_FLOAT常量
  19. 老毛桃怎样查看计算机桌面文件,桌面上的文件在PE里怎么找-win7在pe下的桌面文件,win7在pe下的桌面文件不见了...
  20. 针对日语二级的学习方法

热门文章

  1. 分析爱鲜蜂的产品生命周期图
  2. 介绍一个好用的网盘MEGA
  3. python量化投资培训深圳你了解多少?
  4. css 背景效果_css透明度怎么设置?三种css图片透明度的设置方法
  5. 正面管教之PHP_正面管教是育儿体系?呵呵
  6. 功能简单却流量巨大,你想不到的海外APP
  7. 多线程实现主机端口扫描
  8. 聚观早报 | 首个国产新冠药停产;阿里巴巴创始人马云已回国内
  9. 阿里OceanBase GitHub送礼刷Star引争议,CTO致歉
  10. JDK安装后 没有tools.jar 和dt.jar包的解决办法