 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Sun Nov 22, 2009 2:15 am Post subject: appending a string to GUI Edit control -- newline issue |
|
|
I want to append a string containing newline chars (`n) to an AHK GUI Edit control. I want each of those chars to trigger a new line.
If I write a string using this code
| Code: | | Control, EditPaste, %someStringToWrite%, Edit1, ahk_id %our_UID% |
newline chars show up as square boxes. No new lines. Blechhh.
If I write a string using this code
| Code: | | GuiControl,, EditControl1, %someStringToWrite% |
newline chars cause new lines, as I'd like.
Okay, I'm thinking, maybe we need carriage-return newline pairs. Reading the docs for GuiControl, it seems to confirm my thinking, as it mentions how newlines are turned into carriagereturn newline pairs for writing to an Edit control. However, if I tweak my string so as to do the same transformation. using code like this:
| Code: | | StringReplace, someStringToWrite, someStringToWrite, `n, `r`n, All |
... and then write that transformed string using Control EditPaste, the problem of the little boxes persists.
Anyone got a fix for this ? I like using Control EditPaste because of its appendation properties.
== noob stan |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 1770 Location: MN, USA
|
Posted: Sun Nov 22, 2009 3:42 am Post subject: |
|
|
It works for me. | Code: | string = line1`nline2`nline3`nline4`nline5
StringReplace, string, string, `n, `r`n, All
Gui, Add, Edit, r10 w200
Gui, Show
Sleep,1500
Control, EditPaste, %string%, Edit1, A
return
GuiClose:
ExitApp |
_________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 401
|
Posted: Sun Nov 22, 2009 3:48 am Post subject: |
|
|
| When working with AHK GUI's Inside your own code.. You really should not use 'Control' |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 1770 Location: MN, USA
|
Posted: Sun Nov 22, 2009 3:52 am Post subject: Re: appending a string to GUI Edit control -- newline issue |
|
|
I was about to say the same, but GuiControl does not have an EditPaste subcommand. I'm about to put it on the Wish List.
| Stanley Krute wrote: | | I like using Control EditPaste because of its appendation properties. |
_________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 2431
|
Posted: Sun Nov 22, 2009 6:30 am Post subject: |
|
|
Here's a workaround:
| Code: | var=i want you to append this`r`nand this`r`nand this
highlight={CTRLDOWN}{SHIFTDOWN}{HOME}{SHIFTUP}{CTRLUP}
reltrl=\.*?+[{|()^$
F1::
Clipboard=
ControlGetFocus, ctrl, << WinTitle >>
ControlGetText, full, %ctrl%, << WinTitle >>
Loop {
ControlSend, %ctrl%, %highlight%, << WinTitle >> ; highlight everything from caret to beginning of Edit box
ControlSend, %ctrl%, ^c, << WinTitle >>
ClipWait, 0
if Clipboard ; once copy has completed
Break
}
temp:=Clipboard ; pass string to temp var
Loop, Parse, reltrl ; loop through potential conflicting regex chars
StringReplace, Clipboard, Clipboard, %A_LoopField%, \%A_LoopField%, All ; append escape char to those that exist
Clipboard:=temp . var . RegExReplace(full,Clipboard)
ClipWait
ControlSetText, %ctrl%, , << WinTitle >>
ControlSend, %ctrl%, ^v, << WinTitle >>
return |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Sun Nov 22, 2009 3:46 pm Post subject: Re: appending a string to GUI Edit control -- newline issue |
|
|
| jaco0646 wrote: | | GuiControl does not have an EditPaste subcommand. I'm about to put it on the Wish List. |
That would solve this particular issue quite nicely ! |
|
| Back to top |
|
 |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Sun Nov 22, 2009 4:59 pm Post subject: |
|
|
| jaco0646 wrote: | It works for me. | Code: | string = line1`nline2`nline3`nline4`nline5
StringReplace, string, string, `n, `r`n, All
Gui, Add, Edit, r10 w200
Gui, Show
Sleep,1500
Control, EditPaste, %string%, Edit1, A
return
GuiClose:
ExitApp |
|
Yep, that works for me too.
Hmmm .... must be something else in my code ... hmmm ....
Aha !!! Had to cleanup/debug my string manipulation functions ....
Now things are working just fine.
Thanks jaco0646 and everyone else who's assisted on this'un ....
== noob stan |
|
| Back to top |
|
 |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Sun Nov 22, 2009 5:01 pm Post subject: |
|
|
| i3egohan wrote: | | When working with AHK GUI's Inside your own code.. You really should not use 'Control' |
Could you or someone else elaborate on this ? e.g., why this really should not be done ??
thx
== noob stan |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 1770 Location: MN, USA
|
Posted: Sun Nov 22, 2009 10:32 pm Post subject: |
|
|
Control is a generic command for working with third-party GUIs. GuiControl is designed specifically for AutoHotkey GUIs (and in fact only for AutoHotkey GUIs). For example, GuiControl works with your controls’ associated output variables, rather than just the ClassNN or text. This makes it more reliable. Using GuiControl, you also don't have to worry about WinTitle, WinText, ExcludeTitle, ExcludeText. Of course, GuiControl also offers many more options for working with your individual controls; EditPaste just isn’t one of them.
I've always appended text this way; but the annoying thing is that this moves the cursor to the beginning of the control, so EditPaste has it beat in that respect too. | Code: | string1 = line1`nline2`nline3`nline4`nline5
string2 = line6`nline7`nline8`nline9`nline10
stringReplace, string2, string2, `n, `r`n, All
Gui, Add, Edit, r10 w200 vMyEdit, %string1%
Gui, Show
Sleep,1500
Gui, Submit, NoHide
GuiControl,,MyEdit, % string1 "`n" string2
return
GuiClose:
ExitApp |
_________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Sun Nov 22, 2009 11:58 pm Post subject: |
|
|
| jaco0646 wrote: |
I've always appended text this way; but the annoying thing is that this moves the cursor to the beginning of the control, so EditPaste has it beat in that respect too. | Code: | string1 = line1`nline2`nline3`nline4`nline5
string2 = line6`nline7`nline8`nline9`nline10
stringReplace, string2, string2, `n, `r`n, All
Gui, Add, Edit, r10 w200 vMyEdit, %string1%
Gui, Show
Sleep,1500
Gui, Submit, NoHide
GuiControl,,MyEdit, % string1 "`n" string2
return
GuiClose:
ExitApp |
|
Yes, that was my first approach to appending. But the cursor going to the beginning killed it for me for my particular current need, a scroll-barred logging pane that fills with data, where you'd like to be looking at the most recent info, which is at the end. Moving the cursor down after using the GuiControl technique caused flicker, which was particularly bad when the logging window was filling with lots of little bits of text quickly. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 1770 Location: MN, USA
|
|
| Back to top |
|
 |
Stanley Krute
Joined: 30 Jul 2005 Posts: 38
|
Posted: Mon Nov 23, 2009 6:20 am Post subject: |
|
|
Oh I've had fun today exploring this.
One path ate up a bunch of time, ultimately wasn't optimal, but taught me a lot. I implemented a general stack functionality. Then, if I append a string to my read-only Edit control log, I can push its length onto a stack of such string appendation lengths. If I want to remove the last string[s] written to the log, I can pull their length[s] off the stack, and use that number to build up a string (shift down plus my string[s] length's worth of Left's plus shift up) that lets me select that/those last strings, and then use EditPaste to replace them. Unfortunately, if the AHK window is topmost, you get to see a blue selection wipe occur before the new text appears. Blech.
Yep, I'd like GuiControl to have EditPaste functionality.
I'd also like Edit controls to have -redraw functionality. So one could do things while redraw was off, then turn it on again.
I'd like to quickly turn ReadOnly-ness on and off for Edit controls. So I could send string of text-erasing Backspace keystrokes to my logging pane during a momentary not-ReadOnly period.
Such a greedy needy noob .....
Thx again everyone for the brainstorming and idea-sharing ...
-- stan |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|