Announcement

Collapse
No announcement yet.

ListView and HDN_ENDTRACK

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

  • ListView and HDN_ENDTRACK

    From other threads the Header control is a child control of the ListView. So how does one trap the resizing of the header control of a listview column?

    In other words, in the WM_NOTIFY event, it seems from MSDN that I should be using a NMHEADER PTR and the NMHDR.hdr.code. That would work for the separate Header control but doesn't seem to work for a header control that is a child control of the ListView control.

    Do I need to subclass the ListView to get the Header control message in the WM_NOTIFY event of the ListView? Is there even a WM_NOTIFY message associated with a sub classed Listview?

    Any help would be appreciated.

    Bob Mechler
    Last edited by BOB MECHLER; 30 Jun 2009, 10:04 AM.

  • #2
    This works for me to expand the last column of a listview to fill available space on resize..
    Code:
    MACRO EQ32(a,b)              = (BITS???(a)=BITS???(b))
    ' NOTE: THIS MAY BE REPLACED BY BITSE() in 8x or maybe 9x 
    
    UNION LvUnion
       NMHDR  AS NMHDR
       NMLV   AS NMLISTVIEW
       NMIA   AS NMITEMACTIVATE
       LVDI   AS LV_DISPINFO
       LVCD   AS NMLVCUSTOMDRAW
       NMTTDI AS NMTTDISPINFO
    END UNION
    
    ...
    
    LOCAL hCtrl AS LONG, szText AS ASCIIZ * %MAX_PATH, plvu AS LvUnion PTR, w AS STRING
    
    ....
      CASE %WM_NOTIFY
                     plvu   = lparam
    
                     ' if Endtrack message THIS WORKS
                     IF eq32(@plvu.nmhdr.code, %HDN_ENDTRACK) THEN
                         hCtrl = getDlgItem(hWnd, %ID_LV)
                         IF @plvu.nmhdr.hwndFrom = Listview_GetHeader (hCtrl) THEN
                             Listview_SetColumnWidth  hCtrl, %COL_MAX, %LVSCW_AUTOSIZE_USEHEADER
                              EXIT FUNCTION
                          END IF
                     END IF     '
    Last edited by Michael Mattias; 30 Jun 2009, 10:24 AM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I'm not going to pretend to understand this code fully.

      Is the Union useful to trap the HDN_ENDTRACK when normally it can't be trapped by using a select case based on the control id of the listview?

      Should it be outside any select case that isolates the listview's control id?

      Bob Mechler

      Comment


      • #4
        The UNION is immaterial; it's just what I use for handling WM_NOTIFY from lots of different Common controls.

        I think I should have gone on to show the rest of the WM_NOTIFY code. That code continues with your 'conventional' test of control ID ..
        Code:
        CASE %WM_NOTIFY
                         plvu   = lparam
        
                         ' if Endtrack message THIS WORKS
                         IF eq32(@plvu.nmhdr.code, %HDN_ENDTRACK) THEN
                             hCtrl = getDlgItem(hWnd, %ID_LV)
                             IF @plvu.nmhdr.hwndFrom = Listview_GetHeader (hCtrl) THEN
                                 Listview_SetColumnWidth  hCtrl, %COL_MAX, %LVSCW_AUTOSIZE_USEHEADER
                                  EXIT FUNCTION
                              END IF
                         END IF     '
        
        ' ***  'regular'  WM_NOTIFY 'SELECT CASE' block begins here ***
                         SELECT CASE AS LONG @plvu.nmhdr.idfrom
        
                           CASE %ID_LV
        
                                SELECT CASE AS LONG @plVU.nmhdr.code
        
                                   CASE  %NM_CUSTOMDRAW  ' returns LVCD (NMLVCUSTOMDRAW)
        
                                      SELECT CASE AS LONG @plvu.LVCD.nmcd.dwDrawStage
                                          ' return:
                                         CASE %CDDS_PREPAINT
                   yadda yadda yadda
        What I did was FIRST test for "HDN_ENDTRACK from the Listview's Header" ... then go into a 'regular' test for Control, then code.

        You have to do it this way because you can't control the "Ctrlid" of the header control created by the listview control (AFAIK) and therefore can't test for it in a 'regular' WM_NOTIFY 'SELECT CASE' block.

        MCM
        Last edited by Michael Mattias; 30 Jun 2009, 10:56 AM.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          >Should it be outside any select case that isolates the listview's control id?

          I guess I could have just said "yes," huh?

          (FWIW I found that code using your Disk Utility program).
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Thanks for the extra detail. I believe I can proceed from here.

            Bob Mechler

            Comment


            • #7
              %HDN_ITEMCHANGED worked better than %HDN_ENDTRACK for some reason but the overall idea worked fine.

              In the application I'm tracking up to a possible 10 listviews on different tabs where the width of each column can be unique based on each user of which can be hundreds. Keeping the columnwidths in a random file named with the program name and username.

              Bob Mechler

              Comment

              Working...
              X