mikell Posted October 7, 2010 Share Posted October 7, 2010 (edited) Hello In my script I use Melba23's stringsize func If some characters like: $ ( ) & ' _ are present in the managed string then I get an error message So which are all forbidden characters for this kind of func ? Couldnt find this in autoit help or in forum... And is there an easy way to check if these characters exist in a string ? I mean easier than: If StringInStr($string, "$") OR ... etc Thanks for any help Here is my script expandcollapse popup;simple 'post-it' script (stupid but funny to build) ;auto-resize window and label according to the text <--this was funny ;(many thanks to Melba23 for the nice stringsize function !) #NoTrayIcon #include <StaticConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> Opt("WinTitleMatchMode", 2) Opt("GuiOnEventMode", 1) Global $gui, $header, $text, $label1, $menu, $input1, $exit1, $exit2 Global $log, $name, $inputgui, $okbtn, $inputbox, $post = "" Global $w = 150, $h = 100 Global $x = 400, $y = 20 Global $sFont = "Tahoma" Global $iSize = 16 Global $iWeight = 400 Global $iAttrib = 0 Global $PostitPath = FileGetLongName(@WorkingDir & "\Post-it.exe") Global $datadir = "C:\" ;@desktopdir ; log files place Global $FileList $FileList = _FileListToArray($datadir, "Post-It *" & ".log") ; check logs If Not @error Then ; if log(s) found, then For $i = 1 To $FileList[0] $name = StringTrimRight($FileList[$i], 4) $log = $datadir & "\" & $FileList[$i] If NOT WinExists($name) Then $file = FileOpen($log, 0) $post = FileRead($file) FileClose($file) _CreatePostitGui() ; recreate post-it _ManageText() ; recreate saved text & update log Exitloop Else If $i = $FileList[0] Then _RunBasicGui() EndIf Sleep(1000) Next Else ; if no log found _RunBasicGui() EndIf $log = $datadir & "\" & $name & ".log" While 1 Sleep(10) Wend ;=================================== Func _RunBasicGui() $name = "Post-It 1" $var = WinList("Post-It") ; set post-it name & title, different from possible existing ones For $i = 1 to $var[0][0] If NOT WinExists ("Post-It " & $i) Then $name = "Post-It " & $i ExitLoop Else $name = "Post-It " & $i+1 EndIf Next _CreatePostitGui() EndFunc Func _CreatePostitGui() $var = WinList("Post-It") ; set the new post-it position so it doesnt overlap other ones $ok_x = true For $x = 400 To @desktopwidth-170 For $i = 1 to $var[0][0] $ok_x = true $prevpos = WinGetPos($var[$i][0]) If $prevpos[1] > 130 Then ContinueLoop $xrefpos1 = $prevpos[0]-170 $xrefpos2 = $prevpos[0]+$prevpos[2]+10 If $x > $xrefpos1 AND $x < $xrefpos2 Then $ok_x = false ExitLoop EndIf Next If $ok_x = true Then ExitLoop ; exit & set a new $x Next $gui = GUICreate($name, $w, $h, $x, $y, $WS_POPUP, $WS_EX_TOPMOST) GUISetBkColor (0xffdd00, $gui) $header = GUICtrlCreateLabel ($name, 0, 0, $w, 15, $SS_CENTER) GUICtrlSetColor(-1, 0xffaa00) GUICtrlSetBkColor(-1, 0xffd500) GUICtrlSetResizing(-1, $GUI_DOCKHEIGHT) $text = GUICtrlCreateLabel ("", 10, 15, $w-20, $h-30, $SS_CENTER) GUICtrlSetBkColor(-1, 0xffdd00) GUICtrlSetFont(-1, 16, 400, "Tahoma") $label1 = GUICtrlCreateLabel("", 0, 0, $w, $h, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetState($label1,$GUI_ONTOP) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) $menu = GuiCtrlCreateContextMenu($label1) $input1 = GuiCtrlCreateMenuitem ("Enter the Message" ,$menu) GUICtrlSetOnEvent($input1, "_InputGui") GuiCtrlCreateMenuitem ("",$menu) $exit1 = GuiCtrlCreateMenuitem ("Save Post-it and Quit",$menu) GUICtrlSetOnEvent($exit1, "_Close") $exit2 = GuiCtrlCreateMenuitem ("Delete this Post-it",$menu) GUICtrlSetOnEvent($exit2, "_Terminate") GUISetState() EndFunc ;==>_CreatePostitGui() Func _InputGui() GUICtrlSetState ($input1, $GUI_DISABLE) $pos = WinGetPos($gui) $inputgui = GUICreate("Input", $pos[2], 125, $pos[0], $pos[1]+$pos[3]+5, $WS_POPUP, $WS_EX_TOPMOST) GUISetBkColor (0xffdd00, $inputgui) $label2 = GUICtrlCreateLabel("", 0, 0, $pos[2], 125, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) $inputbox = GUICtrlCreateEdit( "", 5, 8 , $pos[2]-10, 85, $ES_MULTILINE + $ES_WANTRETURN + $ES_AUTOVSCROLL) GUICtrlSetState(-1,$GUI_ONTOP + $GUI_FOCUS) $okbtn = GUICtrlCreateButton(" OK ", $pos[2]/2-25, 98, 50, 22) GUICtrlSetState(-1,$GUI_ONTOP) GUICtrlSetBkColor(-1, 0xffd000) GUICtrlSetColor(-1, 0xff3300) GUICtrlSetOnEvent($okbtn, "_Input") GUISetState(@SW_SHOW, $inputgui) If GuiCtrlRead($text)<>"" Then GUICtrlSetData($inputbox, $post) EndFunc Func _Input() $post = GUICtrlRead($inputbox) _ManageText() GUIDelete($inputgui) GUICtrlSetState ($input1, $GUI_ENABLE) EndFunc Func _ManageText() While 1 If StringLeft($post, 1) = @CR OR StringLeft($post, 1) = @LF OR _ StringLeft($post, 1) = @CRLF OR StringLeft($post, 1) = " " Then $post = StringTrimLeft($post, 1) Else ExitLoop EndIf Wend While 1 If StringRight($post, 1) = @CR OR StringRight($post, 1) = @LF OR _ StringRight($post, 1) = @CRLF OR StringRight($post, 1) = " " Then $post = StringTrimRight($post, 1) Else ExitLoop EndIf Wend $w = 150 $h = 100 While 1 Global $aMsgReturn = _StringSize($post, $iSize, $iWeight, $iAttrib, $sFont, $w-10) If @error = 4 Then ; if font too large or word too long for width $w-10 $w = $w + 15 $h = $h + 10 ; keep a 3:2 ratio Else Exitloop EndIf Wend If $aMsgReturn[3]>$h-20 Then While 1 $aMsgReturn = _StringSize($post, $iSize, $iWeight, $iAttrib, $sFont, $w-10) If $aMsgReturn[3]<$h-20 Then ExitLoop $w = $w + 15 $h = $h + 10 Wend EndIf WinMove($gui, "", Default, Default, $w ,$h) GUICtrlSetPos($text, 5, ($h-15-$aMsgReturn[3])/2+15, $w-10, $aMsgReturn[3]) GUICtrlSetData($text, $aMsgReturn[0], "") If $aMsgReturn[0]<>"" Then $file = FileOpen($log, 2) ; create log & reg entry to save the post-it FileWrite($file, $aMsgReturn[0]) FileClose($file) RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $name, "REG_SZ", $PostitPath) Else RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $name) FileDelete($log) EndIf EndFunc ;==>_ManageText() Func _Close() If GuiCtrlRead($text)<>"" Then GUIDelete() Exit Else MsgBox(48, "Warning", "No message to save, the post-it will be deleted", 3) GUIDelete() RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $name) FileDelete($log) EndIf EndFunc Func _Terminate() ; delete post-it, log, reg entry Local $delete If GuiCtrlRead($text)<>"" Then $delete = MsgBox(36,"Warning","Really delete this post-it ?") Select Case $delete = 6 ;yes GUIDelete() RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $name) FileDelete($log) Exit Case $delete = 7 ;no Return EndSelect Else GUIDelete() RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $name) FileDelete($log) Exit EndIf EndFunc ; #FUNCTION# ============================================================= ; Name...........: _FileListToArray ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax.........: _FileListToArray($sPath[, $sFilter = "*"[, $iFlag = 0]]) ; Parameters ....: $sPath - Path to generate filelist for. ; $sFilter - Optional the filter to use, default is *. Search the Autoit3 helpfile for the word "WildCards" For details. ; $iFlag - Optional: specifies whether to return files folders or both ; |$iFlag=0(Default) Return both files and folders ; |$iFlag=1 Return files only ; |$iFlag=2 Return Folders only ; Return values .: @Error - 1 = Path not found or invalid ; |2 = Invalid $sFilter ; |3 = Invalid $iFlag ; |4 = No File(s) Found ; Author ........: SolidSnake <MetalGX91 at GMail dot com> ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Files\Folders returned ; $array[1] = 1st File\Folder ; $array[2] = 2nd File\Folder ; $array[3] = 3rd File\Folder ; $array[n] = nth File\Folder ;========================================================================= Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0) Local $hSearch, $sFile, $asFileList[1] If Not FileExists($sPath) Then Return SetError(1, 1, "") If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringInStr($sFilter, "|")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "") If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "") If (StringMid($sPath, StringLen($sPath), 1) = "\") Then $sPath = StringTrimRight($sPath, 1) ; needed for Win98 for x:\ root dir $hSearch = FileFindFirstFile($sPath & "\" & $sFilter) If $hSearch = -1 Then Return SetError(4, 4, "") While 1 $sFile = FileFindNextFile($hSearch) If @error Then SetError(0) ExitLoop EndIf If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop $asFileList[0] += 1 If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2] $asFileList[$asFileList[0]] = $sFile WEnd FileClose($hSearch) ReDim $asFileList[$asFileList[0] + 1] ; Trim unused slots Return $asFileList EndFunc ;==>_FileListToArray ; #FUNCTION# ============================================================= ; ; Name...........: _StringSize ; Description ...: Returns size of rectangle required to display string - width can be chosen ; Syntax ........: _StringSize($sText[, $iSize[, $iWeight[, $iAttrib[, $sName[, $iWidth]]]]]) ; Parameters ....: $sText - String to display ; $iSize - Font size in points - default AutoIt GUI default ; $iWeight - Font weight (400 = normal) - default AutoIt GUI default ; $iAttrib - Font attribute (0-Normal, 2-Italic, 4-Underline, 8 Strike - default AutoIt ; $sName - Font name - default AutoIt GUI default ; $iWidth - [optional] Width of rectangle - default is unwrapped width of string ; Requirement(s) : v3.2.12.1 or higher ; Return values .: Success - Returns array with details of rectangle required for text: ; |$array[0] = String formatted with @CRLF at required wrap points ; |$array[1] = Height of single line in selected font ; |$array[2] = Width of rectangle required to hold formatted string ; |$array[3] = Height of rectangle required to hold formatted string ; Failure - Returns 0 and sets @error: ; |1 - Incorrect parameter type (@extended = parameter index) ; |2 - Failure to create GUI to test label size ; |3 - Failure of _WinAPI_SelectObject ; |4 - Font too large for chosen width - longest word will not fit ; Author ........: Melba23 ;==================================================================== Func _StringSize($sText, $iSize = Default, $iWeight = Default, $iAttrib = Default, $sName = Default, $iWidth = 0) Local $hWnd, $hFont, $hDC, $oFont, $tSize, $hGUI, $hText_Label, $sTest_Line Local $iLine_Width, $iWrap_Count, $iLast_Word, $iLine_Count Local $asLines[1], $avSize_Info[4], $aiPos[4] ; Check parameters are correct type If Not IsString($sText) Then Return SetError(1, 1, 0) If Not IsNumber($iSize) And $iSize <> Default Then Return SetError(1, 2, 0) If Not IsInt($iWeight) And $iWeight <> Default Then Return SetError(1, 3, 0) If Not IsInt($iAttrib) And $iAttrib <> Default Then Return SetError(1, 4, 0) If Not IsString($sName) And $sName <> Default Then Return SetError(1, 5, 0) If Not IsNumber($iWidth) Then Return SetError(1, 6, 0) ; Create GUI to contain test labels, set to passed font parameters $hGUI = GUICreate("", 1200, 500, 10, 10) If $hGUI = 0 Then Return SetError(2, 0, 0) GUISetFont($iSize, $iWeight, $iAttrib, $sName) ; Store unwrapped text $avSize_Info[0] = $sText ; Ensure EoL is @CRLF and break text into lines If StringInStr($sText, @CRLF) = 0 Then StringRegExpReplace($sText, "[x0a|x0d]", @CRLF) $asLines = StringSplit($sText, @CRLF, 1) ; Draw label with unwrapped lines to check on max width $hText_Label = GUICtrlCreateLabel($sText, 10, 10) $aiPos = ControlGetPos($hGUI, "", $hText_Label) GUICtrlDelete($hText_Label) ; Store line height for this font size after removing label padding (always 8) $avSize_Info[1] = ($aiPos[3] - 8)/ $asLines[0] ; Store width and height of this label $avSize_Info[2] = $aiPos[2] $avSize_Info[3] = $aiPos[3] - 4; Reduce margin ; Check if wrapping is required If $aiPos[2] > $iWidth And $iWidth > 0 Then ; Set returned text element to null $avSize_Info[0] = "" ; Set width element to max allowed $avSize_Info[2] = $iWidth ; Set line count to zero $iLine_Count = 0 ; Take each line in turn For $j = 1 To $asLines[0] ; Size this line unwrapped $hText_Label = GUICtrlCreateLabel($asLines[$j], 10, 10) $aiPos = ControlGetPos($hGUI, "", $hText_Label) GUICtrlDelete($hText_Label) ; Check wrap status If $aiPos[2] < $iWidth Then ; No wrap needed so count line and store $iLine_Count += 1 $avSize_Info[0] &= $asLines[$j] & @CRLF Else ; Wrap needed so need to count wrapped lines ; Create label to hold line as it grows $hText_Label = GUICtrlCreateLabel("", 0, 0) ; Initialise Point32 method $hWnd = ControlGetHandle($hGui, "", $hText_Label) $hFont = _SendMessage($hWnd, $WM_GETFONT) $hDC = _WinAPI_GetDC($hWnd) $oFont = _WinAPI_SelectObject($hDC, $hFont) If $oFont = 0 Then Return SetError(3, 0, 0) ; Zero counter $iWrap_Count = 0 While 1 ; Set line width to 0 $iLine_Width = 0 ; Initialise pointer for end of word $iLast_Word = 0 For $i = 1 To StringLen($asLines[$j]) ; Is this just past a word ending? If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1 ; Increase line by one character $sTest_Line = StringMid($asLines[$j], 1, $i) ; Place line in label GUICtrlSetData($hText_Label, $sTest_Line) ; Get line length $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sTest_Line) $iLine_Width = DllStructGetData($tSize, "X") ; If too long exit the loop If $iLine_Width >= $iWidth - Int($iSize / 2) Then ExitLoop Next ; End of the line of text? If $i > StringLen($asLines[$j]) Then ; Yes, so add final line to count $iWrap_Count += 1 ; Store line $avSize_Info[0] &= $sTest_Line & @CRLF ExitLoop Else ; No, but add line just completed to count $iWrap_Count += 1 ; Check at least 1 word completed or return error If $iLast_Word = 0 Then GUIDelete($hGUI) Return SetError(4, 0, 0) EndIf ; Store line up to end of last word $avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF ; Strip string to point reached $asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word) ; Trim leading whitespace $asLines[$j] = StringStripWS($asLines[$j], 1) ; Repeat with remaining characters in line EndIf WEnd ; Add the number of wrapped lines to the count $iLine_Count += $iWrap_Count ; Clean up _WinAPI_ReleaseDC($hWnd, $hDC) GUICtrlDelete($hText_Label) EndIf Next ; Convert lines to pixels and add reduced margin $avSize_Info[3] = ($iLine_Count * $avSize_Info[1]) + 4 EndIf ; Clean up GUIDelete($hGUI) ; Return array Return $avSize_Info EndFunc; => _StringSize Edited October 8, 2010 by mikell Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 7, 2010 Moderators Share Posted October 7, 2010 mikell,There is nothng in my StringSize UDF to prevent you putting whatever you like in the text you pass to it. When I run your script it enters the $ ( ) & ' _ characters perfectly and adjusts the size to match the size just as it should. Why do you think it was giving you an error? M23P.S. You do not have the latest version of the UDF - look in my sig to get it.  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
mikell Posted October 7, 2010 Author Share Posted October 7, 2010 Sorry Melba, you're right when writing the script some days ago I tested it and got errors, I thought this was the cause and when finished I didnt try again using these characters So your func is even nicer than I thought before BTW you're an experienced autoit user, please give your advice to a newbie, do you find that my use of your func is correct or is there something to improve ? Got your last version, thanks I spent a loooong time searching the forum for 'how to vertically center text in a label' , only found complicated solutions, but your stringsize is an elegant way to skirt the problem Link to comment Share on other sites More sharing options...
Mison Posted October 8, 2010 Share Posted October 8, 2010 And is there an easy way to check if these characters exist in a string ? I mean easier than: If StringInStr($string, "$") OR ... etc There is. $string = "sdad adasd a $ (asdad sadad ) & ' _ asdadas asd as" ;~ $string = "dsad asda ad asd asd asda dad" ; clean String StringSplit($string, "$()&'_") If @error Then MsgBox(0,"","String is clean") Else MsgBox(0,"","Unwanted characters exists") EndIf Hi ;) Link to comment Share on other sites More sharing options...
GEOSoft Posted October 8, 2010 Share Posted October 8, 2010 $string = "sdad adasd a $ (asdad sadad ) & ' _ asdadas asd as" ;~ $string = "dsad asda ad asd asd asda dad" ; clean String If NOT StringRegExp($string, "[\$\(\)&'_]") Then MsgBox(0,"","String is clean") Else MsgBox(0,"","Unwanted characters exist.") EndIf George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
mikell Posted October 8, 2010 Author Share Posted October 8, 2010 Thanks, both solutions work nice Melba, the & character doesnt work in my script However it exists in tahoma fontI suppose I'll use StringReplace($string, '&', "and")If there are several like this maybe a StringRegExpReplace should be better than a warning msgbox Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 8, 2010 Moderators Share Posted October 8, 2010 (edited) mikell, I spent a loooong time searching the forum for 'how to vertically center text in a label'You do it like this: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> $hGUI = GUICreate("Test", 500, 500) $hLabel = GUICtrlCreateLabel("Test", 10, 10, 480, 480, BitOR($SS_CENTER, $SS_CENTERIMAGE) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd If you do not know about using BitOR to combine styles, read the Setting Styles tutorial in the Wiki. the & character doesnt work in my scriptPost the script you are using now and we will take a look - as I said before it is not my UDF doing it! M23 P.S. Would you mind changing the title of the topic? As there are no forbidden characters in _StringSize I would not want anyone thinking that there are! You can do it by editing your first post and selecting the "Use Full Editor" button - this gives you access to the title inputs at the top. Edited October 8, 2010 by Melba23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
mikell Posted October 8, 2010 Author Share Posted October 8, 2010 (edited) Melba, ok I'm a newbie but please grant me this, I always read the autoit help firstI know $SS_CENTERIMAGE but this doesn't work with word wrap, like this : #include <GUIConstantsEx.au3> #include <StaticConstants.au3> $hGUI = GUICreate("Test", 120, 120) $hLabel = GUICtrlCreateLabel("This is a test with a looong line of text", 10, 10, 100, 100, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndof course I changed the title of the topic - BTW thanks for the 'how to'I understand now my mistake about characters. In first tests I tried pieces of autoit script as strings, and the errors I got were caused by too long words in the string, that was before I introduced the If @error = 4 Then... conditionmy last script is in the first post (edited)For the & I get no error message, but a kind of '_' appears in the label instead of the & . Strange... Edited October 8, 2010 by mikell Link to comment Share on other sites More sharing options...
GEOSoft Posted October 8, 2010 Share Posted October 8, 2010 That doesn't sound like a label. It sounnds more like you are using it on a button. The underlining is the result that you get when placing a & symbol in front of a character in buttons, and Menu/item controls. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
mikell Posted October 8, 2010 Author Share Posted October 8, 2010 GEOSoft, I agree but this doesn't help mePlease have a look at my script : the text is entered in an inputbox or editbox, then treated using Melba's stringsize func, and the result is sent to a label... nothing to do with buttons or menusbut thats right, when I enter &a an underlined 'a' appearsI dont understand.. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 8, 2010 Share Posted October 8, 2010 (edited) That's how you tag hot keys. For example, the string "&File" is how you get File displayed to show that Alt-F will activate that menu. Edited October 8, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
mikell Posted October 8, 2010 Author Share Posted October 8, 2010 (edited) GEOSoft, That doesn't sound like a label. It sounnds more like you are using it on a button. The underlining is the result that you get when placing a & symbol in front of a character in buttons, and Menu/item controls.If I use Melba's sample #include <GUIConstantsEx.au3> #include <StaticConstants.au3> $hGUI = GUICreate("Test", 120, 120) $hLabel = GUICtrlCreateLabel("&test", 10, 10, 100, 100, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I get an underlined character in the label Same with Chr(38) & "test" So ... first, Melba you're definitely right, it seems that it's not a 'stringsize func' problem second, my newbie question : what is the way to write the & character in a label ? Hmm it gets funny there Edit : found solution to write the & character in a label we must enter && this should work in the script : If StringInStr($string, "&") Then StringReplace($string, "&", "&&") Edited October 8, 2010 by mikell Link to comment Share on other sites More sharing options...
trancexx Posted October 8, 2010 Share Posted October 8, 2010 && ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
mikell Posted October 8, 2010 Author Share Posted October 8, 2010 (edited) trancexx I should have waited for your answer instead of searchingfinally works withIf StringInStr($aMsgReturn[0], "&") Then $aMsgReturn[0] = StringReplace($aMsgReturn[0], "&", "&&") GUICtrlSetData($text, $aMsgReturn[0]) Edited October 8, 2010 by mikell Link to comment Share on other sites More sharing options...
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