改进实时快搜ahk进程管理器

之前改进了一下ahk进程管理器

群友提出需要个快搜功能

本来还想弄个标颜色的功能,感觉有了快搜其实意义不大,不折腾了

看一下实时快搜的效果,另外原生的快捷键改成按^组合键

感谢蜜罐老哥提供了操作edit的函数,让激活快搜窗口耿精确

使用方法:^f激活快搜窗口直接输入就可以了,不需要按回车

改进实时快搜ahk进程管理器

 

改进版源码

;修改所有快捷键为ctrl作为组合键避免影响快搜
if !(A_IsAdmin || InStr(DllCall("GetCommandLine", "str"), ".exe"" /r"))
	Run % "*RunAs " (s:=A_IsCompiled ? "" : A_AhkPath " /r ") """" A_ScriptFullPath """" (s ? "" : " /r")
	title:="hzn_AHKManager_V1.0"
Hotkey, IfWinActive, %title%
Hotkey, ^f, focus
#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 h600 w800 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+5 gReloadAll, 重启全部A
	Gui, Add, Button, x+5 gRefreshList vBtnRefresh, 刷新列表N
	Gui, Add, Edit,x+5 vKuaiSou gKuaiSouRefreshList HWNDhedit
	Gui, Show,, %title%
}

focus:
; ControlFocus, edit1,%title%
CEdit.FocusToLine(hedit,1)
Return

KuaiSouRefreshList:
	Gui, submit, nohide
	KuaiSouRefreshList()
Return

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
}

