Jump to content

Recommended Posts

Posted

Hang on a sec... You release plenty of other UDF's for which this is needed (Toast, Extended MsgBox etc.) and never post this??

Is making a GUI the most effective way of doing this? MeasureString is probably a better way to go.

  • Moderators
Posted

Mat,

You release plenty of other UDF's for which this is needed (Toast, Extended MsgBox etc.) and never post this??

Not quite, the UDF was indeed included in the topics of the UDFs you mention - and in many other topics scattered across the Help sections - I just never released it as a standalone UDF in the Examples section. :)

Not sure I understand your second point. Why else do you need to get the size of a chunk of text if not to put it in a GUI? :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Melba, can this be used to get stringsize in order to resize a "progressOn" window, to fit the strings within it?(currently it has a default size)

I'd like a way to resize the ProgressOn window based on the text within it. Too long strings get cut off.

Edited by Datenshi
Posted

My point is that always making GUI's is not a particularly glamorous solution. As I have not tried to make the function myself I cannot say if it will be easy to do or not, but making a GUI and then deleting it just to get the size of a label... Sounds more like a workaround to me.

An idea I've just had is possibly a new function for sizing an existing label, then returning the size. That would stop the need for extra GUI's, save on speed, and do what this is probably going to be used for anyway. You only need to input an id for a label and a width, and it will do its stuff and return a height.

As mentioned, I am not 'in the know' and so all this is complete speculation from looking at your code.

  • Moderators
Posted (edited)

Mat,

Sounds more like a workaround to me

Please do try another way - there is room for all of them. :idea:

Kip,

There are plenty of UDF's like this. Even I made one and posted in Examples

This is not like your UDF - try it and see! :)

M23

Edit: Speeling!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Cheers, ive been using a version of this already, may be differant in the version you posted but note that i found the need to guiswitch to the gui i was creating when adding controls after using stringsize.

Local $HeaderTextSize = _StringSize($sHeaderText, $oSelf.HeaderFontSize, $oSelf.HeaderFontWeight,$oSelf.HeaderFontAttribute, $oSelf.HeaderFontFontName)
    GUISwitch(HWnd($oSelf.GuiHandle))
    $HeaderTextSize[1] += 2
    $hCtrl = _oGUICtrlLabel($sHeaderText, $iLeft, $iTop, $HeaderTextSize[2], $HeaderTextSize[1], BitOR($SS_CENTER,$SS_CENTERIMAGE))
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
  • Moderators
Posted

Datenshi,

Apologies, I missed your post earlier in the noise! :)

can this be used to get stringsize in order to resize a "progressOn" window

Of course, but you need to use WinMove and ControlMove to resize the dialog, labels and progress bar. How you do it depends on whether you want to use a very wide dialog with a single line of text or a block of wrapped text with a normal width dialog (see the examples): :idea:

#include "StringSize.au3"

; The long text we want to fit in the dialog
$sText = "I am a very long line and I will not fit within the width of a normal ProgressOn dialog even with a lot of dieting!"

; Wide dialog
$aSize = _StringSize($sText, 11, 800, 0, "Segoe UI")

ProgressOn("Progress Meter", $sText, "0 percent")

WinMove("Progress Meter", "", (@DesktopWidth - ($aSize[2] + 30)) / 2, Default, $aSize[2] + 30)
ControlMove("Progress Meter", "", "[CLASS:msctls_progress32; INSTANCE:1]", Default, Default, $aSize[2] - 15)

For $i = 10 to 100 step 10
    Sleep(1000)
    ProgressSet( $i, $i & " percent")
Next
ProgressSet(100 , "Done", "Complete")
Sleep(500)
ProgressOff()

; Wrapped text
$aSize = _StringSize($sText, 11, 800, 0 , "Segoe UI", 250)

ProgressOn("Progress Meter", $aSize[0], "0 percent")

WinMove("Progress Meter", "", (@DesktopWidth - ($aSize[2] + 30)) / 2, Default, $aSize[2] + 30, $aSize[3] + 80)
ControlMove("Progress Meter", "", "[CLASS:Static; INSTANCE:1]", Default, Default, $aSize[2], $aSize[3])
ControlMove("Progress Meter", "", "[CLASS:msctls_progress32; INSTANCE:1]", Default, $aSize[3] - 5, $aSize[2] - 15)
ControlMove("Progress Meter", "", "[CLASS:Static; INSTANCE:2]", Default, $aSize[3] + 20)

For $i = 10 to 100 step 10
    Sleep(1000)
    ProgressSet( $i, $i & " percent")
Next
ProgressSet(100 , "Done", "Complete")
Sleep(500)
ProgressOff()

I had to guess at the caption font, but the values I chose seem to work well - and the values for resizing the dialog and the controls were chosen empirically as well. :( Why the progress bar needs to be set to a smaller width I have no idea - blame Bill Gates! :)

