; Tested with AHK v1.1.31.00 Unicode 32/64-bit on Windows XP/7/10
/*
------------------------------------------------------
Filename: 获取通达信持仓.ahk
Description: 在通达信持仓界面,按 F9 可以获取持仓数据,本脚本仅做演示用,如有定制需求,请与作者联系。
Version: 2020年2月29日
Created By: YuKuan.Liu
Author Weixin: sunwind1576157
Type: AutoHotkey
URL: https://blog.csdn.net/liuyukuan/article/details/49722207
------------------------------------------------------
TODO:
+ 切换树状菜单到资金股份.
------------------------------------------------------
*/
CoordMode,Mouse,Window
F9::
PostMessage,0x111,14023,0,SysListView321,ahk_class TdxW_MainFrame_Class ;输出持仓数据
;等待输出设置窗口
loop
{
Sleep,50
if A_Index >100
Reload
}until WinExist("输出")
;~ WinWait, 输出, , 3
loop
{
Sleep,100
ControlGet, isEnable, Enabled,,Edit1,输出
ControlClick,x60 y60,输出
ControlClick,Button1,输出
if A_Index >100
Reload
}until (isEnable=1)
;获取输出路径
ControlGetText,file,Edit1,输出
;~ ControlSend,,{Enter},输出
ControlSend,,{Enter},输出
filename:=GetFilename(File)
;关闭弹出的文件窗口
loop
{
Sleep,50
if A_Index >100
Reload
}until WinExist(filename)
;~ WinWait, %filename%, , 3
WinClose,% filename
;解析持仓数据
fileparse(File)
return
;~ SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]
GetFilename(txt)
{
;~ SplitPath, txt, o ;OutFileName
SplitPath, txt, ,,,o ;OutNameNoExt
return o
}
fileparse(file)
{
FileRead,oFile, %file%
FileContents:=StrReplace(oFile," ","`t")
mark:=0
Loop,parse,FileContents, `n, `r
{
;~ FileDelete,%file%
LineNumber := A_Index
;;-------- 读取人民币:余额、可用、可取、股票市值、基金市值、资产、盈亏--------
if (InStr(A_LoopField,"人民币")=1)
{
Loop, parse, A_LoopField,%A_Tab%,%A_Space%
{
if(A_LoopField<>"")
str.=A_LoopField . "`n"
}
MsgBox %str%
}
;~ Loop, parse, A_LoopField,`t,`=
;-------- 跳过 美 元、港 元、以及--------
else if (InStr(A_LoopField,"美")=1 or InStr(A_LoopField,"港")=1 or InStr(A_LoopField,"-")=1)
{
mark:=LineNumber
;记录 --------在哪一行
continue
}
;-------- 跳过空行--------
else if (LineNumber=mark+1)
{
continue
}
;-------- 读取表头--------
else if (LineNumber=mark+2)
{
Loop, parse, A_LoopField,%A_Tab%,%A_Space%
{
if(A_LoopField<>"")
head.=A_LoopField . "`n"
}
MsgBox 表头是↓`n%head%
}
;-------- 读取数据--------
else{
this_line:=""
if (A_LoopField="")
break
Loop, parse, A_LoopField,%A_Tab%,%A_Space%
{
if(A_LoopField<>"")
this_line.=A_LoopField . "`n"
}
MsgBox % LineNumber-mark-2 "is↓`n" this_line
}
}
}