AutoHotkey Community

It is currently May 27th, 2012, 2:41 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 22nd, 2009, 3:15 am 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 4:42 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 4:48 am 
Offline

Joined: July 18th, 2006, 12:18 pm
Posts: 403
When working with AHK GUI's Inside your own code.. You really should not use 'Control'


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 22nd, 2009, 4:52 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 7:30 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 22nd, 2009, 4:46 pm 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
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 !


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 5:59 pm 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 6:01 pm 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2009, 11:32 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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. :wink:

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 12:58 am 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 1:19 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
That's a common problem, both for logging and for chat windows. You might find this example interesting: Multi Line Edit control woes FIXED!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 7:20 am 
Offline

Joined: July 30th, 2005, 3:49 pm
Posts: 42
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, Bing [Bot], rbrtryn and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group