MouseGetPos, , , , controlclassnn ;获得一个控件
ControlGet, hwnd, Hwnd, , %controlclassnn%, A ;获得控件句柄
;WinGetClass, class, ahk_id %hwnd%
Parent=1
while Parent
Parent := DllCall("GetParent","int",hwnd),p := Parent ? Parent : p,hwnd := Parent ? Parent : hwnd ;获取最顶层父窗
WinGetClass, ParentClass, ahk_id %p%
MsgBox %ParentClass%
ControlGet, controlhwnd, hwnd, , , A ;获取控件hwnd
WinGet, mainhwnd, ID, A ;获取窗口hwnd
/*
VarSetCapacity(c,201,0)
DllCall("GetClassNameA","int",controlhwnd, "Ptr", &c, "Int", 200) ;获取控件类
classname := StrGet(&c,200)
*/
WinGetClass, classname, ahk_id %controlhwnd%
nhwnd := 0, idx := 0
while nhwnd<>controlhwnd
{
idx++,nhwnd := DllCall("FindWindowExA","uint", mainhwnd, "uint", nhwnd, "Str", classname,"uint", 0) ;枚举该类控件,检查是否是这一个控件
if !nhwnd
break
}
classNN := classname idx
GetCookie(){
static url, ua ;链接,user-agent
if !url
url := "http://shop.xj.189.cn:8081/xjwt_webapp/RechangeController/index.do?params=Y2hhbm5lbElkPThhODI4YjQ1NGUzZjIwMTIwMTRlNDdlYjZjYWUwMDBh&fastcode=10000321"
if !ua
ua := "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER"
;设置request-header
headers := {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","Upgrade-Insecure-Requests":"1","Accept-Encoding":"gzip,deflate","Accept-Language":"zh-CN,zh;q=0.8","Host":"shop.xj.189.cn:8081","User-Agent":ua}
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
Try
{
hObject.Open("GET",url) ;get/post
for k,v in headers ;设置请求头
hObject.SetRequestHeader(k, v)
hObject.Send()
hObject.WaitForResponse(-1)
}
hds := hObject.GetAllResponseHeaders() ;获取所有cookie
cookie := ""
Loop, Parse, hds, `n, `r
{
if RegExMatch(A_LoopField,"Set-Cookie:([^;]*;)",m)
cookie .= m1
}
return cookie
}
GZURLDownloadToVar(url, Encoding = "",Method="GET",postData="",headers:=""){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
Try
{
hObject.SetTimeouts(30000,30000,300000,300000)
hObject.Open(Method,url,True)
if IsObject(headers)
{
for k,v in headers
{
if v
hObject.SetRequestHeader(k, v)
}
}
hObject.Send(postData)
hObject.WaitForResponse(-1)
}
catch e
return -1
}
GZIP_DecompressResponseBody(hObject, retHtml, Encoding)
return retHtml
}
GZIP_DecompressBuffer(ByRef var, nSz ){
static hModule, _
If !hModule {
hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr")
_ := { base: {__Delete: "GZIP_DecompressBuffer"} }
}
If !_
Return DllCall("FreeLibrary", "Ptr", hModule)
vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 )
DllCall( "GZIP\InitDecompression" )
DllCall( "GZIP\CreateDecompression", UIntP,CTX, UInt,1 )
If ( DllCall( "GZIP\Decompress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz
, UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) )
VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 )
, DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz )
DllCall( "GZIP\DestroyDecompression", UInt,CTX ), DllCall( "GZIP\DeInitDecompression" )
Return Ok ? vsz : 0
}
GZIP_DecompressResponseBody(ByRef oWinHttp, ByRef retHtml, encoding:="UTF-8") {
If ( oWinHttp.GetResponseHeader("Content-Encoding") != "gzip" )
Return True, retHtml := oWinHttp.ResponseText
body := oWinHttp.ResponseBody
VarSetCapacity(data, size := body.MaxIndex() + 1)
DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata)
DllCall("RtlMoveMemory", "ptr", &data, "ptr", pdata, "ptr", size)
DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(body))
size := GZIP_DecompressBuffer(data, size)
retHtml := StrGet(&data, size, encoding)
}
function curlPost($url,$post = true, $data = array(), $timeout = 30, $CA = true){
// 链接,是否使用POST方式, post数据, 超时, 验证http证书
$cacert = getcwd() . '/cacert.pem'; //CA根证书
$SSL = substr($url, 0, 8) == "https://" ? true : false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout-2);
if ($SSL && $CA) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 只信任CA颁布的证书
curl_setopt($ch, CURLOPT_CAINFO, $cacert); // CA根证书(用来验证的网站证书是否是CA颁布)
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名,并且是否与提供的主机名匹配
} else if ($SSL && !$CA) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 检查证书中是否设置域名
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($post== true) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); //避免data数据过长问题
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}else{
curl_setopt($ch, CURLOPT_HEADER, 0);
}
//curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //data with URLEncode
$ret = curl_exec($ch);
//var_dump(curl_error($ch)); //查看报错信息
curl_close($ch);
return $ret;
}
转换效率 decodeu3>decodeu4>decodeu2>decodeu
使用环境Autohotkey ansi32,输出gb2312字符串
decodeu2(out){
foundpos := 1
while(foundpos := RegExMatch(out,"\\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})",m))
Unicode2Ansi(Chr("0x" m2) Chr("0x" m1),tmpstr,0),out := RegExReplace(out,"\\u" m1 m2, tmpstr)
return out
}
decodeu3(out){
foundpos := 1
while(foundpos := RegExMatch(out,"\\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})",m))
Unicode2Ansi(Chr("0x" m2) Chr("0x" m1),tmpstr,0),out := strReplace(out,"\u" m1 m2, tmpstr)
return out
}
decodeu4(out){
foundpos := 1, VarSetCapacity(char,3,0)
while(foundpos := RegExMatch(out,"\\u([A-Fa-f0-9]{4})",m))
NumPut("0x" m1,&char,,"UShort"),out := strReplace(out,"\u" m1 m2, StrGet(&char,,"CP1200"))
return out
}
decodeu(ustr){
Loop
{
if !ustr
break
if RegExMatch(ustr,"^\s*\\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})(.*)",m)
{
word_u := Chr("0x" m2) Chr("0x" m1), ustr := m3, word_a := ""
Unicode2Ansi(word_u,word_a,0)
out .= word_a
}
else if RegExMatch(ustr, "^([a-zA-Z0-9\.\?\-\!\s\:""]*)(.*)",n)
{
ustr := n2
out .= n1
}
}
return out
}
Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
{
nSize := DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "Uint", 0
, "int", 0
, "Uint", 0
, "Uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "str", sString
, "int", nSize
, "Uint", 0
, "Uint", 0)
}
这是一个读取ahk文件列表汇集到一个文件便于全文搜索的示例
FileRead, c, *P936 list.txt
Loop, Parse, c, `n, `r
{
file := FileOpen(A_LoopField,"r") ;读取文件头4字节
int := file.ReadUInt()
file.close()
if InStr(Format("{1:X}", int),"BFBBEF") ;包含UTF-8 BOM
FileRead, t, *P65001 %A_LoopField%
else
FileRead, t, *P936 %A_LoopField%
FileAppend, % ";" A_LoopField "`n`n" t "`n", ahk_combine.ahk
}
MsgBox OK
;适合所有工作表字段(列头)一致的情况
#maxmem 1024
file := "d:\desktop\list.xls"
xls := new exceldb()
xls.open(file)
content := ""
for k,v in xls.GetTableInfo()
{
for a,b in xls.GetTable("select * from [" k "$]")
{
tmp_str := ""
for x,y in b
{
tmp_str .= tmp_str ? "`t""" y """" : """" y """"
}
content .= tmp_str "`t" k "`n"
}
}
FileAppend % content, d:\desktop\out1.txt
请使用Autohotkey H版运行和编译
Gui, Add, ListView, x0 y0 w150 h400, I D|SleepMSec
Gui, Show
obj := CriticalObject()
SplitPath, A_AhkPath, , AHKDir
max := 10, Threads := [], count := 0
loop % max
Threads[A_index] := ""
Loop
{
for k,v in Threads
{
if(!v)
{
script := "#notrayicon`nobj:=CriticalObject(" CriticalObject(obj,1) "," CriticalObject(obj,2) ")`nrandom, x, 500, 5000`nsleep % x`nobj[" k "] := x"
Threads[k] := AhkDllThread(AHKDir "\AutoHotkey.dll")
Threads[k].ahktextdll(script)
}
else
{
if (!Threads[k].ahkReady())
{
LV_Add("",k,obj[k])
obj[k] := "",Threads[k] := ""
}
}
}
Sleep, 100
}
GetToolTipText(){
WinGet, hwnd, ID, ahk_class tooltips_class32
if hwnd
{
ControlGetText, text, , ahk_id %hwnd%
return text
}
}
43 queries in 1.202 seconds |