KuaiSouRefreshList() {
	Global KuaiSou
	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
				if instr(fName, KuaiSou)
				{
					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


Class CEdit
{
	;获取Edit控件内指定行文本内容
	GetLineChar(HWND, LineNumber=-1){
		static EM_GETLINE=196
		if (LineNumber = -1)
			LineNumber := this.GetCaretLine(HWND)
		len := this.LineLength(HWND, LineNumber)
		ifEqual, len, 0, return
		VarSetCapacity(Text, len*4,0), NumPut(len = 1 ? 2 : len, Text)
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_GETLINE, "Ptr", LineNumber-1, "Ptr", &Text, "Ptr")
		VarSetCapacity(Text, -1)
		return len = 1 ? SubStr(Text, 1, -1) : Text
	}
	LineLength(HWND, LineNumber) {
		static EM_LINELENGTH=193
		Return DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_LINELENGTH, "Ptr", LineNumber, "Ptr", 0, "Ptr")
	}
	;根据字符在edit控件的位置获取字符坐标
	GetPosFromChar(HWND,CharPos,ByRef X,ByRef Y){
		Static EM_POSFROMCHAR:=0xD6
		p:=DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_POSFROMCHAR, "Ptr", CharPos, "Ptr", 0, "Ptr")
		X:=(p & 0xFFFF)<<48>>48
		;-- LOWORD of result and converted from UShort to Short
		Y:=(p>>16)<<48>>48
		;-- HIWORD of result and converted from UShort to Short
	}
	;定位到edit控件指定行位置
	FocusToLine(HWND,LineNumber,toend:=True){
		Static EM_LINEINDEX := 0xBB
		Static EM_LINESCROLL:=0xB6
		Static EM_SCROLLCARET := 0x00B7
		static EM_GETSCROLLPOS:=1245,EM_SETSCROLLPOS:=1246
		VarSetCapacity(POINT, 8, 0)
		Pos:=DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_LINEINDEX, "Ptr", LineNumber-1, "Ptr", 0, "Ptr")
		len := this.LineLength(HWND, LineNumber)
		this.SetSel(HWND, toend?Pos+1+len:Pos+1, toend?Pos+1+len:Pos+1)
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_SCROLLCARET, "Ptr", 0, "Ptr", 0, "Ptr")
		this.GetPosFromChar(HWND,toend?Pos+1+len:Pos+1,xpos,ypos)
		ControlFocus,,ahk_id %HWND%
		DllCall("User32.dll\SetCaretPos", "Int", xpos, "Int", ypos)
		Return toend?Pos+1+len:Pos+1
	}
	;获取光标在edit控件中的第几行
	GetCaretLine(HWND){
		Static EM_LINEINDEX := 0xBB
		Static EM_EXLINEFROMCHAR := 0x0436
		Static EM_LINEFROMCHAR = 0xC9
		Pos:=DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_LINEINDEX, "Ptr", -1, "Ptr", 0, "Ptr")
		Return DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_LINEFROMCHAR, "Ptr", Pos, "Ptr", 0, "Ptr")+1
	}
	;有edit控件第几行插入字符,插入前面还是后面取决于toend
	InsertChar(HWND,Text,LineNumber,toend=True){
		Static EM_REPLACESEL := 0xC2
		CharPos:=this.FocusToLine(HWND,LineNumber,toend)
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_REPLACESEL, "Ptr",1, "Ptr", &text, "Ptr")
		Pos := this.GetSel(HWND),this.SetSel(HWND, Pos.start, Pos.End)
	}
	;向edit控件追加字符,newline追加时是否换行
	Append(HWND, text,newline:=True){
		Static EM_REPLACESEL:=0xC2
		Static WM_VSCROLL:=0x115
		ControlFocus,,ahk_id %HWND%
		this.ScrollCaret(HWND),Text:=newline?"`r`n" Trim(Text,"`r`n"):Text
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_REPLACESEL, "Ptr",1, "Ptr", &text, "Ptr")
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", WM_VSCROLL, "Ptr", 7, "Ptr", 0, "Ptr")
		pos:=this.GetSel(HWND),this.SetSel(HWND, pos.End, pos.End)
		;this.GetPosFromChar(HWND,pos.End,xpos,ypos)
		;DllCall("User32.dll\SetCaretPos", "Int", xpos, "Int", ypos)
	}
	;获取edit控件中内容总行数
	GetLineCount(HWND){
		Static EM_GETLINECOUNT := 0xBA
		Return DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_GETLINECOUNT, "Ptr", 0, "Ptr", 0, "Ptr")
	}
	;设置edit控件内字符与控件边框的左右间距
	SetMargins(Hwnd, Left := "", Right := "") {
		Static EM_SETMARGINS = 0x00D3
		Set := 0 + (Left <> "") + ((Right <> "") * 2)
		Margins := (Left <> "" ? Left & 0xFFFF : 0) + (Right <> "" ? (Right & 0xFFFF) << 16 : 0)
		Return DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_SETMARGINS, "Ptr", Set, "Ptr", Margins, "Ptr")
	}
	;滚动编辑控件的内容到最后一行直到插入符号可见,NoHighlight去高亮显示
	ScrollCaret(HWND,NoHighlight:=True) { ; Scrolls the caret into view.
		Static EM_SCROLLCARET := 0x00B7
		Static EM_SETSEL:=0x00B1
		Count:=this.GetLineCount(HWND)
		this.FocusToLine(HWND,this.GetLineChar(HWND, Count)<>""?Count:Count-1,True),this.SetSel(HWND, -2, -1)
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_SCROLLCARET, "Ptr", 0, "Ptr", 0, "Ptr")
		Return True
	}
	;获取edit控件鼠标选中字符的首尾位置
	GetSel(HWND) {
		Static EM_GETSEL = 0x00B0
		start:=0,End:=0
		DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_GETSEL, "Ptr", &start, "Ptr", &end, "Ptr")
		Return {Start: NumGet(start, 0, "UInt"), End: NumGet(end, 0, "UInt")}
	}
	;选中edit控件中指定位置的字符
	SetSel(HWND, Start, End) {
		Static EM_SETSEL:=0x00B1
		Return DllCall("User32.dll\SendMessage", "Ptr", HWND, "UInt", EM_SETSEL, "Ptr", Start - 1, "Ptr", End - 1, "Ptr")
	}
	;当edit控件内容为空时设置水印提示字符,Edit框为单行时显示
	SetCueBanner(Hwnd, string, hideonfocus := true){
		static EM_SETCUEBANNER := 0x1501
		return DllCall("user32\SendMessage", "ptr", Hwnd, "uint", EM_SETCUEBANNER, "int", hideonfocus, "str", string, "int")
	}
}

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

光速吟唱-文本快速输入工具

2022-8-2 13:26:46

其他应用

AHKInfo 1.3.5 加宽修正版 by dbgba

2022-8-3 19:33:59

3 条回复 A文章作者 M管理员
  1. AHK中文社区
    1河许人给您打赏了¥2
  2. usnake

    为啥我打开是乱码呢

    • 而今迈步从头越

      我晚上发个编译版本的分享吧,直接下载编译版本的用就行了

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