Function Reference


_GUICtrlListView_GetStringWidth

Determines the width of a specified string

#include <GuiListView.au3>
_GUICtrlListView_GetStringWidth ( $hWnd, $sString )

Parameters

$hWnd Control ID/Handle to the control
$sString String for which the width will be calculated

Return Value

Success: the string width.
Failure: 0

Remarks

This function returns the exact width, in pixels, of the specified string.
If you use the returned string width as the column width in the _GUICtrlListView_SetColumnWidth() function the string will be truncated.
To retrieve the column width that can contain the string without truncating it, you must add padding to the returned string width.

Example

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $idListview

    GUICreate("ListView Get String Width", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Column 1", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1")
    _GUICtrlListView_AddItem($idListview, "Item 2")
    _GUICtrlListView_AddItem($idListview, "Item 3")

    ; Get width of string
    MsgBox($MB_SYSTEMMODAL, "Information", 'Width of "Test": ' & _GUICtrlListView_GetStringWidth($idListview, "Test"))

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example