Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CListCtrl - stop headers from being resized

CListCtrl - stop headers from being resized

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tre K Renegade
    wrote on last edited by
    #1

    Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren

    R M O 3 Replies Last reply
    0
    • T Tre K Renegade

      Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      I am not 100% sure about this, but you need to handle the HDN_BEGINDRAG message (?) and return FALSE. I seem to recall this from somewhere. Hope its of help. Roger Allen Sonork 100.10016 WHats brown and sticky? A stick or some smelly stuff!

      1 Reply Last reply
      0
      • T Tre K Renegade

        Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren

        M Offline
        M Offline
        Mike Upton
        wrote on last edited by
        #3

        You need to handle the HDN_BEGINTRACK notification sent by the list's header control, and return TRUE to disable resizing. [edit]changed FALSE to TRUE above (whoops!)[/edit]


        "We are the knights who say Ni" (The Knights Who Say Ni)

        1 Reply Last reply
        0
        • T Tre K Renegade

          Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren

          O Offline
          O Offline
          OBRon
          wrote on last edited by
          #4

          If you implement a notification handler for HDN_BEGINTRACK and within that function set *pResult = TRUE, that will prevent the header sizing from happening. Unfortunately, the handler for HDN_DIVIDERDBLCLICK does not allow this override, so header sizing can still happen if the user double clicks a header divider. I don't know a way to change this behavior. Ron Ward

          T 1 Reply Last reply
          0
          • O OBRon

            If you implement a notification handler for HDN_BEGINTRACK and within that function set *pResult = TRUE, that will prevent the header sizing from happening. Unfortunately, the handler for HDN_DIVIDERDBLCLICK does not allow this override, so header sizing can still happen if the user double clicks a header divider. I don't know a way to change this behavior. Ron Ward

            T Offline
            T Offline
            Tre K Renegade
            wrote on last edited by
            #5

            Hi, I tried this, but nothing seems to happen. Resizing is still possible. I just used the classwizard to add a handler for =HDN_BEGINTRACK and made the change you suggested, like this: void CMyList::OnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR; *pResult = TRUE; } Perhaps there is something else I'm doing that's preventing your solution from working. But I can't find anything out of the ordinary. I just SubClassDlgItem() and set the extended style to include gridlines and fullrowselect. Any ideas? Thanks. Ren.

            M 1 Reply Last reply
            0
            • T Tre K Renegade

              Hi, I tried this, but nothing seems to happen. Resizing is still possible. I just used the classwizard to add a handler for =HDN_BEGINTRACK and made the change you suggested, like this: void CMyList::OnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR; *pResult = TRUE; } Perhaps there is something else I'm doing that's preventing your solution from working. But I can't find anything out of the ordinary. I just SubClassDlgItem() and set the extended style to include gridlines and fullrowselect. Any ideas? Thanks. Ren.

              M Offline
              M Offline
              Mike Upton
              wrote on last edited by
              #6

              If you use classwizard to insert a handler for HDN_BEGINTRACK in the list control, it incorrectly inserts a reflection handler, even though the notification is sent directly to the list control (ie not through the reflection mechanism). That's why the classwizard handler is marked =HDN_BEGINTRACK (= indicates a reflected notification). You need to replace the line ON_NOTIFY_REFLECT(HDN_ENDTRACK, OnEndtrack) in the message map with ON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrack). (See the MSDN knowledge base article Q281155)


              "We are the knights who say Ni" (The Knights Who Say Ni)

              T 1 Reply Last reply
              0
              • M Mike Upton

                If you use classwizard to insert a handler for HDN_BEGINTRACK in the list control, it incorrectly inserts a reflection handler, even though the notification is sent directly to the list control (ie not through the reflection mechanism). That's why the classwizard handler is marked =HDN_BEGINTRACK (= indicates a reflected notification). You need to replace the line ON_NOTIFY_REFLECT(HDN_ENDTRACK, OnEndtrack) in the message map with ON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrack). (See the MSDN knowledge base article Q281155)


                "We are the knights who say Ni" (The Knights Who Say Ni)

                T Offline
                T Offline
                Tre K Renegade
                wrote on last edited by
                #7

                Sorry guys, but it's still not working. I've tried changing the message map as directed, but nothing happens. The message is still not sent. (I've checked with a messagebox.) I noticed that the MSDN article refers to CListView while I'm working with a CListCtrl. Could this have anything to do with it?

                C 1 Reply Last reply
                0
                • T Tre K Renegade

                  Sorry guys, but it's still not working. I've tried changing the message map as directed, but nothing happens. The message is still not sent. (I've checked with a messagebox.) I noticed that the MSDN article refers to CListView while I'm working with a CListCtrl. Could this have anything to do with it?

                  C Offline
                  C Offline
                  Chris Richardson
                  wrote on last edited by
                  #8

                  I had gone through this in a lengthy thread a while back on CodeGuru: http://www.codeguru.com/forum/showthread.php?s=&threadid=215009[^] There are several ways to handle it. Chris Richardson C/C++ Include Finder[^]

                  T 1 Reply Last reply
                  0
                  • C Chris Richardson

                    I had gone through this in a lengthy thread a while back on CodeGuru: http://www.codeguru.com/forum/showthread.php?s=&threadid=215009[^] There are several ways to handle it. Chris Richardson C/C++ Include Finder[^]

                    T Offline
                    T Offline
                    Tre K Renegade
                    wrote on last edited by
                    #9

                    I have to admit I don't really understand everything being explained in the thread, but no worries: it works now. I'll just give a short report for any interested parties too lazy to check the thread you mentioned: PROBLEM: Stop CListCtrl column headers from being resized. SOLUTION: Let your view handle the HDN_BEGINTRACK message and have it return TRUE. void CMyList::OnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR; *pResult = TRUE; } BUG: Something about the class wizard messing up and another thing about unicode and ansi, which results in your handler never being called. FIX: Edit your message map manually. First remove: ON_NOTIFY_REFLECT(HDN_BEGINTRACK,OnBeginTrack) And instead add: ON_NOTIFY(HDN_BEGINTRACKW, 0, OnBegintrack) ON_NOTIFY(HDN_BEGINTRACKA, 0, OnBegintrack) That's it. Thanks 4 the help, guys.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups