Jump to content

WM_SIZE ListView


Recommended Posts

Hey,

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)
    Return $GUI_RUNDEFMSG
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?

James

Link to comment
Share on other sites

  • Moderators

JamesBrooks,

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<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<TabConstants.au3>
#include<GuiListView.au3>
#include <GuiTab.au3>

Opt("GUIResizeMode", $GUI_DOCKBORDERS)

; 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) & " "
    Next
Next
    
; 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

    GUICtrlCreateTabItem($aTitles[$i])
    $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])
    Next

Next

; Close Tab definiton
GUICtrlCreateTabItem("")

; Create button
$hButton = GUICtrlCreateButton("Button", 10, $iGUIHeight - 40, 120, 30)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKWIDTH, $GUI_DOCKHEIGHT, $GUI_DOCKBOTTOM))

GUISetState(@SW_SHOW)

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

; 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)
        Next
; Reset flag
        $fResized = False
    EndIf

WEnd

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
        GUICtrlCreateTabItem($aTabTitles[$i])
    Next
; Measure the client area of the Tab
    $aPos = _GUICtrlTab_GetDisplayRect(ControlGetHandle($TestGUI, "", $TestTAB))
; Delete test GUI
    GUIDelete($TestGUI)
; Return new TabTop value
    Return $aPos[1]
    
EndFunc
    
Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    
    $iGUIWidth = BitAND($lParam, 0xFFFF)
    $iGUIHeight = BitShift($lParam, 16)
; Set flag
    $fResized = True
        
    Return $GUI_RUNDEFMSG
    
EndFunc;==>WM_SIZE

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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