trancexx Posted May 6, 2010 Share Posted May 6, 2010 (edited) Subtitle doesn't make sense, don't try to find one. Seems everyone has a version of this function. Here's another one. This one is trick free and it's mine, mine, mine... expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <WinAPI.au3> ; Make GUI GUICreate("StringSize", 600, 400) GUISetBkColor(0) ; black magic GUI ; First example: Global $sLabelText = "Pa Da Pam Pam..." Global $aLabelTextSize = _StringSize($sLabelText, 14) GUICtrlCreateLabel($sLabelText, 10, 20, $aLabelTextSize[0], $aLabelTextSize[1]) ; create label in calculated size GUICtrlSetFont(-1, 14) ; set wanted font GUICtrlSetBkColor(-1, 0xFFFFFF) ; make the background white ; Print size ConsoleWrite($aLabelTextSize[0] & " x " & $aLabelTextSize[1] & @CRLF) ; Secand example: $sLabelText = "abcdehmma" $aLabelTextSize = _StringSize($sLabelText, 60, 800) GUICtrlCreateLabel($sLabelText, 10, 80, $aLabelTextSize[0], $aLabelTextSize[1]) ; create label in calculated size GUICtrlSetFont(-1, 60, 800) ; set wanted font GUICtrlSetBkColor(-1, 0xFFFFFF) ; make the background white ; Print size ConsoleWrite($aLabelTextSize[0] & " x " & $aLabelTextSize[1] & @CRLF) ; Third example: $sLabelText = "First line of the text" & @LF & "Second line of the text" & @CRLF & "Third line of the text" & @CRLF & "Fourth line of the text. See ya!" $aLabelTextSize = _StringSize($sLabelText, 17, 700, 2, "Tahoma", 4) GUICtrlCreateLabel($sLabelText, 10, 220, $aLabelTextSize[0], $aLabelTextSize[1]) ; create label in calculated size GUICtrlSetFont(-1, 17, 700, 2, "Tahoma", 4) ; set wanted font GUICtrlSetBkColor(-1, 0xFFFFFF) ; make the background white ; Print size ConsoleWrite($aLabelTextSize[0] & " x " & $aLabelTextSize[1] & @CRLF) ; Show GUI GUISetState() ; Wait for the exit While GUIGetMsg() <> -3 WEnd ; FUNCTION Func _StringSize($sText, $iSize = 8.5, $iWeight = 400, $iAttrib = 0, $sName = "", $iQuality = 2) Local Const $LOGPIXELSY = 90 Local $fItalic = BitAND($iAttrib, 2) Local $hDC = _WinAPI_GetDC(0) Local $hFont = _WinAPI_CreateFont(-_WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * $iSize / 72, 0, 0, 0, $iWeight, $fItalic, BitAND($iAttrib, 4), BitAND($iAttrib, 8), 0, 0, 0, $iQuality, 0, $sName) Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont) Local $tSIZE Local $iWidth = 0, $iHeight = 0 Local $aArrayOfStrings = StringSplit(StringStripCR($sText), @LF, 2) For $sString In $aArrayOfStrings If $fItalic Then $sString &= " " $tSIZE = _WinAPI_GetTextExtentPoint32($hDC, $sString) If DllStructGetData($tSIZE, "X") > $iWidth Then $iWidth = DllStructGetData($tSIZE, "X") $iHeight += DllStructGetData($tSIZE, "Y") Next _WinAPI_SelectObject($hDC, $hOldFont) _WinAPI_DeleteObject($hFont) _WinAPI_ReleaseDC(0, $hDC) Local $aOut[2] = [$iWidth, $iHeight] Return $aOut EndFunc ;==>_StringSize You calculate the size of the string considering the font and make the label in that size. That's it. edit: edit Edited May 6, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
lsakizada Posted May 6, 2010 Share Posted May 6, 2010 Works perfect! great work. Very usefull not only for labels. Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
Yashied Posted May 6, 2010 Share Posted May 6, 2010 2nd example My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
trancexx Posted May 6, 2010 Author Share Posted May 6, 2010 When you manage to find the cause of that don't forget to post the solution. I'm clueless. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
KaFu Posted May 6, 2010 Share Posted May 6, 2010 (edited) Just from the looks it seems like the font on the screenshot is painted with quality = 5, a little blurry... Yashied, maybe adjust the quality setting in _StringSize() and retry. trancexx, maybe this is a system specific setting? Saw a function floating around to aquire the system's font default setting, should this be taken into account? Edit: I would recommand following steps to make it OS/Font independant: - Create Control - Set Font - Set Control Size with _StringSize(), where _StringSize() should read the actual font settings used by the control. Edited May 6, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
trancexx Posted May 6, 2010 Author Share Posted May 6, 2010 (edited) Just from the looks it seems like the font on the screenshot is painted with quality = 5, a little blurry... Yashied, maybe adjust the quality setting in _StringSize() and retry. trancexx, maybe this is a system specific setting? Saw a function floating around to aquire the system's font default setting, should this be taken into account?Edit: I would recommand following steps to make it OS/Font independant:- Create Control- Set Font- Set Control Size with _StringSize(), where _StringSize() should read the actual font settings used by the control.Yes, but that's defeating the main purpose of why I posted this.Anyway, _WinAPI_CreateFont() function seems to be the cause of problems. It has $szFace = 'Arial' as the last parameter. AutoIt on the other hand is using empty string as default. Edited May 6, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Yashied Posted May 6, 2010 Share Posted May 6, 2010 (edited) AutoIt on the other hand is using empty string as default.It seems "MS Shell Dlg" or font that is defined by theme. Edited May 6, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
slayerz Posted May 6, 2010 Share Posted May 6, 2010 Great example...thanks trancexx AUTOIT[sup] I'm lovin' it![/sup] Link to comment Share on other sites More sharing options...
Mat Posted May 6, 2010 Share Posted May 6, 2010 If Melba is reading this, this is exactly what I was hinting at. No GUI's, just api. Well done AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Moderators Share Posted May 6, 2010 (edited) Of course Melba23 is reading this! This shows the gulf between a hobbyist coder like me and a real programmer - vast! Nice example trancexx. M23 Edit: There is one difference though, my version will wrap the text for you to fit an designated width - you do not have to preformat with @CRLFs, the UDF does it for you. Edited May 6, 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...
Mat Posted May 6, 2010 Share Posted May 6, 2010 Of course Melba23 is reading this! This shows the gulf between a hobbyist coder like me and a real programmer - vast! Nice example trancexx. M23Edit: There is one difference though, my version will wrap the text for you to fit an designated width - you do not have to preformat with @CRLFs, the UDF does it for you.I'm fairly sure that with a little editing trancexx will be able to figure it out There is one more difference though... I can understand what goes on in your code AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Moderators Share Posted May 6, 2010 Mat,There is one more difference though... I can understand what goes on in your codeToo true! M23 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...
trancexx Posted May 6, 2010 Author Share Posted May 6, 2010 (edited) I'm not a real programmer Melba23. @Yashied, could you try replacing _WinAPI_GetDC(0) with _WinAPI_GetDC(_WinAPI_GetDesktopWindow()) And if that doesn't work then with the gui handle. Edited May 6, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Moderators Share Posted May 6, 2010 trancexx,I'm not a real programmer Melba23You could have fooled me! Would you accept "very talented coder"? M23 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...
Mat Posted May 6, 2010 Share Posted May 6, 2010 You could have fooled me! Would you accept "very talented coder"? 'REAL' programmers are something different... http://www.pbm.com/~lindahl/real.programmers.html etc. AutoIt Project Listing Link to comment Share on other sites More sharing options...
trancexx Posted May 6, 2010 Author Share Posted May 6, 2010 trancexx,You could have fooled me! Would you accept "very talented coder"? M23I would.You have to see my other talents...Sometimes I replace barcode stamps on the fruits in the grocery, steal a snickers even. I can say I'm very talented in different areas.Tell no one about that. It's kinda of a secret. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Moderators Share Posted May 6, 2010 trancexx,Sometimes I replace barcode stamps on the fruits in the groceryYou devil, you! M23 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...
trancexx Posted May 6, 2010 Author Share Posted May 6, 2010 Have you ever done that? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
TheSaint Posted May 8, 2010 Share Posted May 8, 2010 @trancexx - If you are not indulging in a bit of leg pull, then you are obviously a gal after my own heart. However, I would suggest you give up the habit, and indulge in other things that are still exciting ... but only embarrassing when you eventually get caught or found out. Take it from one that was lucky enough to learn in time! Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) 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