Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

' Very Simple Virtual Listview for PBWin10

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin ' Very Simple Virtual Listview for PBWin10

    ' Thanks to the expanded DDT in recent versions of PowerBasic for
    ' Windows, it is now possible to make a virtual listview in a very
    ' simple way. Scrollbar controls are used instead of listview's
    ' built-in scrollbars, which move in pixel steps instead of item/
    ' subitem steps. The latter seems preferable for a grid like this.
    '
    ' Best regards
    '
    ' Erik

    Code:
    ' Very Simple Virtual Listview for PBWin10
    '
    ' Thanks to the expanded DDT in recent versions of PowerBasic for
    ' Windows, it is now possible to make a virtual listview in a very
    ' simple way. Scrollbar controls are used instead of listview's
    ' built-in scrollbars, which move in pixel steps instead of item/
    ' subitem steps. The latter seems preferable for a grid like this.
    '
    ' Best regards
    '
    ' Erik
    '
    #COMPILE EXE
    #DIM ALL
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "COMMCTRL.INC"
    #INCLUDE ONCE "PBForms.INC"
    '
    %IDD_DIALOG1               =  101
    %IDC_LISTVIEW1             = 1001
    %IDC_SCROLLBAR2_VERTICAL   = 1003
    %IDC_SCROLLBAR1_HORIZONTAL = 1002
    %IDC_FRAME1                = 1004
    '
    SUB UpdateListview(BYREF DataArray() AS STRING, BYVAL xPos AS LONG, BYVAL yPos AS LONG, _
                       BYVAL xPage AS LONG, BYVAL yPage AS LONG, BYVAL hDlg AS LONG)
        LOCAL i AS LONG, j AS LONG
        FOR i = 1 TO xPage + 2
            LISTVIEW SET COLUMN hDlg, %IDC_LISTVIEW1, i, 130
            LISTVIEW SET HEADER hDlg, %IDC_LISTVIEW1, i, DataArray(i + xPos - 1, 0)
        NEXT
        FOR j = 1 TO yPage
            FOR i = 1 TO xPage + 2
                LISTVIEW SET TEXT hDlg, %IDC_LISTVIEW1, j, i, DataArray(i + xPos - 1, j + yPos - 1)
            NEXT
        NEXT
    END SUB
    '
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        STATIC i AS LONG, j AS LONG
        STATIC Rows AS LONG, Columns AS LONG
        STATIC xPos AS LONG, xPage AS LONG, xMin AS LONG, xMax AS LONG
        STATIC yPos AS LONG, yPage AS LONG, yMin AS LONG, yMax AS LONG
    
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
                ' Specification of size of array.
                ' You may specify any size.
                Rows = 100
                Columns = 500
                '
                ' Two empty columns are being added.
                DIM DataArray(1 TO Columns + 2, 0 TO Rows) AS STATIC STRING
                ' Fill array with data
                FOR i = 1 TO Columns
                    FOR j = 0 TO Rows
                        IF j = 0 THEN  ' Row zero is used for column headers.
                            DataArray(i, j)= " column" + STR$(i)
                        ELSE           ' j >= 1  Item/subitem content
                            DataArray(i, j)= " column" + STR$(i) + " row" + STR$(j)
                        END IF
                    NEXT
                NEXT
                '
                ' Number of rows and columns in a displayed page
                yPage = 19
                xPage = 5
    
                ' Initialize listview and scrolbars
                LOCAL lStyle AS LONG
                LISTVIEW GET STYLEXX CBHNDL, %IDC_LISTVIEW1 TO lStyle
                LISTVIEW SET STYLEXX CBHNDL, %IDC_LISTVIEW1, lStyle OR %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
                FOR i = 1 TO xPage + 2
                    LISTVIEW INSERT COLUMN CBHNDL, %IDC_LISTVIEW1, i, DataArray(i, 0), 130, 0
                NEXT
                FOR j = 1 TO yPage
                    LISTVIEW INSERT ITEM CBHNDL, %IDC_LISTVIEW1, j, 1, DataArray(1, j)
                    FOR i = 2 TO xPage + 2
                        LISTVIEW SET TEXT CBHNDL, %IDC_LISTVIEW1, j, i, DataArray(i, j)
                    NEXT
                NEXT
    
                yMin = 1 : yMax = Rows : yPos = 1
                SCROLLBAR SET PAGESIZE CBHNDL, %IDC_SCROLLBAR2_VERTICAL, yPage
                SCROLLBAR SET RANGE CBHNDL, %IDC_SCROLLBAR2_VERTICAL, yMin, yMax
    
                xMin = 1 : xMax = Columns : xPos = 1
                SCROLLBAR SET PAGESIZE CBHNDL, %IDC_SCROLLBAR1_HORIZONTAL, xPage
                SCROLLBAR SET RANGE CBHNDL, %IDC_SCROLLBAR1_HORIZONTAL, xMin, xMax
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CB.WPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
    
            CASE %WM_HSCROLL
                SELECT CASE LOWRD(CBWPARAM)' scroll message
                    CASE %SB_LINERIGHT     : INCR xPos
                    CASE %SB_PAGERIGHT     : xPos = xPos + xPage - 1
                    CASE %SB_LINELEFT      : DECR xPos
                    CASE %SB_PAGELEFT      : xPos = xPos - xPage + 1
                    CASE %SB_THUMBPOSITION, %SB_THUMBTRACK : SCROLLBAR GET TRACKPOS CBHNDL, %IDC_SCROLLBAR1_HORIZONTAL TO xPos
                END SELECT
                xPos = MAX&(xMin, MIN&(xPos, xMax - xPage + 1)) ' Ensure that position is within range
                SCROLLBAR SET POS CBHNDL, %IDC_SCROLLBAR1_HORIZONTAL, xPos
                CALL UpdateListview(DataArray(), xPos, yPos, xPage, yPage, CBHNDL)
    
            CASE %WM_VSCROLL
                SELECT CASE LOWRD(CBWPARAM)' scroll message
                    CASE %SB_LINEDOWN      : INCR yPos
                    CASE %SB_PAGEDOWN      : yPos = yPos + yPage - 1
                    CASE %SB_LINEUP        : DECR yPos
                    CASE %SB_PAGEUP        : yPos = yPos - yPage + 1
                    CASE %SB_THUMBPOSITION, %SB_THUMBTRACK : SCROLLBAR GET TRACKPOS CBHNDL, %IDC_SCROLLBAR2_VERTICAL TO yPos
                END SELECT
                yPos = MAX&(yMin, MIN&(yPos, yMax - yPage + 1)) ' Ensure that position is within range
                SCROLLBAR SET POS CBHNDL, %IDC_SCROLLBAR2_VERTICAL, yPos
                CALL UpdateListview(DataArray(), xPos, yPos, xPage, yPage, CBHNDL)
    
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                    ' not used here
                END SELECT
        END SELECT
    END FUNCTION
    '
    FUNCTION PBMAIN()
        PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
            %ICC_INTERNET_CLASSES)
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
        DIALOG NEW PIXELS, 0, "Very Simple Virtual Listview", , , 741, 410, _
            %WS_POPUP OR %WS_BORDER OR _
            %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR _
            %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
            %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
            OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LISTVIEW,  hDlg, %IDC_LISTVIEW1, "", 20, 20, 680, _
            350, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %LVS_REPORT OR _
            %LVS_SHOWSELALWAYS OR %LVS_NOSCROLL, _ ' please note the NOSCROLL style
            %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
        CONTROL ADD SCROLLBAR, hDlg, %IDC_SCROLLBAR1_HORIZONTAL, "", 20, 370, _
            680, 20
        CONTROL ADD SCROLLBAR, hDlg, %IDC_SCROLLBAR2_VERTICAL, "", 700, 20, 20, _
            350, %WS_CHILD OR %WS_VISIBLE OR %SBS_VERT
        CONTROL ADD FRAME,     hDlg, %IDC_FRAME1, "", 20, 12, 700, 380, %WS_CHILD _
            OR %WS_VISIBLE OR %BS_LEFT OR %BS_TOP OR %BS_GROUPBOX, _
             %WS_EX_LEFT OR %WS_EX_LTRREADING
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        FUNCTION = lRslt
    END FUNCTION

  • #2
    I started a discussion thread here.

    Comment

    Working...
    X