Jump to content

Resize a _GUICtrlListViewCreate when maximizing


HeXetic
 Share

Recommended Posts

I have a GUI with a listview created with _GUICtrlListViewCreate, but I need to get it to resize when the window is resized or when the window is maximized.

I have tried to use the GUICtrlSetResizing method but that only seems to work with the built in GUI Control Creation.

Below is an example of what i'm trying to do:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$GUI = GUICreate("Resizing", 500, 200, -1, -1, $WS_OVERLAPPEDWINDOW)

$TodoListView = _GUICtrlListView_Create($GUI, "", 10, 20, 480, 160)
_GUICtrlListView_SetExtendedListViewStyle($TodoListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

_GUICtrlListView_InsertColumn($TodoListView, 0, "No", 70)
_GUICtrlListView_InsertColumn($TodoListView, 1, "Ref", 70)
_GUICtrlListView_InsertColumn($TodoListView, 2, "Item", 270)
_GUICtrlListView_InsertColumn($TodoListView, 3, "Status", 70)

GUICtrlSetResizing(-1, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKBOTTOM))

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

Had the same problem with SMF, GUICtrlSetResizing doesn't work with handles but only with control ids. If you need the handle, determine it with GUICtrlGetHandle(). Otherwise as far as I know anything that can be done with _GUICtrlListView_Create() you can add to GUICtrlCreateListView() with _GUICtrlListView_SetExtendedListViewStyle().

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$GUI = GUICreate("Resizing", 500, 200, -1, -1, $WS_OVERLAPPEDWINDOW)

$TodoListView = GUICtrlCreateListView("", 10, 20, 480, 160)

_GUICtrlListView_SetExtendedListViewStyle($TodoListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_InsertColumn($TodoListView, 0, "No", 70)
_GUICtrlListView_InsertColumn($TodoListView, 1, "Ref", 70)
_GUICtrlListView_InsertColumn($TodoListView, 2, "Item", 270)
_GUICtrlListView_InsertColumn($TodoListView, 3, "Status", 70)

GUICtrlSetResizing($TodoListView, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKBOTTOM))

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

Had the same problem with SMF, GUICtrlSetResizing doesn't work with handles but only with control ids. If you need the handle, determine it with GUICtrlGetHandle(). Otherwise as far as I know anything that can be done with _GUICtrlListView_Create() you can add to GUICtrlCreateListView() with _GUICtrlListView_SetExtendedListViewStyle().

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$GUI = GUICreate("Resizing", 500, 200, -1, -1, $WS_OVERLAPPEDWINDOW)

$TodoListView = GUICtrlCreateListView("", 10, 20, 480, 160)

_GUICtrlListView_SetExtendedListViewStyle($TodoListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_InsertColumn($TodoListView, 0, "No", 70)
_GUICtrlListView_InsertColumn($TodoListView, 1, "Ref", 70)
_GUICtrlListView_InsertColumn($TodoListView, 2, "Item", 270)
_GUICtrlListView_InsertColumn($TodoListView, 3, "Status", 70)

GUICtrlSetResizing($TodoListView, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKBOTTOM))

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Well that works just fine. I didn't know you could combine GUICtrlCreateListView with the _GUICtrlListView UDF. I have incorporated this method into my program and the data retrieval and editing all still works.

Just one last question though. When the window is resized or maximized I need the Item column to resize according. The rest of the columns always need to stay the same size, is this possible to do?

Link to comment
Share on other sites

Like Zedna mentioned there might be a solution for that with WM_SIZE too. Another way might be to create an adlib polling the gui size with WinGetPos() and on change (save size to check string/array) you can use _GUICtrlListView_SetColumnWidth().

Edited by KaFu
Link to comment
Share on other sites

That was just what I needed, I have it working perfectly now. All I did was add two lines in the WM_SIZE function to delete the existing Item column, and then recreate it with the $iWidth variable minus the size of the other two columns.

I'm not sure if this is the most efficient way of doing it, but it definitely works. For anyone that's interested, here is an example.

Edit: Found a better way, the old method ended up removing everything in the Item column, it now just resizes the column without deleting it. See below:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>

$Gui = GUICreate("Gui", 500, 500, 100, 100, BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

    $List = _GUICtrlListView_Create($Gui, "", 10, 10, 480, 480)
    _GUICtrlListView_SetExtendedListViewStyle($List, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

    _GUICtrlListView_InsertColumn($List, 0, "No", 70)
    _GUICtrlListView_InsertColumn($List, 1, "Item", 310)
    _GUICtrlListView_InsertColumn($List, 2, "Status", 100)
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")

    GUISetState()

    While 1
        $Msg = GUIGetMsg()
        If $Msg = $GUI_EVENT_CLOSE Then Exit
    WEnd

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    Local $iWidth = BitAND($lParam, 0xFFFF)
    Local $iHeight = BitShift($lParam, 16)
    _WinAPI_MoveWindow($List, 10, 10, $iWidth - 20, $iHeight - 20, True)
    _GUICtrlListView_SetColumn($List, 2, "Item", $iWidth - 260)
    Return $GUI_RUNDEFMSG
EndFunc
Edited by HeXetic
Link to comment
Share on other sites

  • 1 year later...

That was just what I needed, I have it working perfectly now. All I did was add two lines in the WM_SIZE function to delete the existing Item column, and then recreate it with the $iWidth variable minus the size of the other two columns.

I'm not sure if this is the most efficient way of doing it, but it definitely works. For anyone that's interested, here is an example.

Edit: Found a better way, the old method ended up removing everything in the Item column, it now just resizes the column without deleting it. See below:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>

$Gui = GUICreate("Gui", 500, 500, 100, 100, BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

    $List = _GUICtrlListView_Create($Gui, "", 10, 10, 480, 480)
    _GUICtrlListView_SetExtendedListViewStyle($List, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))

    _GUICtrlListView_InsertColumn($List, 0, "No", 70)
    _GUICtrlListView_InsertColumn($List, 1, "Item", 310)
    _GUICtrlListView_InsertColumn($List, 2, "Status", 100)
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")

    GUISetState()

    While 1
        $Msg = GUIGetMsg()
        If $Msg = $GUI_EVENT_CLOSE Then Exit
    WEnd

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    Local $iWidth = BitAND($lParam, 0xFFFF)
    Local $iHeight = BitShift($lParam, 16)
    _WinAPI_MoveWindow($List, 10, 10, $iWidth - 20, $iHeight - 20, True)
    _GUICtrlListView_SetColumn($List, 2, "Item", $iWidth - 260)
    Return $GUI_RUNDEFMSG
EndFunc

Thanks this just helped me out loads :x

Drunken Frat-Boy Monkey Garbage

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...