仿Listary功能_Quant

/*
作者:sunwind
时间:2015年11月30日15:45:07
环境:Windows7
脚本说明:
0、ahk实现listary中的Ctrl+G打开最近目录等功能
1、获取到的当前资源管理器打开的路径
2、获取excel文档路径(可以扩展其它常用应用的文档路径)
3、用弹出菜单展示
4、在保存/打开对话框中点击菜单项,可以更换对话框到相应路径
5、在非保存/打开对话框中点击菜单项,可以用资源管理器打开相应路径
6、点击菜单项中的xls文档路径,可以跳转到文档所在路径(其它类型的office文档都可实现,暂未开发)
*/
#SingleInstance,Force
history:=A_ScriptDir . "" . A_ScriptName . ".txt"
 ;~ Ctrl+G
^g::
!a::
    dir:=[]  ;定义存放路径的数组
    changyong=
    (
    【常用路径】
    d:abc
    C:Usersliuyk2DocumentsmyCRM
    )
;上述多行文本用于配置常用路径菜单项,且第一行为菜单项名称,另含【的菜单项目,点击时将不予处理
    
 ;获取Explorer打开的目录
    for oExplore in ComObjCreate("Shell.Application").Windows
    {  
        if (a_index=1)
        {
            dir.Push("【当前打开的路径有】")
        }
         OutDir:=oExplore.LocationURL
         if (OutDir="")  ;剔除 资源管理器显示的 "库" 这种情况
         {
            dir.Pop()
         }
         else
         {
            dir.Push(OutDir)
            Log(OutDir)
         }
    }

 ;获取已经打开的excel文档路径 ,这里可以扩展其它office文件的路径
 try{
    oExcel := ComObjActive("Excel.Application")

    for Item in oExcel.workbooks
    {
        if (a_index=1)
        {
           dir.Push("【当前打开的xls有】")
        }
        item:=oExcel.workbooks(A_index).FullName
        SplitPath,item,,OutDir ;获取Excel文件路径
        dir.Push(OutDir)
        Log(OutDir)
        oExcel.ActiveWindow.Caption :=Item
    }
}
catch e
{
}

  ;~ 【常用路径】
 loop,parse,changyong,"`n"
{
    dir.push(LTrim(A_LoopField))
}
    

 ;~ 【最近使用的路径】
gaopin:=getHistory(history)
loop,parse,gaopin,"`n"
{
     if (a_index=1)
        {
           dir.Push("【最近使用的路径】")
        }
    StringTrimLeft, Outdir, A_LoopField, 6 ; trim左侧6个字符
    ;~ MsgBox %Outdir%
    dir.push(Outdir)
}

;组装成菜单

    Menu, MyMenu, Add  ; 添加分隔线.
    Menu, MyMenu,  DeleteAll ; 清空菜单项
    
    Loop % dir.Length()
    {
         item:=dir[A_Index]
        if (InStr(item,"file:///"))
        {   
            Menu, MyMenu, Add, %item%, MenuHandler
 
        }
        else if (InStr(item,"http"))
        {   
        ;过滤掉http开头的。

        }
        else
        {
            Menu, MyMenu, Add, %item%, MenuHandler
 
        }
    }
;显示菜单
Menu, MyMenu, Show
return
    
MenuHandler:
    if (not instr(A_ThisMenuItem,"【"))
        {
            WinGet, this_id,ID, A
            WinGetTitle, this_title, ahk_id %this_id%
            WinGetClass,this_class,ahk_id %this_id%
            if(this_class="#32770") ;保存/打开对话框
            {
                If(instr(this_title,"存") or instr(this_title,"Save"))
                    {
                        ChangePath(A_ThisMenuItem,this_id)   
                    }
                else if(instr(this_title,"开") or instr(this_title,"Open"))
                    {
                     ChangePath(A_ThisMenuItem,this_id)   
                    }
            }
            else  ;普通窗口
            {
                try
                    {
                        OpenPath(A_ThisMenuItem)
                    }
                    catch e {
                          MsgBox % "Error in " e.What ", which was called at line " e.Line  "`n" e.Message  "`n" e.Extra
                    }
            }

        }

return


OpenPath(_dir)
{
    Run,"%_dir%"  ;只是打开路径
}

OpenAndSelect()
{

}
ChangePath(_dir,this_id)
{
    WinActivate,ahk_id %this_id%
    ControlFocus,ReBarWindow321,ahk_id %this_id%
    ControlSend,ReBarWindow321,{f4},ahk_id %this_id%
    Loop{
        ControlFocus,Edit2,ahk_id %this_id%
        ControlGetFocus,f,ahk_id %this_id%
        if A_index>50 
            break
    }until (f="Edit2")
    
    ControlSetText,edit2,%_dir%,ahk_id %this_id%
    ControlSend,edit2,{Enter},ahk_id %this_id%
}

;; ---------------------------------------------------------------------------
Log(debugstr)
{
    global
    FileAppend, %debugstr%`n, %history%
}
getHistory(history)
{
;获取最近使用的top10路径
a := []
b =
Loop, read, %history%
  {
    last_line := A_LoopReadLine  ; 当循环结束时, 这里会保持最后一行的内容.
	if !a["" last_line]
		a["" last_line] := 1
	else
		a["" last_line] += 1
}
for c,d in a
{
	d2 := SubStr("00000", 1, 5-strlen(d)) d
	str := d2 "_" c
	b .= b ? "`n" str : str
}
Sort, b, R
e := StrSplit(b,"`n","`r")
f =
loop 10
	f .= f ? "`n" e[A_index] : e[A_index]
return %f%
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他

任务管理

2020-3-9 1:03:44

其他

仿快捷方式更改图标_选择图标GUI

2020-3-9 1:05:44

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索