SetWindowText and Edit controls
Posted: 14 Oct 2017, 02:36
The proper way to set the text of Edit controls is to use WM_SETTEXT.
However I tested SetWindowText on the Edit control on Notepad, and although it didn't set the text, when I subsequently did GetWindowText, it returned the text that I had set with SetWindowText. Where is this text being stored?
Note: when I manually change the visible text, it does not affect the Get/SetWindowText text.
Note: when I reload the script, it does not affect the Get/SetWindowText text.
Note: when I apply Get/SetWindowText text to an internal AHK GUI window it does get/set the text. (The MSDN articles for the 2 functions say you can use them on internal windows but you are not supposed to use them on external windows.)
This is potentially useful, if an Edit control can have in effect two separate buffers for storing text consistently. You can store additional information there.
However I tested SetWindowText on the Edit control on Notepad, and although it didn't set the text, when I subsequently did GetWindowText, it returned the text that I had set with SetWindowText. Where is this text being stored?
Note: when I manually change the visible text, it does not affect the Get/SetWindowText text.
Note: when I reload the script, it does not affect the Get/SetWindowText text.
Note: when I apply Get/SetWindowText text to an internal AHK GUI window it does get/set the text. (The MSDN articles for the 2 functions say you can use them on internal windows but you are not supposed to use them on external windows.)
This is potentially useful, if an Edit control can have in effect two separate buffers for storing text consistently. You can store additional information there.
Code: Select all
q::
WinGet, hWnd, ID, A
ControlGet, hWnd, Hwnd,, Static1, A
ControlGet, hWnd, Hwnd,, Edit1, A
vChars := DllCall("user32\GetWindowTextLength", Ptr,hWnd) + 1
VarSetCapacity(vText, vChars*2, 0)
DllCall("user32\GetWindowText", Ptr,hWnd, Str,vText, Int,vChars)
MsgBox, % vText
vText := "hello"
DllCall("user32\SetWindowText", Ptr,hWnd, Str,vText)
;needed for Static controls
WinSet, Redraw,, % "ahk_id " hWnd
return
w::
Gui, New, +HwndhGui, MyWinTitle
Gui, Add, Edit
Gui, Show
return