Announcement

Collapse
No announcement yet.

ListView redraw problem

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

  • ListView redraw problem

    The following is some PB Forms code to illustrate the problem I need help with. It's a simple dialog with a tab control and Listview. I can show and hide the listview based on the tab pressed but if you resize the columns using the splitter bar it doesn't redraw correctly.

    I I leave the tab control but make it's height so that it doesn't occupy any of the space the listview does then the listview redraws correctly. What else do I need to do?
    Code:
    #PBFORMS CREATED V1.51
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #IF NOT %DEF(%WINAPI)
      #INCLUDE "WIN32API.INC"
    #ENDIF
    #IF NOT %DEF(%COMMCTRL_INC)
      #INCLUDE "COMMCTRL.INC"
    #ENDIF
    #INCLUDE "PBForms.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1           =  101
    %TAB_SYSTABCONTROL32_1 = 1001
    %LV    = 1002
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    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 SampleTabCtrl(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL _
      lCount AS LONG) AS LONG
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
      PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
        %ICC_INTERNET_CLASSES)
    
      ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
      LOCAL lpNmh AS NMHDR PTR
      LOCAL lTabhit AS LONG
    
      SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG
          ' Initialization handler
    
        CASE %WM_NOTIFY
          lpNmh = CBLPARAM
          SELECT CASE @lpNmh.idFrom  'correct id location
            CASE %TAB_SYSTABCONTROL32_1
              SELECT CASE @LPnMH.code
                CASE %NM_CLICK
                  CONTROL SEND CBHNDL,@lpNmh.idFrom, %tcm_getcursel, 0, 0, TO lTabhit
                    SetWindowText CBHNDL,STR$(lTabhit)
                    IF lTabhit = 1 THEN
                      CONTROL SHOW STATE CBHNDL,%LV,%SW_SHOW
                    ELSE
                      CONTROL SHOW STATE CBHNDL,%LV,%SW_HIDE
                    END IF
              END SELECT
          END SELECT
        CASE %WM_NCACTIVATE
          STATIC hWndSaveFocus AS DWORD
          IF ISFALSE CBWPARAM THEN
            ' Save control focus
            hWndSaveFocus = GetFocus()
          ELSEIF hWndSaveFocus THEN
            ' Restore control focus
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          END IF
    
        CASE %WM_COMMAND
          ' Process control notifications
          SELECT CASE AS LONG CBCTL
            CASE %TAB_SYSTABCONTROL32_1
    
            CASE %LV
    
          END SELECT
      END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Sample Code **
    '------------------------------------------------------------------------------
    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 SampleTabCtrl(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lCount _
      AS LONG) AS LONG
      LOCAL i        AS LONG
      LOCAL hCtl     AS DWORD
      LOCAL szBuf    AS ASCIIZ * 32
      LOCAL tTC_Item AS TC_ITEM
    
      CONTROL HANDLE hDlg, lID TO hCtl
    
      tTC_Item.Mask    = %TCIF_TEXT
      tTC_Item.iImage  = -1
      tTC_Item.pszText = VARPTR(szBuf)
    
      FOR i = 0 TO lCount - 1
        szBuf = USING$("Press me to hide " + STR$(i), i)
        IF I = 1 THEN
          szBuf = "Press me to show"
        END IF
        TabCtrl_InsertItem hCtl, i, tTC_Item
      NEXT i
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
      LOCAL lRslt AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
      LOCAL hDlg  AS DWORD
    
      DIALOG NEW hParent, "Dialog1", 70, 70, 396, 217, %WS_POPUP OR %WS_BORDER OR _
        %WS_DLGFRAME OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _
        %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
        %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR _
        %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
        %WS_EX_RIGHTSCROLLBAR, TO hDlg
      CONTROL ADD "SysTabControl32", hDlg, %TAB_SYSTABCONTROL32_1, _
        "SysTabControl32_1", 8, 16, 384, 176, %WS_CHILD OR %WS_VISIBLE OR _
        %WS_TABSTOP OR %TCS_SINGLELINE OR %TCS_RIGHTJUSTIFY, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING
      CONTROL ADD "SysListView32", hDlg, %LV, "SysListView32_1", _
        20, 44, 364, 128, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %LVS_REPORT _
        OR %LVS_SHOWSELALWAYS, %WS_EX_LEFT OR %WS_EX_CLIENTEDGE OR _
        %WS_EX_RIGHTSCROLLBAR
    #PBFORMS END DIALOG
    
      SampleTabCtrl  hDlg, %TAB_SYSTABCONTROL32_1, 5
      SampleListView hDlg, %LV, 3, 30
      CONTROL SHOW STATE hdlg,%LV,%SW_HIDE
      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
    #PBFORMS END CLEANUP
    
      FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    Bob Mechler

  • #2
    As a disclaimer, I really don't do DDT. However,
    I didn't have a splitterbar problem, but ther were others because of refresh issues. Try inserting these codes in FUNCTION ShowDIALOG1Proc() :
    ....
    CASE %WM_EXITSIZEMOVE
    ' ~~~~~~~~~~~~~~~~~~~~~
    CALL UpdateWindow(CBHNDL)

    CASE %WM_SYSCOMMAND
    ' ~~~~~~~~~~~~~~~~~~~
    IF CBWPARAM = %SC_MAXIMIZE OR CBWPARAM = %SC_RESTORE THEN
    CALL UpdateWindow(CBHNDL)
    END IF

    CASE %WM_COMMAND

    ' Process control notifications
    SELECT CASE AS LONG CBCTL
    CASE %TAB_SYSTABCONTROL32_1

    CASE %LV
    CALL UpdateWindow(CBHNDL)
    END SELECT
    ......

    regards, Ian
    :) IRC :)

    Comment


    • #3
      I placed the example code and it did not make a difference.

      I'm wondering if I should use a separate header control and a listview with the noheader setting so I don't have to subclass the control. The HDN_ENDTRACK event seems to be the one that fires when through with sizing the columns but that isn't available in a normal WM_NOTIFY callback. Reading different posts, it's only available in a subclassed listview. I tried the examples using DDT controls but the examples used SDK and I didn't have any luck.

      Bob Mechler

      Comment


      • #4
        Change order of listview and tab

        Change your Control Add Listview to before your tab and it will work. There are some old thread (can't find it now) about this!

        Comment


        • #5
          Hot dog! That worked just fine.

          Thanks,

          Bob Mechler

          Comment

          Working...
          X