Cheers just me, I thought if anyone knew, it might be you. Haha in the article they actually call this second text buffer simply a 'special place'. It's great to have some confirmation of the existence of a second buffer. I'd actually saved this article before, but it's far more meaningful this time.
I'll mark this is as solved, although any further details beyond a 'special place' would be welcome. Not that I'm expecting any.
Since Edit controls have two text storage locations, you can store 'secret' text in any Edit control you like. Curiously enough though, if the Edit control belongs to your process, AFAIK you would need a workaround, which is what I have done in the two functions below.
I would use this text buffer as a handy place to store text, when communicating between scripts. I might use the Edit control's text itself, but AutoHotkey can change that text, e.g. when you want to list variables, so to store it in a 'special place' is safer.
Code: Select all
q:: ;Edit control - set 'special place' text
ControlGet, hCtl, Hwnd,, Edit1, A
WinGet, vPID, PID, % "ahk_id " hCtl
vText := "hello " vPID
JEE_EditSetTextSpecialPlace(hCtl, vText)
return
w:: ;Edit control - get 'special place' text
ControlGet, hCtl, Hwnd,, Edit1, A
MsgBox, % JEE_EditGetTextSpecialPlace(hCtl)
return
;==================================================
;q:: ;AutoHotkey main window - set 'special place' text
DetectHiddenWindows, On
ControlGet, hCtl, Hwnd,, Edit1, % "ahk_id " A_ScriptHwnd
WinGet, vPID, PID, % "ahk_id " hCtl
vText := "hello " vPID
JEE_EditSetTextSpecialPlace(hCtl, vText)
return
;w:: ;AutoHotkey main window - get 'special place' text
DetectHiddenWindows, On
ControlGet, hCtl, Hwnd,, Edit1, % "ahk_id " A_ScriptHwnd
MsgBox, % JEE_EditGetTextSpecialPlace(hCtl)
return
;==================================================
;The secret life of GetWindowText – The Old New Thing
;https://blogs.msdn.microsoft.com/oldnewthing/20030821-00/?p=42833
JEE_EditGetTextSpecialPlace(hCtl)
{
static vScriptPID := DllCall("kernel32\GetCurrentProcessId", UInt)
DllCall("user32\GetWindowThreadProcessId", Ptr,hCtl, UIntP,vPID, UInt)
if !(vPID = vScriptPID)
{
vChars := DllCall("user32\GetWindowTextLength", Ptr,hCtl) + 1
VarSetCapacity(vText, vChars*2, 0)
DllCall("user32\GetWindowText", Ptr,hCtl, Str,vText, Int,vChars)
return vText
}
vScript .= "vChars := DllCall(" Chr(34) "user32\GetWindowTextLength" Chr(34) ", Ptr," hCtl ") + 1"
vScript .= "`r`n" "VarSetCapacity(vText, vChars*2, 0)"
vScript .= "`r`n" "DllCall(" Chr(34) "user32\GetWindowText" Chr(34) ", Ptr," hCtl ", Str,vText, Int,vChars)"
vScript .= "`r`n" "FileAppend, % vText, *"
oShell := ComObjCreate("WScript.Shell")
oExec := oShell.Exec(Chr(34) A_AhkPath Chr(34) " /ErrorStdOut *")
oExec.StdIn.Write(vScript)
oExec.StdIn.Close()
vStdOut := oExec.StdOut.ReadAll()
oShell := oExec := ""
return vStdOut
}
;==================================================
JEE_EditSetTextSpecialPlace(hCtl, vText)
{
static vScriptPID := DllCall("kernel32\GetCurrentProcessId", UInt)
DllCall("user32\GetWindowThreadProcessId", Ptr,hCtl, UIntP,vPID, UInt)
if !(vPID = vScriptPID)
{
DllCall("user32\SetWindowText", Ptr,hCtl, Str,vText)
return
}
vText := StrReplace(vText, "``", "````")
vText := StrReplace(vText, "`r", "``r")
vText := StrReplace(vText, "`n", "``n")
if !!SubStr(1,0) ;vIsV1
vText := StrReplace(vText, Chr(34), Chr(34) Chr(34))
else
vText := StrReplace(vText, Chr(34), "``" Chr(34))
vScript := "DllCall(" Chr(34) "user32\SetWindowText" Chr(34) ", Ptr," hCtl ", Str," Chr(34) vText Chr(34) ")"
oShell := ComObjCreate("WScript.Shell")
oExec := oShell.Exec(Chr(34) A_AhkPath Chr(34) " /ErrorStdOut *")
oExec.StdIn.Write(vScript)
oExec.StdIn.Close()
oShell := oExec := ""
}