Wicked_Caty Posted April 13, 2016 Posted April 13, 2016 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!
AutoBert Posted April 13, 2016 Posted April 13, 2016 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
Wicked_Caty Posted April 13, 2016 Author Posted April 13, 2016 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.
AutoBert Posted April 13, 2016 Posted April 13, 2016 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 krasnoshtan and Wicked_Caty 1 1
InunoTaishou Posted April 14, 2016 Posted April 14, 2016 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 expandcollapse popup#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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now