Announcement

Collapse
No announcement yet.

Listview scroll position

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

  • Listview scroll position

    I can't quite find the solution to this.

    I have a 2 column listview that can scroll. Right now, I just care about Horiz scroll.

    I get the scroll bar position with

    control handle cbhndl, ListviewID to hCtl
    pos= GetScrollPos(hctl,%SB_HORZ)

    and later

    SetScrollPos(hCTL,%SB_HORZ,pos,-1)

    But that only sets the scroll bar

    Adding
    ListView_Scroll (hCTL,pos,0) moves the listview, but this is in pixels and what is saved with GetScroll pos is not. Is there a way to get the ListView scroll position?
    Barry

  • #2
    removed original suggestion.

    You probably will need to relate the scroll bar range to the pixel length it takes.
    ListView_GetItemRect
    GetScrollRange
    Last edited by Richard Angell; 12 Jan 2008, 12:11 PM.
    Rick Angell

    Comment


    • #3
      Barry,

      It appears that the stock LV has a range in pixels 1 pixel off from the ListView_GetItemRect horizontal value. See CASE %WM_USER+100 in the demo code below. Does this help? Is your dialog or window in PIXELS?

      Code:
      #PBFORMS CREATED V1.51
      #COMPILE EXE
      #DIM ALL
      
      #PBFORMS BEGIN INCLUDES
      %USEMACROS = 1
      #IF NOT %DEF(%WINAPI)
          #INCLUDE "WIN32API.INC"
      #ENDIF
      #IF NOT %DEF(%COMMCTRL_INC)
          #INCLUDE "COMMCTRL.INC"
      #ENDIF
      #INCLUDE "PBForms.INC"
      #PBFORMS END INCLUDES
      
      #PBFORMS BEGIN CONSTANTS
      %IDLG_DIALOG1         =  101
      %ILVC_SYSLISTVIEW32_1 = 1001
      %ILBL_POSITION        = 1002
      %IBTN_QUIT         = 1003
      #PBFORMS END CONSTANTS
      
      DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
      DECLARE FUNCTION SampleListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL _
          lColCnt AS LONG, BYVAL lRowCnt AS LONG) AS LONG
      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
      #PBFORMS DECLARATIONS
      
      FUNCTION PBMAIN()
          PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
              %ICC_INTERNET_CLASSES)
      
          ShowDIALOG1 %HWND_DESKTOP
      END FUNCTION
      
      CALLBACK FUNCTION ShowDIALOG1Proc()
          STATIC hListView AS DWORD
          LOCAL x,rslt AS LONG
          LOCAL lpMinPos,lpMaxPos  AS LONG
      
          SELECT CASE AS LONG CBMSG
              CASE %WM_INITDIALOG
                  CONTROL HANDLE CBHNDL,%ILVC_SYSLISTVIEW32_1 TO hListView
                  DIALOG POST CBHNDL,%WM_USER+100,0,0
      
              CASE %WM_USER+100
                   rslt = GetScrollRange(hListView, %SB_HORZ,lpMinPos,lpMaxPos)
                   CONTROL SEND CBHNDL,%ILVC_SYSLISTVIEW32_1,%LVM_SCROLL,500,0
                   x = GetScrollPos(hListView, %SB_HORZ)
                   CONTROL SET TEXT CBHNDL,%ILBL_POSITION,FORMAT$(x)
      
              CASE %WM_NCACTIVATE
                  STATIC hWndSaveFocus AS DWORD
                  IF ISFALSE CBWPARAM THEN
                      hWndSaveFocus = GetFocus()
                  ELSEIF hWndSaveFocus THEN
                      SetFocus(hWndSaveFocus)
                      hWndSaveFocus = 0
                  END IF
      
              CASE %WM_COMMAND
                  SELECT CASE AS LONG CBCTL
                      CASE %ILVC_SYSLISTVIEW32_1
      
                      CASE %ILBL_POSITION
      
                      CASE %IBTN_QUIT
                          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                              DIALOG END CBHNDL
                          END IF
      
                  END SELECT
          END SELECT
      END FUNCTION
      
      FUNCTION SampleListView(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lColCnt _
          AS LONG, BYVAL lRowCnt AS LONG) AS LONG
          LOCAL lCol   AS LONG
          LOCAL lRow   AS LONG
          LOCAL hCtl   AS DWORD
          LOCAL tLVC   AS LV_COLUMN
          LOCAL tLVI   AS LV_ITEM
          LOCAL szBuf  AS ASCIIZ * 32
          LOCAL lStyle AS LONG
      
          CONTROL HANDLE hDlg, lID TO hCtl
      
          lStyle = ListView_GetExtendedListViewStyle(hCtl)
          ListView_SetExtendedListViewStyle(hCtl, lStyle OR %LVS_EX_FULLROWSELECT _
              OR %LVS_EX_GRIDLINES)
      
          ' Load column headers.
          tLVC.mask    = %LVCF_FMT OR %LVCF_TEXT OR %LVCF_SUBITEM
          tLVC.fmt     = %LVCFMT_LEFT
          tLVC.pszText = VARPTR(szBuf)
          FOR lCol = 0 TO lColCnt - 1
              szBuf       = USING$("Column #", lCol)
              tLVC.iOrder = lCol
              ListView_InsertColumn(hCtl, lCol, tLVC)
          NEXT lCol
      
          ' Load sample data.
          FOR lRow = 0 TO lRowCnt - 1
              tLVI.stateMask = %LVIS_FOCUSED
              tLVI.pszText   = VARPTR(szBuf)
              tLVI.iItem     = lRow
              FOR lCol = 0 TO lColCnt - 1
                  szBuf         = USING$("Column # Row #", lCol, lRow)
                  tLVI.iSubItem = lCol
                  tLVI.lParam   = lRow
                  IF lCol = 0 THEN
                      tLVI.mask = %LVIF_TEXT OR %LVIF_PARAM OR %LVIF_STATE
                      ListView_InsertItem(hCtl, tLVI)
                  ELSE
                      tLVI.mask = %LVIF_TEXT
                      ListView_SetItem(hCtl, tLVI)
                  END IF
              NEXT lCol
          NEXT lRow
      
          ' Auto size columns.
          FOR lCol = 0 TO lColCnt - 2
              ListView_SetColumnWidth(hCtl, lCol, %LVSCW_AUTOSIZE)
          NEXT lCol
          ListView_SetColumnWidth(hCtl, lColCnt - 1, %LVSCW_AUTOSIZE_USEHEADER)
      END FUNCTION
      
      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt  AS LONG
      
      #PBFORMS BEGIN DIALOG %IDLG_DIALOG1->->
          LOCAL hDlg   AS DWORD
          LOCAL hFont1 AS DWORD
          LOCAL hFont2 AS DWORD
      
          DIALOG NEW hParent, "LV Horizontal Scroll Position", 322, 128, 400, 246, _
              %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
              %WS_SYSMENU 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 "SysListView32", hDlg, %ILVC_SYSLISTVIEW32_1, _
              "SysListView32_1", 5, 5, 380, 200, %WS_CHILD OR %WS_VISIBLE OR _
              %WS_BORDER OR %WS_TABSTOP OR %LVS_REPORT OR %LVS_SINGLESEL OR _
              %LVS_SHOWSELALWAYS OR %LVS_EDITLABELS, %WS_EX_CLIENTEDGE OR _
              %WS_EX_LEFT OR %WS_EX_RIGHTSCROLLBAR
          CONTROL ADD LABEL,  hDlg, %ILBL_POSITION, "0", 10, 215, 120, 25
          CONTROL ADD BUTTON, hDlg, %IBTN_QUIT, "Quit", 330, 215, 50, 25
      
          hFont1 = PBFormsMakeFont("MS Sans Serif", 18, 700, %FALSE, %FALSE, _
              %FALSE, %ANSI_CHARSET)
          hFont2 = PBFormsMakeFont("MS Sans Serif", 18, 700, %FALSE, %TRUE, %FALSE, _
              %ANSI_CHARSET)
      
          CONTROL SEND hDlg, %ILBL_POSITION, %WM_SETFONT, hFont1, 0
          CONTROL SEND hDlg, %IBTN_QUIT, %WM_SETFONT, hFont2, 0
      #PBFORMS END DIALOG
      
          SampleListView hDlg, %ILVC_SYSLISTVIEW32_1, 20, 100
      
          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
      
      #PBFORMS BEGIN CLEANUP %IDLG_DIALOG1
          DeleteObject hFont1
          DeleteObject hFont2
      #PBFORMS END CLEANUP
      
          FUNCTION = lRslt
      END FUNCTION
      Rick Angell

      Comment


      • #4
        It appears that the stock LV has a range in pixels 1 pixel off from the ListView_GetItemRect horizontal value
        Retrieved RECT boundaries are always inclusive of the four points, making
        Width = nRight - nLeft + 1.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          The problem was I was using SetScrollPos and not sending a message for the Listview with LVM_SETSCROLL

          Thanks for the example.
          Barry

          Comment


          • #6
            Right you are Michael.
            Rick Angell

            Comment

            Working...
            X