Announcement

Collapse
No announcement yet.

Listview Header

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

  • Listview Header

    Greetings all you happy coding people!
    Question: Yes or No; Can the resizing\divider for a listview's
    header be disabled?

    Regards,
    Adam(Aka; the person who only lives about 6 miles from Michigan
    International Speedway and boy do you know when their's a race! )

    ------------------

  • #2
    I'm not sure, but with mouse controls you can cancel the mouse hit by suppressing wm_mouseactivate

    ' WM_MOUSEACTIVATE Return Codes
    %MA_ACTIVATE
    %MA_ACTIVATEANDEAT
    %MA_NOACTIVATE
    %MA_NOACTIVATEANDEAT


    ------------------
    hellobasic

    Comment


    • #3
      Rev, Rev, Rev.... Yes!

      Well that's more of a should be able to do it using subclassing.
      Playing with just the normal header control, there are messages
      sent before,during and after resize takes place. Or as Edwin
      mentioned you can eat some mouse messages by just subclassing
      the ListViews header control.

      Code:
      'Get the header component of the listview controls handle 
      hWndListViewHeader& = GetWindow(hWndNew,%GW_CHILD)
      If hWndListViewHeader& <> 0 Then
          'SubClass the Control.
          lpOldWndProc& = SetWindowLong(hWndListViewHeader&,%GWL_WNDPROC,ByVal CodePtr(ChildControlSubClassProc))
      End If
      HTH
      Regards,
      Jules



      [This message has been edited by Jules Marchildon (edited May 26, 2001).]
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        Thank you, gentlemen - your suggestions are most appreciated!
        Well I am off to do some more coding and in a day or two will be
        listening to the Engine Serenades by Johann Penske Bach!!!!!

        Whoops! That's what I get for not checking the schedule first -
        they don't have anything going on at MIS until June 9!
        Regards,
        Adam

        ------------------


        [This message has been edited by Adam Ritchie (edited May 26, 2001).]

        Comment


        • #5
          Hi Adam;

          Just tested the subclassed listview to achieve your desired effect.
          I had to subclass both listview and header. The header sends notificaions
          off to the listview, and the header is subclassed just to supress the
          cursor from changing to the sizer cursor.

          No more side effects, found the problem

          Code snippets...
          Code:
                 'subclass the listview control to catch some header notifications
                 'and supress the resizer on the header. Subclass the child header
                 'control to supress changing the cursor on us.
                  GLOBAL hWndListViewHeader AS LONG
                  GLOBAL lpOldWndProc1      AS LONG
                  GLOBAL lpOldWndProc2      AS LONG
                  lpOldWndProc1 = SetWindowLong(hListView,%GWL_WNDPROC,BYVAL CODEPTR(ListViewProc))
                  hWndListViewHeader = GetWindow( hListview,%GW_CHILD )
                  lpOldWndProc2 = SetWindowLong(hWndListViewHeader,%GWL_WNDPROC,BYVAL CODEPTR(HeaderProc))
                    
          ...etc
          
          CASE %WM_DESTROY
             'Unsubclass the Header Control...
             Call SetWindowLong( hWndListViewHeader,%GWL_WNDPROC,lpOldWndProc2 )
             Call SetWindowLong( hListView, %GWL_WNDPROC,lpOldWndProc1 )
          
          ...etc
          
           
          '-----------------------------------------------------------------------
          ' SubClassed ListView control
          ' Prevents header from sizing, but still allows button clicks.
          '-----------------------------------------------------------------------
          FUNCTION ListViewProc(BYVAL hWnd as LONG, _
                                BYVAL wMsg as LONG, _
                                BYVAL wParam as LONG, _
                                BYVAL lParam as LONG) AS LONG
           
          local hdnptr      as HD_NOTIFY PTR
          local hdiptr      as HD_ITEM   PTR
          local hditem      as HD_ITEM
           
              '---
              SELECT CASE wMsg
           
                  CASE %WM_NOTIFY  'wParam is the ID of header = 0 
                       
                          hdnptr = lParam
                          hdiptr = @hdnptr.pitem
                          select case @hdnptr.hdr.code
                              case %HDN_BEGINTRACKW   '<--must add "W" here
                                   FUNCTION = %TRUE
                              case else
                                   FUNCTION = CallWindowProc( lpOldWndProc1, hWnd, wMsg, wParam, lParam)
                          End Select
            
                  CASE ELSE
                      'A benign message, call the class procedure
                      FUNCTION = CallWindowProc( lpOldWndProc1, hWnd, wMsg, wParam, lParam)
           
              END SELECT
           
          END FUNCTION
           
           
          '-----------------------------------------------------------------------
          ' SubClassed child Header control in a ListView
          ' Prevents the cursor from changing on us when we don't want to resize
          '-----------------------------------------------------------------------
          FUNCTION HeaderProc(BYVAL hWnd as LONG, _
                              BYVAL wMsg as LONG, _
                              BYVAL wParam as LONG, _
                              BYVAL lParam as LONG) AS LONG
           
              '---
              SELECT CASE wMsg
          
                 'NOTE: uncomment this message if you don't care about clicking
                 '      the header buttons, in that case, you don't need to subclass
                 '      the Listview control itself, just the header.
                 ' 
                 'Defeat this message so that mouse clicks do not activate the control
                 'CASE %WM_MOUSEACTIVATE
                 '    Function = %MA_ACTIVATEANDEAT     
          
                 'feature that headers have of resizing a column when a
                 'double click is done on the column separator line.
                  CASE %WM_LBUTTONDBLCLK
                       FUNCTION = %TRUE  
           
                 'Defeat the system changing cursors on us. We do it based on our own hit testing
                  CASE %WM_SETCURSOR
                      Function = %TRUE
            
                  CASE ELSE
                      'A benign message, call the class procedure
                      FUNCTION = CallWindowProc( lpOldWndProc2, hWnd, wMsg, wParam, lParam)
            
              END SELECT
            
          END FUNCTION

          Regards,
          Jules

          Updated the above, now works as expected. Found the tip about using %HDN_BEGINTRACKW
          instead of %HDN_BEGINTRACK and the DoubleClick feature at the code guru site.



          [This message has been edited by Jules Marchildon (edited May 26, 2001).]
          Best regards
          Jules
          www.rpmarchildon.com

          Comment


          • #6
            Hmmm, interesting Jules. You know your suggestions were already
            underneath my nose. I am working on the visual forms stuff
            and you already had the solutions in the dmsmod.bas file where
            you subclassed the header of the listview control after it is
            created. The listview control I am working on is for the versions'
            info tab sheet of the options dialog I added to it(It's just about
            done).
            I don't need to do any sorting or anything like that.
            I just want to suppress the sizing of the columns simply becuase
            their is no reason to do so in this circumstance.
            Another idea I had was to get rid of the built-in header
            and "roll my own" using static controls with the WS_DLGFRAME
            style bit set and setting the parent to the listview control.
            I don't need button presses either so I think this will also
            give me the desired effect I want.
            Thanks so much sir!

            See ya',
            Adam

            ------------------

            Comment


            • #7
              I'm looking for a 'style' that autosizes the header to maximum width.
              I.o.w. only one header element and no way to size..
              Sure capturing messages, but maybe there's a better way?

              Btw, try to prevent the hook for the listview.
              Maybe you can use the header only.
              (I'm almost sure)


              ------------------
              hellobasic

              Comment


              • #8
                Another approach..

                This one hooks the header only.
                Note: %LVM_GETHEADER only for 4.70 and up, use Jules code instead.

                Code:
                 
                    hWndc = SendDlgItemMessage( CbHndl, 100, %LVM_GETHEADER, 0, 0)
                    SetWindowLong hWndc, %GWL_USERDATA, GetWindowLong( hWndc, %GWL_WNDPROC )
                    SetWindowLong hWndc, %GWL_WNDPROC, CodePtr( LVHeader_Callback )
                  
                Function LVHeader_Callback( ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long ) As Long
                 
                    Dim pPrevProc   As Long
                    Dim R           As Rect
                    Dim HDHT        As HDHITTESTINFO
                    Static hCursor  As Long
                 
                    pPrevProc = GetWindowLong( hWnd, %GWL_USERDATA )
                 
                    Select Case wMsg
                    Case %WM_NCHITTEST
                 
                        GetWindowRect hWnd, R
                 
                        HDHT.pt.x = LoWrd( lParam ) - R.nLeft
                        HDHT.pt.y = HiWrd( lParam ) - R.nTop
                 
                        SendMessage hWnd, %HDM_HITTEST, 0, VarPtr( HDHT )
                 
                        If ( HDHT.flags And %HHT_ONDIVIDER ) Then
                 
                            Function = %HTTRANSPARENT
                            Exit Function
                 
                        ElseIf( HDHT.flags And %HHT_ONDIVOPEN ) Then
                 
                            Function = %HTTRANSPARENT
                            Exit Function
                 
                        ElseIf( HDHT.flags And %HHT_ONHEADER ) Then
                 
                            hCursor = GetCursor()
                 
                        End If
                 
                    Case %WM_SETCURSOR
                 
                        If hCursor Then
                 
                            SetCursor hCursor
                            Function = 1
                            Exit Function
                 
                        End If
                 
                    Case %WM_DESTROY, %WM_NCDESTROY
                 
                        hCursor = 0
                 
                    End Select
                 
                    If pPrevProc Then
                        Function = CallWindowProc( pPrevProc, hWnd, wMsg, wParam, lParam )
                    End If
                 
                End Function
                ------------------
                hellobasic

                Comment


                • #9
                  Can the resizing\divider for a listview's
                  header be disabled?
                  Adam,
                  Yes you can without subclassing.

                  Code:
                    SetWindowLongA hListViewHeader, %GWL_STYLE, GetWindowLongA(hListViewHeader, %GWL_STYLE) OR %HDS_FLAT OR %HDS_NOSIZING

                  Comment


                  • #10
                    Wow Jim... this may set the record for a necropost, 18+ years later.
                    <b>George W. Bleck</b>
                    <img src='http://www.blecktech.com/myemail.gif'>

                    Comment


                    • #11
                      George,
                      My pleasure. Back from the near dead. Ha Ha I'm certain they will be wondering the same thing in the future. Same as they are now.

                      Comment

                      Working...
                      X