I hope that is what you wanted. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Yoriz,

i found the need to guiswitch to the gui i was creating when adding controls after using stringsize

Sorry about that. :idea: As MAt pointed out, the UDF does create and then destroy a GUI (to get the font object required for sizing) so I imagine this is what is causing the problem.

I have only ever used the UDF BEFORE creating the GUI and any of its controls so I had not noticed this before. Let me think for a while about how we might get around it. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Hey no need to appologise, i just got used to swoppping back :idea: . would this work ?

$hWndPrevious = GUISwitch(WinGetHandle("Program Manager","")) ; at the start of your udf function

If $hWndPrevious Then GUISwitch($hWndPrevious) ; just before returning from your udf function

There may be a nicer way to get the previous window.

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
  • Moderators
Posted

Yoriz,

I do not get the same problem as you when I use StringSize and then try to create more controls in a GUI: :idea:

#include <GUIConstantsEx.au3>
#include "StringSize.au3"

$sText = "pppppppppppp ppppp ppppppppp pppppppppp ppppppppppp ppppppp ppppp ppp"

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create first control
$hButton = GUICtrlCreateButton("Test", 10, 100, 80, 30)

; Run StringSize
$aSize = _StringSize($sText, Default, Default, Default, Default, 200)

; Create second control
$hLabel = GUICtrlCreateLabel($aSize[0], 10, 10, 200, $aSize[3])

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

For me that code runs without problem and both controls appear in the GUI.

Your code looks as if you are using AutoItObject - I wonder if that might be causing the problem? I do not know enough about AIO to make any sensible comments about the possibility.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Sorry about the missunderstanding, yes im using oop and its probably not that causing it either, i bet im probably creating guis in a strange way thats causing the problem. :idea:

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
  • Moderators
Posted

Yoriz,

Could you post some code that does not work so I could play with it. I already have the AIO UDFs. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • 2 weeks later...
Posted

I am using your code kinda backwards - I know my width maximum (160) and I know my height maximum (55), so I run my string through _StringSize with the font size set too high and decrease by one, and compare $array[3] to 55. If it is less than 55, we're gold, ExitLoop and go. Sometimes it hangs though, here is an example:

For $a = 24 To 1 Step -1
    $findIt = _StringSize("CAT5E Crossover Coupler CAT5E Crossover Coupler", $a, Default, Default, "Arial", 160)
    If $findIt[3] <= 55 Then
        MsgBox(0, "font size to use: " & $a)
        ExitLoop
    EndIf
Next

The above works, but run them together as "CAT5E Crossover CouplerCAT5E Crossover Coupler" and it hangs. Got a solution up your sleeve?

Thanks, wonderful UDF as always!

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
  • Moderators
Posted

llewxam,

Got a solution up your sleeve?

Yes, I messed up the error-checking return code - which I had already realised while I was away last week. :idea:

The UDF should return an error if it cannot fit a word into the minimum width required - which should happen a lot in your case! I messed up the original error return code so you did not get an error returned and the UDF just ran on and on........

I have amended the UDF in the first post to get over this - but you will now need to amend your code to look for the @error returns which you will now get:

For $a = 24 To 1 Step -1
    ConsoleWrite($a & " - ")
    $findIt = _StringSize("CAT5E Crossover CouplerCAT5E Crossover Coupler", $a, Default, Default, "Arial", 160)
    If Not @error Then
        ConsoleWrite($findIt[3] & @CRLF)
        If $findIt[3] <= 55 Then
            MsgBox(0, "", "font size to use: " & $a)
            ExitLoop
        EndIf
    Else
        ConsoleWrite("error " & @error & @CRLF)
    EndIf
Next

The ConsoleWrites are obviously there to show you what is going on - you can delete them when you have seen what is going on:

24 - error 4
23 - error 4
22 - error 4
21 - error 4
20 - error 4
19 - error 4
18 - error 4
17 - 129
16 - 124
15 - 119
14 - 67
13 - 61
12 - 58
11 - 52

Sorry about that - I will try to do better next time! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Sorry about that - I will try to do better next time! :idea:

hahaha!!

I actually kinda switched things around to get around the issue differently, but will update the UDF abyway just in case. What I did was:

$fontSize = 0
Do
    $findFontSize += 1
    $findit = _StringSize($PlabelName, $findFontSize, Default, Default, "Arial", 160)
Until $findit[3] > 55
$fontSize = $findFontSize - 1

Thankfully most of the terms used in the app aren't very large, but I want to make it not puke if at all possible :)

Thanks again, again

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
  • Moderators
Posted

llewxam,

That will work because by going up in point value you should not hit an error state before finding a valid size.

But as a matter of principle, it is a good idea to do some errorchecking whan you call complex UDFs (especially when you write them!). :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...