Jump to content

Handy tip for edit controls


Recommended Posts

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
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...