Jump to content
Sign in to follow this  

WM_SIZE ListView

Recommended Posts



I have been looking to resize a ListView, created with _GUICtrlListView_Create() when the window has been maximized.

I have other controls working fine but the LV has been causing problems. I have searched and found this:

Func WM_SIZE($hWnd, $iMsg, $iwParam, $lParam)
    Local $iWidth = BitAND($lParam, 0xFFFF)
    Local $iHeight = BitShift($lParam, 16)
    _WinAPI_MoveWindow($DriveList, 10, 10, $iWidth - 20, $iHeight - 20, True)
    _GUICtrlListView_SetColumn($DriveList, 2, "Type", $iWidth - 260)
EndFunc  ;==>WM_SIZE

But this only does the second column. To fix this, I used _GUICtrlListView_SetColumWidth($DriveList, -1, $iWidth - 260), this kept all columns the same size, resized the width and the height to fit the whole GUI.

Any ideas?


Share this post

Link to post
Share on other sites


I did this bit of ListView resizing when I was trying to cope with varying numbers of tab rows when resizing the GUI. Does it offer any insight to your problem? The ListView is back-coloured blue to show its extent - the button is inactive:

#include <GuiTab.au3>


; When window is resized, run this function
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

Global $iGUIWidth = 800, $iGUIHeight = 500, $fResized = False

$MainGUI = GUICreate("Directory List", $iGUIWidth, $iGUIHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
$TAB = GUICtrlCreateTab(1, 1, $iGUIWidth - 2, $iGUIHeight - 50, BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))

; Set number of TabItems
Global $iTabNumber = 15

; Create array holding dummy tabitems
Global $aTitles[$iTabNumber + 1]
For $i = 1 To $iTabNumber
    $aTitles[$i] = ""
    For $j = 1 To Random(4, 10, 1)
        $aTitles[$i] &= String($i) & " "
; Determine initial TabTop value
$iTabTop = Tab_Sizer($iTabNumber, $aTitles)

; Create array to hold ListView handles
Global $aListView[$iTabNumber + 1] = [$iTabNumber]

; Create tabitems
For $i = 1 To $iTabNumber

    $aListView[$i] = GUICtrlCreateListView("Column 1|Column 2", 10, $iTabTop, $iGUIWidth - 22, $iGUIHeight - $iTabTop - 50)
        _GUICtrlListView_SetColumnWidth($aListView[$i], 0, 150)
        _GUICtrlListView_SetColumnWidth($aListView[$i], 1, $LVSCW_AUTOSIZE_USEHEADER)
        _GUICtrlListView_SetBkColor($aListView[$i], 0xFF0000); Just to show the size
        GUICtrlSetResizing($aListView[$i], BitOR($GUI_DOCKBORDERS, $GUI_DOCKLEFT))

; Fill ListView with items
    For $j = 1 To 25
        GUICtrlCreateListViewItem("Item " & $j & " - ListView " & $i & "|   Blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah", $aListView[$i])


; Close Tab definiton

; Create button
$hButton = GUICtrlCreateButton("Button", 10, $iGUIHeight - 40, 120, 30)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        Case $hButton
   ; Button press code goes here

; Look for resize message
    If $fResized Then

; Determine new TabTop value
        $iTabTop = Tab_Sizer($iTabNumber, $aTitles)
; Resize all Listviews to fit new Tab dimensions
        For $i = 1 To $aListView[0]
            GUICtrlSetPos($aListView[$i], 10, $iTabTop, $iGUIWidth - 22, $iGUIHeight - $iTabTop - 50)
            _GUICtrlListView_SetColumnWidth($aListView[$i], 0, $LVSCW_AUTOSIZE_USEHEADER)
; Reset flag
        $fResized = False


Func Tab_Sizer($iTabTotal, $aTabTitles)
; Create test GUI
    $TestGUI = GUICreate("", $iGUIWidth, 500)
; Create test Tab
    $TestTAB = GUICtrlCreateTab(1, 1, $iGUIWidth - 2, 500, BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))
; Create correct number of TabItems
    For $i = 1 To $iTabTotal
; Measure the client area of the Tab
    $aPos = _GUICtrlTab_GetDisplayRect(ControlGetHandle($TestGUI, "", $TestTAB))
; Delete test GUI
; Return new TabTop value
    Return $aPos[1]
Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    $iGUIWidth = BitAND($lParam, 0xFFFF)
    $iGUIHeight = BitShift($lParam, 16)
; Set flag
    $fResized = True

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


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


Share this post

Link to post
Share on other sites

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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.