Roman Posted July 10, 2012 Share Posted July 10, 2012 Hi I want to write a filesystem path as simple text in a GUI. When I use GUICtrlCreateLabel or GUICtrlSetData respectively, a very long path will only be wrapped around if it contains a white space. If the path contains no white space, the path will be truncated at the end of the Control (which ends near the boarder of the GUI). I would like, that somehow the path would be splitted on an appropriate backslash within this path, and wrapped around to the next line. But I have no idea if this is possible with AutoIt or how to do that? Cheers, Roman Link to comment Share on other sites More sharing options...
abaddon7734 Posted July 10, 2012 Share Posted July 10, 2012 (edited) roman,The GuiCtrlCreateLabel can have width and height parameters (kind of like invisible borders) . So if you set it with a width less than the main window's width, it will automatically wrap fit. Also you have to set appropriate height so that when the text wrap falls into new lines, it shows. If you want to manually make a new line from anywhere in the text, use the @LF line feed macro. See this example:#include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> GUICreate("Window size: 300x300", 300, 300) GUISetState() GUICtrlCreateLabel("Label with width more than window: 500", 20, 20, 250) GUICtrlSetFont(-1, 8.5, 600) GUICtrlCreateLabel("", 20, 40, 500, 400) GUICtrlSetData(-1, "C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel("Label with small width less than window: 260", 20, 100, 260) GUICtrlSetFont(-1, 8.5, 600) GUICtrlCreateLabel("", 20, 120, 260, 500) GUICtrlSetData(-1, "C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel('Label with manual line feed "@LF" ', 20, 180, 250) GUICtrlSetFont(-1, 8.5, 600) GUICtrlCreateLabel("", 20, 200, 500, 500) GUICtrlSetData(-1, "C:Documents and Settingsusername" & @LF & "Application DataNokiaPCSync" & @LF & "SynchDataBackups1232012") While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndYou can also create different styles of actual frames for labels and also align and justify text with labels. See http://www.autoitscript.com/autoit3/docs/appendix/GUIStyles.htm#Label for more info Edited July 10, 2012 by abaddon7734 GoogleGonnaSaveUs 1 Link to comment Share on other sites More sharing options...
Roman Posted July 10, 2012 Author Share Posted July 10, 2012 (edited) Hi abaddon7734Thanks, but now try this:#include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> GUICreate("Window size: 300x300", 300, 300) GUISetState() GUICtrlCreateLabel("Label with width more than window: 500", 20, 20, 250) GUICtrlSetFont(-1, 8.5, 600) GUICtrlCreateLabel("", 20, 40, 500, 400) GUICtrlSetData(-1, "C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel("Label with small width less than window: 260", 20, 100, 260) GUICtrlSetFont(-1, 8.5, 600) GUICtrlCreateLabel("", 20, 120, 260, 500) GUICtrlSetData(-1, "C:Documents_and_SettingsusernameApplication_DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel('Label with manual line feed "@LF" ', 20, 180, 250) GUICtrlSetFont(-1, 8.5, 600) GUICtrlCreateLabel("", 20, 200, 500, 500) GUICtrlSetData(-1, "C:Documents and Settingsusername" & @LF & "Application DataNokiaPCSync" & @LF & "SynchDataBackups1232012") While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndNo wrap fit in the second example. Manually inserting @LF is no option.Cheers. Edited July 10, 2012 by roman abaddon7734 1 Link to comment Share on other sites More sharing options...
PhoenixXL Posted July 10, 2012 Share Posted July 10, 2012 (edited) Why not get the dimensions of the rectangle that would be able to bound the text Try this code: expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPLus.au3> Local $sLongest_Text="C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012" Local $sPos=CalcRectangle($sLongest_Text) GUICreate("Window size: 300x300", $sPos[0], 500) GUISetState() GUICtrlCreateLabel("Label with width more than window: 500", 20, 20, 250) GUICtrlSetFont(-1, 8.5, 600) $sPos=CalcRectangle("C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel("", 20, 40, $sPos[0], $sPos[1]) GUICtrlSetBkColor(-1,0xFF23FF) GUICtrlSetData(-1, "C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel("Label with small width less than window: 260", 20, 100, 260) GUICtrlSetFont(-1, 8.5, 600) $sPos=CalcRectangle('C:Documents_and_SettingsusernameApplication_DataNokiaPCSyncSynchDataBackups1232012') GUICtrlCreateLabel("", 20, 120, $sPos[0], $sPos[1]) GUICtrlSetBkColor(-1,0xFF23FF) GUICtrlSetData(-1, "C:Documents_and_SettingsusernameApplication_DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel('Label with manual line feed "@LF" ', 20, 180, 250) GUICtrlSetFont(-1, 8.5, 600) $sPos=CalcRectangle("C:Documents and Settingsusername" & @LF & "Application DataNokiaPCSync" & @LF & "SynchDataBackups1232012") GUICtrlCreateLabel("", 20, 200, $sPos[0], $sPos[1]) GUICtrlSetData(-1, "C:Documents and Settingsusername" & @LF & "Application DataNokiaPCSync" & @LF & "SynchDataBackups1232012") GUICtrlSetBkColor(-1,0xFF23FF) While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func CalcRectangle($sString, $sFont='Arial',$fFontsize=8.5) _GDIPlus_Startup() Local $aResult, $hFont, $i=0 ,$iLen = StringLen($sString),$tLayout Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle())) Local $tRectF = DllStructCreate($tagGDIPRECTF) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFont = _GDIPlus_FontCreate( _GDIPlus_FontFamilyCreate($sFont), $fFontsize, 0) Do $tLayout = _GDIPlus_RectFCreate(0, 0, $i, 0) $aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", _ "handle", $hGfx, _ "wstr", $sString, _ "int", $iLen, _ "handle", $hFont, _ "struct*", $tLayout, _ "handle", $hFormat, _ "struct*", $tRectF, _ "int*", 0, _ "int*", 0) If $aResult[8] >= $iLen Then ExitLoop $i += 1 Until False _GDIPlus_FontDispose($hFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGfx) $tLayout = 0 Local $sReturn[2]=[DllStructGetData($aResult[7],'Width'),DllStructGetData($aResult[7],'Height')] _GDIPlus_Shutdown() Return $sReturn EndFunc The rectangle having the exact text in it(nor more nor less space) has been colored pink Hope this helps Regards Phoenix XL Edited July 10, 2012 by PhoenixXL abaddon7734 1 My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Roman Posted July 10, 2012 Author Share Posted July 10, 2012 Thanks, but the GUI size should not change, because there are other controls. That would not be look very nice. Link to comment Share on other sites More sharing options...
PhoenixXL Posted July 10, 2012 Share Posted July 10, 2012 (edited) As U wish friend then u have only two choices left First: Type the default text of the label upon creation then the label will align the text in accordance Second(recommended) : Use the following function and get the font size which would be able to fit in the specified width and height The following script adjusts the size of the font so that the text fits in the specified width and height expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPLus.au3> Local $sLongest_Text="C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012" Local $sPos GUICreate("Window size: 300x300", 500, 500) GUISetState() GUICtrlCreateLabel("Label with width more than window: 500", 20, 20, 250) GUICtrlSetFont(-1, 8.5, 600) $sPos=CalcFontSize("C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012",500,100) GUICtrlCreateLabel("", 20, 40, 500, 100) GUICtrlSetFont(-1,$sPos) ;GUICtrlSetBkColor(-1,0xFF23FF) GUICtrlSetData(-1, "C:Documents and SettingsusernameApplication DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel("Label with small width less than window: 260", 20, 100, 260) GUICtrlSetFont(-1, 8.5, 600) $sPos=CalcFontSize("C:Documents_and_SettingsusernameApplication_DataNokiaPCSyncSynchDataBackups1232012",260,100) GUICtrlCreateLabel("", 20, 120, 260,100) GUICtrlSetFont(-1,$sPos) ;GUICtrlSetBkColor(-1,0xFF23FF) GUICtrlSetData(-1, "C:Documents_and_SettingsusernameApplication_DataNokiaPCSyncSynchDataBackups1232012") GUICtrlCreateLabel('Label with manual line feed "@LF" ', 20, 180, 250) GUICtrlSetFont(-1, 8.5, 600) $sPos=CalcFontSize("C:Documents and Settingsusername" & @LF & "Application DataNokiaPCSync" & @LF & "SynchDataBackups1232012",100,100) GUICtrlCreateLabel("", 20, 200, 100,100) GUICtrlSetFont(-1,$sPos) GUICtrlSetData(-1, "C:Documents and Settingsusername" & @LF & "Application DataNokiaPCSync" & @LF & "SynchDataBackups1232012") ;GUICtrlSetBkColor(-1,0xFF23FF) While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func CalcFontSize($sString, $iW, $iH, $sFont='Arial') _GDIPlus_Startup() Local $aResult, $hFont, $i, $iLen = StringLen($sString) Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle())) Local $tRectF = DllStructCreate($tagGDIPRECTF) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) $i = 1 Do $hFont = _GDIPlus_FontCreate($hFamily, $i, 0) $aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", "handle", $hGfx, "wstr", $sString, "int", -1, "handle", $hFont, "struct*", $tLayout, "handle", $hFormat, "struct*", $tRectF, "int*", 0, "int*", 0) _GDIPlus_FontDispose($hFont) If $aResult[8] < $iLen Or $aResult[9] = 2 Or $i > $iH / 1.45 Then ExitLoop $i += 1 Until False _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGfx) $tLayout = 0 Return $i-0.0000000001 _GDIPlus_Shutdown() EndFunc Edited July 10, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
abaddon7734 Posted July 10, 2012 Share Posted July 10, 2012 Similar discussion here: Link to comment Share on other sites More sharing options...
BrewManNH Posted July 10, 2012 Share Posted July 10, 2012 If you have a long path name, inside a label you can use either of the $DT_PATH_ELLIPSIS or $DT_END_ELLIPSIS style settings in the label. Just be aware, that the 2 values in the WindowsConstants.au3 file are set according to Microsoft documentation, but they work backwards, for example the Path_Ellipsis creates a path like this "C:Documents and Settings..." and the End_Ellipsis creates a path like this "C:Documents...Username", this is a problem with Windows and not AutoIt. matwachich 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
matwachich Posted June 29, 2013 Share Posted June 29, 2013 Thank you for the $DT_PATH_ELLIPSIS trick! Link to comment Share on other sites More sharing options...
guinness Posted June 29, 2013 Share Posted June 29, 2013 I don't believe this is documented for GUICtrlCreateLabel, so I wouldn't totally rely on it if it isn't documented in the help file. Look at _StringCompact in my signature instead.Oh and please refrain from necoring old posts. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
guinness Posted June 29, 2013 Share Posted June 29, 2013 Yeah, because the help file totally documents everything that you can do with AutoIt.Correct. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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