Wicked_Caty

No carriage return in label

5 posts in this topic

My program generates a huge lot of numbers that has to be displayed in a label. Usually there are around 100 thousand and 1 million numbers, so I obviously have certain problems with space. I get the data into the label, but it's all in one line and simply exceeds the label (by a couple of million pixels, but never mind that)... Of course it won't fit into a 200x200 big label either, but it'd look a lot nicer. I don't even need to scroll in it.

The only thing in need is an automatic @CRLF at the border of the label.

Something like the style $ES_MULTILINE for the input box.

Here's the most important stuff from the GUI.

Local $gui = GUICreate("Crypt", 630, 440)
    Local $in = GUICtrlCreateInput("", 10, 10, 300, 300, $ES_MULTILINE) ; need something like $ES_MULTILINE just one line later in this code
    Local $out = GUICtrlCreateLabel("", 320, 10, 300, 300) ; instead of "", please imagine a random number between 1e5 and 1e6 here please
    ; a lot of buttons that don't matter right now

    GUISetBkColor(0x111111, $gui)
    GUICtrlSetBkColor($in, 0xEEEEEE)
    GUICtrlSetBkColor($out, 0xEEEEEE)
    ; again a lot of button configuartion that's completely unnecessary right now

    GUICtrlSetColor($in, 0x111111)
    GUICtrlSetColor($out, 0x111111)
    ; same as before

    GUISetFont(13, 200, 0, "Candara", $gui)
    GUICtrlSetFont($in, 13, 200, 0, "Candara")
    GUICtrlSetFont($out, 13, 200, 0, "Candara")
    ; still configuation for the buttons

    Local $data0 = ""
    ; some unimportant variables

    GUISetState(@SW_SHOW, $gui)
    
    ; switch from GUIGetMsg() in an infinite while-loop

Thanks!

Share this post


Link to post
Share on other sites



Try this:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateLabel("Line 1 "&@CRLF&"Line 2", 10, 30, 100,59)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
1 minute ago, AutoBert said:

Try this:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateLabel("Line 1 "&@CRLF&"Line 2", 10, 30, 100,59)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

EndFunc   ;==>Example

 

It would be nice, if I could just squeeze it in manually. Sadly, it doesn't work. I get those numbers in a huge single string, and it has to be exactly that way for further processing. There's nothing I could change about that.

The program has to detect itself when the numbers would exceed the limits of the label. Then it has to put them into the next line without adding an actual carriage return. Similar to what is done in the input box in my example.

Share this post


Link to post
Share on other sites

Then try this:

; *** Start added by AutoIt3Wrapper ***
#include <EditConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateEdit("Line 1 "&@CRLF&"Line 2", 10, 30, 100,59,BitOR($ES_MULTILINE, $ES_ReadOnly))
    GUISetState(@SW_SHOW) ;

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

EndFunc   ;==>Example

 

1 person likes this

Share this post


Link to post
Share on other sites

Something like this? I would have finished this sooner but I found it to be an interesting concept and wanted to make it more functional, allowing you to scroll through all the lines. A snippit I will store in my saved functions folder :)

#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

Global $hMain = GUICreate("Multiline", 420, 175)
Global $lblDisplay = GUICtrlCreateLabel("", 10, 10, 380, 130)
Global $btnUpateLabel = GUICtrlCreateButton("Update Label", 10, 145, 380, 20)
Global $btnUp = GUICtrlCreateButton("↑", 390, 10, 25, 25)
Global $btnDown = GUICtrlCreateButton("↓", 390, 115, 25, 25)
Global $lblTopLine = GUICtrlCreateLabel(0 & @CRLF & 0, 395, 60, 30, 30)
Global $aLines = Null
Global $iTopLine = 0

GUICtrlSetFont($btnDown, 14)
GUICtrlSetFont($btnUp, 14)

GUISetState(@SW_SHOW)

While (True)
    Local $sString = ""

    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            GUIDelete($hMain)
            Exit 0
        Case $btnUpateLabel
            Local $iRandomStop = Random(99999, 999999, 1)
            For $i = 0 To $iRandomStop
                $sString &= Random(0, 9, 1)
            Next
            $aLines = LongStringToArray($lblDisplay, $sString, $hMain)
            $iTopLine = 0
            ConsoleWrite("Total string length: " & StringLen($sString) & @CRLF & "Rows created from string: " & UBound($aLines) & @CRLF & "Current string: " & $sString & @CRLF)
            GUICtrlSetDataFromArray($lblDisplay, $aLines, $iTopLine, -1)
            GUICtrlSetData($lblTopLine, $iTopLine + 1 & @CRLF & UBound($aLines))

        Case $btnDown
            If ($iTopLine + 1 < UBound($aLines)) Then
                $iTopLine += 1
                GUICtrlSetDataFromArray($lblDisplay, $aLines, $iTopLine, -1)
                GUICtrlSetData($lblTopLine, $iTopLine + 1 & @CRLF & UBound($aLines))
            EndIf
        Case $btnUp
            If ($iTopLine - 1 >= 0) Then
                $iTopLine -= 1
                GUICtrlSetDataFromArray($lblDisplay, $aLines, $iTopLine, -1)
                GUICtrlSetData($lblTopLine, $iTopLine + 1 & @CRLF & UBound($aLines))
            EndIf
    EndSwitch
