Kawvin快捷菜单
SetWorkingDir,%A_ScriptDir% ;设置工作目录 #SingleInstance force ;单脚本运行 #WinActivateForce ;强制激活窗体 Process Priority,,High ;线程,主,高级别 CoordMode,Mouse,Screen ;设置鼠标相对于屏幕激活 CoordMode,Menu ;设置菜单相对于窗口激活 AutoTrim,on ;自动省略首尾的空格和Tab ComObjError(0) ;禁用 COM 错误通告 Menu, Tray, UseErrorLevel ;阻止显示对话框和终止线程 Label_My_global_and_PreDefined_Var: global szMenuIdx:={} ;菜单用1 global szMenuContent:={} ;菜单用2 global szMenuWhichFile:={} ;菜单用3 SplitPath,A_ScriptFullPath,,,,MyOutNameNoExt global MenuLst_ini := MyOutNameNoExt . ".ini" global KyMenu_IconSize:= global KyMenu_IconDir:= Label_Candy_DrawMenu: Menu,KyTopLevelMenu,add Menu,KyTopLevelMenu,DeleteAll KyMenu_IconSize:=SkSub_IniRead(MenuLst_ini, "General_Settings", "MenuIconSize",16) KyMenu_IconDir:=SkSub_IniRead(MenuLst_ini, "General_Settings", "MenuIconDir") ;菜单图标位置 ;加菜单 szMenuIdx:={} szMenuContent:={} szMenuWhichFile:={} SkSub_GetMenuItem(Candy_Profile_Dir,CandyMenu_ini,CandyMenu_sec,"KyTopLevelMenu","") SkSub_DeleteSubMenus("KyTopLevelMenu") For,k,v in szMenuIdx { SkSub_CreateMenu(v,"KyTopLevelMenu","Label_Candy_HandleMenu",KyMenu_IconDir,KyMenu_IconSize) } Menu,KyTopLevelMenu,add Menu,KyTopLevelMenu,add,生成菜单,Label_Kawvin_MakeMenu Menu, KyTopLevelMenu, icon, 生成菜单,%KyMenu_IconDir%\Make.ico,,%KyMenu_IconSize% Menu,KyTopLevelMenu,add,编辑菜单,Label_Kawvin_EditMenu Menu, KyTopLevelMenu, icon, 编辑菜单,%KyMenu_IconDir%\Edit.ico,,%KyMenu_IconSize% Menu,KyTopLevelMenu,add,界面编辑菜单,Label_Kawvin_GUIEditMenu Menu, KyTopLevelMenu, icon, 界面编辑菜单,%KyMenu_IconDir%\EditGui.ico,,%KyMenu_IconSize% MouseGetPos,CandyMenu_X, CandyMenu_Y MouseMove,CandyMenu_X,CandyMenu_Y,0 MouseMove,CandyMenu_X,CandyMenu_Y,0 Menu,KyTopLevelMenu,shOW return ;================菜单处理================================ Label_Candy_HandleMenu: MyArray_Memu:=StrSplit( szMenuContent[ A_thisMenu "/" A_ThisMenuItem], ";") CmdStr1:=MyArray_Memu[1] CmdStr2:=MyArray_Memu[2] CmdStr3:=MyArray_Memu[3] CmdStr4:=MyArray_Memu[4] ;msgbox %CmdStr1% %CmdStr2%,%CmdStr3%,%CmdStr4% Run ,%CmdStr1% %CmdStr2%,%CmdStr3%,%CmdStr4% UseErrorLevel return ;================菜单生成================================ Label_Kawvin_MakeMenu: ;选择要生成菜单的文件夹 FileSelectFolder,MyAppsDir,*%A_ScriptDir%,0,选择要生成菜单的目录`n`n名称中含有 `[ 或 `] 则自动排除 if MyAppsDir= return ;遍历exe文件 ;filedelete,%MenuLst_ini% FileMove,%MenuLst_ini%,%MenuLst_ini%.bak,1 FileAppend,[General_Settings]`n,%MenuLst_ini% FileAppend,AppsDir=%MyAppsDir%`n,%MenuLst_ini% FileAppend,MenuIconSize=20`n,%MenuLst_ini% FileAppend,MenuIconDir=图标库`n,%MenuLst_ini% FileAppend,随系统启动=0`n`n,%MenuLst_ini% FileAppend,[Kawvin_Hotkey]`n,%MenuLst_ini% FileAppend,MyHotkey1=!c`n,%MenuLst_ini% FileAppend,MyHotkey2=!F9`n`n,%MenuLst_ini% FileAppend,[MyMenus]`n,%MenuLst_ini% loop,Files,%MyAppsDir%\*.exe,R { MyMenuName:=A_LoopFileFullPath if (InStr(MyMenuName,"[") > 0 or InStr(MyMenuName,"]") > 0) continue StringReplace,MyMenuName,MyMenuName,%MyAppsDir%\,,all StringReplace,MyMenuName,MyMenuName,.exe,,all StringReplace,MyMenuName,MyMenuName,`\,`/,all ;MyMenuPath:=A_LoopFileFullPath FileAppend,%MyMenuName%`=%A_LoopFileFullPath%`n,%MenuLst_ini% } return ;================菜单编辑================================ Label_Kawvin_EditMenu: Run,%MenuLst_ini% return Label_Kawvin_GUIEditMenu: Run,Kawvin快捷菜单编辑器.exe return /* ╔══════════════════════════════════════╗ ║<<<<Fuctions所用到的函数>>>> ║ ╚══════════════════════════════════════╝ */ SkSub_GetMenuItem(IniDir,IniNameNoExt,Sec,TopRootMenuName,Parent="") ;从一个ini的某个段获取条目,用于生成菜单。 { Items:=SkSub_IniRead_Section(MenuLst_ini,"MyMenus") ;本次菜单的发起地 StringReplace,Items,Items,△,`t,all loop,Parse,Items,`n { Left:=RegExReplace(A_LoopField,"(?<=\/)\s+|\s+(?=\/)|^\s+|(|\s+)=[^!]*[^>]*") Right:=RegExReplace(A_LoopField,"^.*?\=\s*(.*)\s*$","$1") if (RegExMatch(left,"^/|//|/$|^$")) ;如果最右端是/,或者最左端是/,或者存在//,则是一个错误的定义,抛弃 continue if RegExMatch(Left,"i)(^|/)\+$") ;如果左边的最末端是仅仅一个"独立的" + 号 { m_Parent := InStr(Left,"/") > 0 ? RegExReplace(Left,"/[^/]*$") "/" : "" ;如果+号前面有存在上级菜单,则有上级菜单,否则没有 Right:=RegExReplace(Right,"~\|",Chr(3)) arrRight:=StrSplit(Right,"|"," `t") rr1:=arrRight[1] rr2:=RegExReplace(arrRight[2],Chr(3),"|") rr3:=RegExReplace(arrRight[3],Chr(3),"|") rr4:=RegExReplace(arrRight[4],Chr(3),"|") } else { szMenuIdx.Insert( Parent "" Left ) szMenuContent[ TopRootMenuName "/" Parent "" Left] := Right szMenuWhichFile[ TopRootMenuName "/" Parent "" Left] :=IniNameNoExt } } } SkSub_DeleteSubMenus(TopRootMenuName) { For i,v in szMenuIdx { if InStr(v,"/")>0 { Item:=RegExReplace(v, "(.*)/.*", "$1") Menu,%TopRootMenuName%/%Item%,add Menu,%TopRootMenuName%/%Item%,DeleteAll } } } SkSub_CreateMenu(Item,ParentMenuName,label,IconDir,IconSize) ;条目,它所处的父菜单名,菜单处理的目标标签 { ;送进来的Item已经经过了“去空格处理”,放心使用 arrS:=StrSplit(Item,"/"," `t") _s:=arrS[1] if arrS.MaxIndex()= 1 ;如果里面没有 /,就是最终的”菜单项“。添加到”它的父菜单”上。 { if InStr(_s,"-") = 1 ;-分割线 Menu, %ParentMenuName%, Add else if InStr(_s,"*") = 1 ;* 灰菜单 { _s:=LTrim(_s,"*") Menu, %ParentMenuName%, Add, %_s%,%Label% Menu, %ParentMenuName%, Disable, %_s% } else { y:=szMenuContent[ ParentMenuName "/" Item] z:=SkSub_Get_MenuItem_Icon( y ,IconDir) Menu, %ParentMenuName%, Add, %_s%,%Label% Menu, %ParentMenuName%, icon, %_s%,%z%,,%IconSize% } } else ;如果有/,说明还不是最终的菜单项,还得一层一层分拨出来。 { _Sub_ParentName=%ParentMenuName%/%_s% StringTrimLeft,_subItem,Item,StrLen(_s)+1 SkSub_CreateMenu(_subItem,_Sub_ParentName,label,IconDir,IconSize) Menu,%ParentMenuName%,add,%_s%,:%_Sub_ParentName% IfExist,%KyMenu_IconDir%\%_s%.ico Menu, %ParentMenuName%, icon, %_s%,%KyMenu_IconDir%\%_s%.ico,,%IconSize% } } SkSub_Get_MenuItem_Icon(item,iconpath) ; item=需要获取图标的条目,iconpath=你定义的图标库文件夹 { if RegExMatch(item,"i)^(ow|openwith|rot|Run|roa|Runp|Rund)\|") ;运行命令类 { cmd_removed:=RegExReplace(item,"^.*?\|") ;里面纯粹的 应用程序 路径 x:=RegExReplace(cmd_removed,"i)exe[^!]*[^>]*", "exe") return %x% } else if InStr(item,".exe") ;省略了指令的openwith| { x:=RegExReplace(item,"i)\.exe[^!]*[^>]*", ".exe") return %x% } else { t:=RegExReplace(item,"\s*\|.*?$") ;去除运行参数,只保留第一个|最前面的部分 x:=AssocQueryApp(t) return %x% } } AssocQueryApp(sExt) { sExt =.%sExt% ;ASSOCSTR_EXECUTABLE DllCall("shlwapi.dll\AssocQueryString", "uint", 0, "uint", 2, "uint", &sExt, "uint", 0, "uint", 0, "uint*", iLength) VarSetCapacity(sApp, 2*iLength, 0) DllCall("shlwapi.dll\AssocQueryString", "uint", 0, "uint", 2, "uint", &sExt, "uint", 0, "str", sApp, "uint*", iLength) return sApp } SkSub_IniRead(ini, sec, key="", default = "") ;iniread的函数化 { IniRead, v, %ini%, %sec%, %key%, %Default% return, v } SkSub_IniRead_Section(ini,sec) { ;返回全部某段的内容,函数化而已 IniRead,keylist,%ini%,%sec% ;提取[sec]段里面所有的群组 return %keylist% }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
?