Выводит последние 66 строк.
SetTimer, ListLines, 333
loop
{
If !Mod(A_Index, 4)
Sleep 1
Sleep 111
}
ListLinesOutput(Text) {
ToolTip % LastLines(Text, 66), 0, 0, 2
}
LastLines(Haystack, Lines) {
If (1, StrReplace(Haystack, "`n", , c)) && (r := c - Lines + 1) > 0
Haystack := SubStr(Haystack, InStr(Haystack, "`n", , , r) + 1)
Return Haystack
}
ListLines() {
Static hwndEdit, pSFW, pSW, bkpSFW, bkpSW
ListLines Off
if !hwndEdit
{
; Retrieve the handle of our main window's Edit control:
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Process, Exist
ControlGet, hwndEdit, Hwnd,, Edit1, ahk_class AutoHotkey ahk_pid %ErrorLevel%
DetectHiddenWindows, %dhw%
astr := A_IsUnicode ? "astr" : "str"
hmod := DllCall("GetModuleHandle", "str", "user32.dll")
; Get addresses of these two functions:
pSFW := DllCall("GetProcAddress", "uint", hmod, astr, "SetForegroundWindow")
pSW := DllCall("GetProcAddress", "uint", hmod, astr, "ShowWindow")
; Make them writable:
DllCall("VirtualProtect", "uint", pSFW, "uint", 8, "uint", 0x40, "uint*", 0)
DllCall("VirtualProtect", "uint", pSW, "uint", 8, "uint", 0x40, "uint*", 0)
; Save initial values of the first 8 bytes:
bkpSFW := NumGet(pSFW+0, 0, "int64")
bkpSW := NumGet(pSW+0, 0, "int64")
}
; Overwrite SetForegroundWindow() and ShowWindow() temporarily:
NumPut(0x0004C200000001B8, pSFW+0, 0, "int64") ; return TRUE
NumPut(0x0008C200000001B8, pSW+0, 0, "int64") ; return TRUE
; Dump ListLines into hidden AutoHotkey main window:
ListLines
; Restore SetForegroundWindow() and ShowWindow():
NumPut(bkpSFW, pSFW+0, 0, "int64")
NumPut(bkpSW, pSW+0, 0, "int64")
; Retrieve ListLines text and strip out some unnecessary stuff:
ControlGetText, ListLinesText,, ahk_id %hwndEdit%
RegExMatch(ListLinesText, ".*`r`n`r`n\K[\s\S]*(?=`r`n`r`n.*$)", ListLinesText)
StringReplace, ListLinesText, ListLinesText, `r`n, `n, All
ListLinesOutput(ListLinesText)
; ListLines On
; return ListLinesText ; This line appears in ListLines if we're called more than once.
}