WEnd

Func GUICtrlSetDataFromArray(Const $iCtrlid, Const $aArray, $iRowStart = -1, $iRowEnd = -1)
    If (Not IsArray($aArray)) Then Return SetError(1, 0, ConsoleWrite("Array not created yet. Press the Update Label button." & @CRLF))
    If ($iRowStart < 0 Or StringLen($iRowStart) = 0 Or $iRowStart >= UBound($aArray)) Then $iRowStart = 0
    If ($iRowEnd < 0 Or StringLen($iRowEnd) = 0 Or $iRowEnd >= UBound($aArray)) Then $iRowEnd = UBound($aArray) - 1
    Local $sDataString = ""

    For $i = $iRowStart To $iRowEnd
        $sDataString &= $aArray[$i] & @CRLF
    Next

    Return GUICtrlSetData($iCtrlid, StringTrimRight($sDataString, 2))
EndFunc   ;==>GUICtrlSetDataFromArray

Func LongStringToArray(Const $iCtrlid, Const $vValue, Const $hWindow)
    If ($vValue = "") Then Return SetError(1, 0, $vValue)
    Local $hWnd = (IsHWnd($iCtrlid) ? $iCtrlid : GUICtrlGetHandle($iCtrlid))
    Local $sFinalString = ""
    Local $aSize = ControlGetPos($hWindow, "", $iCtrlid)
    Local $iStringLen = StringLen($vValue)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT)
    Local $hSelectObject = _WinAPI_SelectObject($hDC, $hFont)

    For $i = 1 To $iStringLen
        Local $sLine = ""
        Local $bMeasured = False
        Do
            $sLine &= StringMid($vValue, $i, 1)

            Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sLine)

            If (DllStructGetData($tSize, 1) > $aSize[2]) Then
                $sLine = StringTrimRight($sLine, 1)
                $bMeasured = True
            Else
                $i += 1
            EndIf
            $tSize = Null

        Until ($bMeasured Or $i > $iStringLen)

        $sFinalString &= $sLine & @LF
    Next

    _WinAPI_SelectObject($hDC, $hSelectObject)
    _WinAPI_ReleaseDC($hWnd, $hDC)

    Return StringSplit(StringTrimRight($sFinalString, 2), @LF, $STR_NOCOUNT)
EndFunc   ;==>LongStringToArray

Func GUICtrlMeasureString($iCtrlid)
    Local $hWnd = (IsHWnd($iCtrlid) ? $iCtrlid : GUICtrlGetHandle($iCtrlid))
    Local $aReturn[2] = [0, 0]
    Local $sText = GUICtrlRead($iCtrlid)
    Local $aText = Null
    If ($sText = "") Then Return $aReturn

    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT)
    Local $hSelectObject = _WinAPI_SelectObject($hDC, $hFont)
    Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText)

    _WinAPI_SelectObject($hDC, $hSelectObject)
    _WinAPI_ReleaseDC($hWnd, $hDC)

    Return $aReturn
EndFunc   ;==>GUICtrlMeasureString

 

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

  • Similar Content

    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)

       
    • GordonFreeman
      By GordonFreeman
      Hi, i'm trying to save data in an ini key that contains @LF and @CRLF (to use in an edit control). But @LF and @CRLF cause error in ini files (because it breaks the line). Then im trying to find a workaround. Here's the script thanks in advance:
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 438, 192, 124) $hEDIT = GUICtrlCreateEdit("",11,11,600,400) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### IniWrite("JustATest.ini","TestSec","TestKey","TestValue " & @CRLF & "Testing" & @LF & "test") $sData = IniRead("JustATest.ini","TestSec","TestKey","") GUICtrlSetData($hEDIT,$sData) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • hemichallenger
      By hemichallenger
      Not sure if this is possible or if someone has already tackled this. Is it possible to embed PowerShell into a GUI? Autoit is great for quick function but sometime I need to run a command thru PowerShell. It be great to have PowerShell console embedded into the gui.