Does Edit box can be append text?
Does Edit box can be append text?
append text to the end of text box, like FileAppend, and always show last line.
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: Does Edit box can be append text?
try this:
Code: Select all
var := "some text"
gui, add, edit, x0 y0 w200 h200 vtxt, % var
gui, add, button, x0 y+5 gadd, add some more
gui, show
return
add:
gui, submit, nohide
txt .= " and some more"
guicontrol,, txt, %txt%
guicontrol,focus,txt
send, ^{end}
return
14.3 & 1.3.7
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Does Edit box can be append text?
Or like this:
Code: Select all
text := " add some more"
Gui, Add, Edit, w200 h200 hwndhEdit
Gui, Add, Button, xp y+5, Add Text
handler := Func("AppendText").Bind(text, hEdit)
GuiControl, +g, Button1, % handler
Gui, Show
Return
AppendText(text, hEdit) {
static WM_GETTEXTLENGTH := 0x0E
, EM_SETSEL := 0xB1
, EM_REPLACESEL := 0xC2
WinWait, ahk_id %hEdit%
SendMessage, WM_GETTEXTLENGTH
SendMessage, EM_SETSEL, ErrorLevel, ErrorLevel
SendMessage, EM_REPLACESEL, true, &text
}
Re: Does Edit box can be append text?
Thank you very much, this is I need code.teadrinker wrote: ↑27 May 2020, 10:33Or like this:Code: Select all
text := " add some more" Gui, Add, Edit, w200 h200 hwndhEdit Gui, Add, Button, xp y+5, Add Text handler := Func("AppendText").Bind(text, hEdit) GuiControl, +g, Button1, % handler Gui, Show Return AppendText(text, hEdit) { static WM_GETTEXTLENGTH := 0x0E , EM_SETSEL := 0xB1 , EM_REPLACESEL := 0xC2 WinWait, ahk_id %hEdit% SendMessage, WM_GETTEXTLENGTH SendMessage, EM_SETSEL, ErrorLevel, ErrorLevel SendMessage, EM_REPLACESEL, true, &text }
Re: Does Edit box can be append text?
This code is not the best, because it is reload all text every time, text box will flash 0.0001 secend :pflyingDman wrote: ↑27 May 2020, 10:15try this:Code: Select all
var := "some text" gui, add, edit, x0 y0 w200 h200 vtxt, % var gui, add, button, x0 y+5 gadd, add some more gui, show return add: gui, submit, nohide txt .= " and some more" guicontrol,, txt, %txt% guicontrol,focus,txt send, ^{end} return
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: Does Edit box can be append text?
Add:
to both scripts. @teadrinker 's version will take about 12.5 seconds to complete adding 100 small strings of text. My simple script does it in 3.125 seconds. @Bral, the 0.0001 second flash (btw it does not flash here...) is insignificant compared to these numbers.
@teadrinker : nice script; I learned something new.
Code: Select all
#\::
a := A_TickCount
loop,100
ControlClick, Button1, A,,,1
MsgBox, % A_TickCount - a
return
@teadrinker : nice script; I learned something new.
14.3 & 1.3.7
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Does Edit box can be append text?
@flyingDman
I'm not sure that your test is correct. Try this:
Or this:
WinWait was here just to shorten the code.
I'm not sure that your test is correct. Try this:
Code: Select all
text := " add some more"
Gui, Add, Edit, w200 h200 hwndhEdit
Gui, Add, Button, xp y+5, Add Text
handler := Func("AppendText").Bind(text, hEdit)
GuiControl, +g, Button1, % handler
Gui, Show
Return
AppendText(text, hEdit) {
static WM_GETTEXTLENGTH := 0x0E
, EM_SETSEL := 0xB1
, EM_REPLACESEL := 0xC2
start := A_TickCount
WinWait, ahk_id %hEdit%
Loop 100 {
SendMessage, WM_GETTEXTLENGTH
SendMessage, EM_SETSEL, ErrorLevel, ErrorLevel
SendMessage, EM_REPLACESEL, true, &text
}
MsgBox, % A_TickCount - start
}
Code: Select all
text := " add some more"
Gui, Add, Edit, w200 h200 hwndhEdit
Gui, Add, Button, xp y+5, Add Text
handler := Func("AppendText").Bind(text, hEdit)
GuiControl, +g, Button1, % handler
Gui, Show
Return
AppendText(text, hEdit) {
static WM_GETTEXTLENGTH := 0x0E
, EM_SETSEL := 0xB1
, EM_REPLACESEL := 0xC2
start := A_TickCount
Loop 100 {
SendMessage, WM_GETTEXTLENGTH,,,, ahk_id %hEdit%
SendMessage, EM_SETSEL, ErrorLevel, ErrorLevel,, ahk_id %hEdit%
SendMessage, EM_REPLACESEL, true, &text,, ahk_id %hEdit%
}
MsgBox, % A_TickCount - start
}
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: Does Edit box can be append text?
I think my test more accurately simulate the process of manually adding by clicking the button. I noticed the difference in speed when i was clicking myself. It felt sluggish.
But to make it an apple to apple comparison: will result is very similar times. Mine minimally slower. But I don't want to make this a p... contest. Your code shows an impressive way of doing this.
But to make it an apple to apple comparison:
Code: Select all
gui, add, edit, w200 h200 vtxt,
gui, add, button, y+5 gadd, add some more
gui, show
return
add:
a := A_TickCount
gui, submit, nohide
Loop, 100
{
txt .= " add some more"
guicontrol,, txt, %txt%
}
guicontrol,focus,txt
send, ^{end}
MsgBox, % A_TickCount - a
return
14.3 & 1.3.7
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Does Edit box can be append text?
Try your test several times without removing an existing text.
Re: Does Edit box can be append text?
I tested add 1000 times, your code is faster, But i don't know why need WM_GETTEXTLENGTH and EM_SETSEL? i delete that 2 line and code work fine.teadrinker wrote: ↑27 May 2020, 13:46Try your test several times without removing an existing text.
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Does Edit box can be append text?
It may work without these commands only if the caret is located at the end of the text.
WM_GETTEXTLENGTH gets the text length, EM_SETSEL sets the caret at the end, EM_REPLACESEL inserts the text at the caret position.
WM_GETTEXTLENGTH gets the text length, EM_SETSEL sets the caret at the end, EM_REPLACESEL inserts the text at the caret position.
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Does Edit box can be append text?
@just me
Interesting idea about SendMessage, 0x00B1, -2, -1, but it doesn't speed up the code.
Interesting idea about SendMessage, 0x00B1, -2, -1, but it doesn't speed up the code.