AutoHotkey进程管理-Lion

NoEnv NoTrayIcon SingleInstance Force SetBatchLines -1 DetectHiddenWindows On CreateGUI() CreateMenu() RefreshList() ret

AutoHotkey进程管理-Lion

#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 
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
应用

小白快速安装AutoHotKey教程

2021-8-12 16:16:45

应用

Autohotkey实现的批量复制粘贴工具-feiyue

2021-8-15 14:01:27

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
❯
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索