Specifying only one optional argument in a function with multiple?

Started by Quin, February 12, 2025, 09:48:59 PM

Previous topic - Next topic

Quin


MrBcx

The following should help. 

You might need to insert multiple calls in your code to this SUB, especially if your code
is also modifying the listview control in question.

I've attached an updated AMORT.BAS to demonstrate this.



SUB ReduceListViewColumns(hListView AS HWND, KeepColumns AS INT)
    DIM ColCount AS INT
    DIM i AS INT
    DIM rc AS RECT
    DIM LVC AS LV_COLUMN
    DIM Width AS INT

    ' Detect number of columns
    ColCount = 0
    LVC.mask = LVCF_WIDTH
    WHILE SendMessage(hListView, LVM_GETCOLUMN, ColCount, &LVC)
        ColCount = ColCount + 1
    WEND

    ' Remove extra columns first
    FOR i = ColCount - 1 TO KeepColumns STEP -1
        SendMessage(hListView, LVM_DELETECOLUMN, i, 0)
    NEXT

    ' Get client rect
    SendMessage(hListView, &H100E, 0, &rc)
    Width = (rc.right - rc.left) / KeepColumns

    ' Set normal width
    FOR i = 0 TO KeepColumns - 1
        SendMessage(hListView, LVM_SETCOLUMNWIDTH, i, Width)
    NEXT
END SUB





Quin

I'm almost certain there's a way to do this, in fact I'm almost certain I've seen code to do it before, but I just cannot figure it out or find it in the docs.
I'm trying to create a Bcx_ListView with 5 columns instead of the normal 15. The only problem is that I don't want to change either of the window styles, just the NumCols parameter. However, this doesn't seem to be possible. I've tried putting multiple commas in a row like AutoHotkey (which I figured wouldn't work), tried NumCols = 5 after my height argument, I've tried NumCols: 5 in the same place, but I just can't figure it out.
Any tips/advice here?
Thanks!