#NoEnv
#NoTrayIcon
#SingleInstance Force
SetBatchLines -1
DetectHiddenWindows On
CreateGUI()
CreateMenu()
RefreshList()
return
GuiClose:
GuiEscape:
ExitApp
CreateGUI() {
global
Gui, +HwndHGUI
Gui, Font, s10, 微软雅黑
Gui, Add, ListView, xm w700 r10 Grid HwndHLV gLvEvent AltSubmit, 文件名|文件路径|PID
Loop, Parse, % "退出Q|重启R|暂停S|暂停热键D|结束进程X", |
Gui, Add, Button, % (A_Index=1 ? "" : "x+40") . " Disabled gExecMenu", %A_LoopField%
Gui, Add, Button, x+100 gReloadAll, 重启全部A
Gui, Add, Button, x+55 gRefreshList vBtnRefresh, 刷新列表N
Gui, Show,, AHK 进程管理 v1.05
}
CreateMenu() {
Loop, Parse, % "退出Q|重启R|暂停S|暂停热键D||结束进程X", |
Menu, lvMenu, Add, % A_LoopField, MenuHandler
}
RefreshList() {
static selfPID := DllCall("GetCurrentProcessId")
LV_Delete()
WinGet, id, List, ahk_class AutoHotkey
Loop, %id% {
this_id := id%A_Index%
WinGet, this_pid, PID, ahk_id %this_id%
if (this_pid != selfPID)
{
WinGetTitle, this_title, ahk_id %this_id%
fPath := RegExReplace(this_title, " - AutoHotkey v[\d.]+$")
SplitPath, fPath, fName
LV_Add("", fName, fPath, this_pid)
}
}
LV_ModifyCol()
LV_ModifyCol(1, "Sort")
GuiControl,, BtnRefresh, 刷新列表N
}
GuiContextMenu(GuiHwnd, CtrlHwnd) {
global HLV
if (CtrlHwnd = HLV) && LV_GetNext() {
Menu, lvMenu, Show
}
}
MenuHandler(ItemName) {
static cmd := {重启R: 65303, 暂停热键D: 65305, 暂停: 65306, 退出Q: 65307}
static WM_COMMAND := 0x111
if (ItemName = "结束进程X") {
for i, obj in GetSelectedInfo()
Process, Close, % obj.pid
} else {
for i, obj in GetSelectedInfo()
PostMessage, WM_COMMAND, % cmd[ItemName],,, % obj.path " ahk_pid " obj.pid
}
if (ItemName = "重启R") {
GuiControl,, BtnRefresh, 刷新中...
SetTimer, RefreshList, -3000
} else if (ItemName ~= "退出Q|结束")
SetTimer, RefreshList, -300
}
GetSelectedInfo() {
RowNum := 0, arr := []
while, RowNum := LV_GetNext(RowNum) {
LV_GetText(path, RowNum, 2)
LV_GetText(pid, RowNum, 3)
arr.push( {pid: pid, path: path} )
}
return arr
}
LvEvent() {
if !(A_GuiEvent == "I")
return
GuiControlGet, isEnabled, Enabled, 退出Q
nSelected := LV_GetCount("Selected")
if !(isEnabled && nSelected) || !(!isEnabled && !nSelected)
{
Loop, Parse, % "退出Q|重启R|暂停S|暂停热键D|结束进程X", |
GuiControl, % "Enabled" !!nSelected, %A_LoopField%
}
}
ExecMenu() {
MenuHandler(A_GuiControl)
}
ReloadAll() {
Loop, % LV_GetCount()
{
LV_GetText(path, A_Index, 2)
LV_GetText(pid, A_Index, 3)
PostMessage, 0x111, 65303,,, % path " ahk_pid " pid
}
}
#If WinActive("ahk_id " HGUI)
q::MenuHandler("退出Q")
r::MenuHandler("重启R")
s::MenuHandler("暂停")
d::MenuHandler("暂停热键D")
x::MenuHandler("结束进程X")
a::ReloadAll()
n::RefreshList()
#If
暂无讨论,说说你的看法吧