Sign in to follow this  
Followers 0
lte5000

Handy tip for edit controls

3 posts in this topic

In edit controls, linefeeds apparently don't appear as you would normally expect, other than when using the enter key to manually insert a linefeed.

So the (only?) way to show linefeeds properly when setting an edit control with data which contains linefeeds is to ControlSend() an enter keystroke after each new line...

Here's a quick script in which I used this method.

Global $boolStarted
Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
Opt("WinSearchChildren", 1)
GUICreate("Current Weather", @DesktopWidth - 100, @DesktopHeight - 100)
$edit_1 = GUISetControl("edit",  "", 5, 5, @DesktopWidth - 150, @DesktopHeight - 150)
$button_1 = GUISetControl("button",  "Next", @DesktopWidth - 140, 5, 35, @DesktopHeight - 150)
GUIShow()
While 1
        $msg = GUIMsg(0)
        Select
                Case $msg = $button_1
                        $iToggle = Not $iToggle
                        If $iToggle Then 
                                GUIWrite($edit_1, "", "Ready to load WX data...")
                                URLDownloadToFile("http://www.srh.noaa.gov/data/CTP/AFDCTP", "wx.tmp")
                                $hfile = FileOpen("wx.tmp", 0)
                                While 1
                                        $szLine = FileReadLine($hfile)
                                        If @error = -1 Then ExitLoop
                                        If $szLine <> "" Then GUIWrite($edit_1, "", $szLine)
                                        ControlSend("Current Weather", "", "Edit1", "{ENTER}")
                                        Sleep(5)
                                Wend
                                FileClose($hfile)
                        Else
                                GUIWrite($edit_1, "", "Ready to load WX data...")
                                ControlSend("Current Weather", "", "Edit1", "{ENTER}")
                                URLDownloadToFile("http://www.accuweather.com", "wx.tmp")
                                $hfile = FileOpen("wx.tmp", 0)
                                While 1
                                        Sleep(5)
                                        $szLine = FileReadLine($hfile)
                                        If Not StringInStr($szLine, "A Glimpse Inside Joe's Column...") And Not $boolStarted Then ContinueLoop
                                        $boolStarted = 1
                                        If $boolStarted And Not StringInStr($szLine, "<b>") Then ContinueLoop
                                        If StringInStr($szLine, "A Glimpse Inside Joe's Column...") Then ContinueLoop
                                        If StringInStr($szLine, "<b>") Then 
                                                $iStartPos = StringInStr($szLine, "<b>")
                                                $iEndPos = StringInStr($szLine, "</b>")
                                        EndIf
                                        $szQuote = StringMid($szLine, $iStartPos + 3, $iEndPos - $iStartPos - 3)
                                        If $szLine <> "" Then GUIWrite($edit_1, "", $szQuote)
                                        ExitLoop
                                Wend
                                FileClose($hfile)
                        EndIf
                Case $msg = -3
                        Exit
        EndSelect
        Sleep(10)
Wend

Share this post


Link to post
Share on other sites



Did you try @CRLF? That's the only thing that properly places a newline in an edit control, I believe.

Share this post


Link to post
Share on other sites

Did you try @CRLF?

No.

That's the only thing that properly places a newline in an edit control, I believe.

Yes you're right. Inserting an @CRLF is a better way than sending "Enter".

Thanks.

Kendall

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0