CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Exclamation HOW: detect the column is resize in CListCtrl

    Hi!! I have a CListCtrl in report view.. How can I detect wether the divider between the column is moving or changing or being drag away? I have search through the MSDN and found out that HDN_TRACK can use to detect the devider is draging.. Am I right.. Please correct me if I am wrong..

    My problem is I don know how to code with HDN_TRACK.. Can anyone teach me to code on that? I have a scenarior here, if the divider bar is moving, I don care anything just as long as it is moving, then start the blah_function()..

    THank YOu @!
    Last edited by huahsin68; October 20th, 2004 at 11:02 PM.

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: HOW: detect the column is resize in CListCtrl

    If you're interested in calling some function when the user has stopped dragging the divider, handle HDN_ENDTRACK.

    HDN_BEGINTRACK - Notifies a header control's parent window that the user has begun dragging a divider in the control (that is, the user has pressed the left mouse button while the mouse cursor is on a divider in the header control).
    HDN_TRACK - Notifies a header control's parent window that the user is dragging a divider in the header control.
    HDN_ENDTRACK - Notifies a header control's parent window that the user has finished dragging a divider.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Re: HOW: detect the column is resize in CListCtrl

    My problem is how to code? I got this code from wizard:

    Code:
    void CBasicDlg::onBTrackList(NMHDR* pNMHDR, LRESULT* pResult) 
    {
       HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
       // TODO: Add your control notification handler code here
    	
       *pResult = 0;
    }

    THank YOu @!

  4. #4
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: HOW: detect the column is resize in CListCtrl

    Quote Originally Posted by huahsin68
    My problem is how to code?
    How to code what? You didn't specify what exactly you want to do when the divider is being dragged - you just said "start the blah_function()..". So add the call to blah_function() to the handler, and you're done.

  5. #5
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Re: HOW: detect the column is resize in CListCtrl

    No!! It is not working...

    I just put in TRACE("ASD\n"); in the code, but the output didn print the word... I think we have to do something with *phdn variable.. right?


    THank YOu @!

  6. #6
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: HOW: detect the column is resize in CListCtrl

    Quote Originally Posted by huahsin68
    I just put in TRACE("ASD\n"); in the code, but the output didn print the word...
    I hope you're aware that you will see the trace output only when you run your code in the debugger... Have you done that?
    Quote Originally Posted by huahsin68
    I think we have to do something with *phdn variable.. right?
    No. You need to access the HD_NOTIFY structure only to get additional info, like which column header was dragged. The handler will be called in any case.

  7. #7
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Re: HOW: detect the column is resize in CListCtrl

    Quote Originally Posted by gstercken
    I hope you're aware that you will see the trace output only when you run your code in the debugger... Have you done that?
    Of course I know this.. I am doing MFC.. I think there must be some trick to deal with HDN_TRACK... because before I post this thread, I found 1 thread also asking the same question, but that thread haven solve the problem yet...

    There must be some trick to get this done... right?

    The purpose of asking this question is because I have a scenario here. When I drag my column far away, the horizontal bar will appear, if the horizontal bar appear, then it will cover the last row... thus the verticle bar will appear also.. this will look urgly and I don like it... so what I did is, if the horizontal bar appear, I remove the last row, thus the verticle bar wouldn appear..

    So the key to solve this bug is to know how to detect the divider bar is being drag away.. If anyone can help, please suggest me or recommend me.. If not, I try the other algorithm...

    THank YOu @!

  8. #8
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: HOW: detect the column is resize in CListCtrl

    Two additional things:
    • Where have you implemented the handler for the HDN_TRACK notification message? Note that notification messages are sent to the control's parent window - however, for a header control in a list view control, the parent is the list view control, not the dialog that contains it. So if you haven't already done so, derive a class from CListCtrl and implement the handler there.
    • There is an ANSI vs. UNICODE issue with some notification messages - actually, the actual codes being sent are HDN_TRACKA and HDN_TRACKW, respectively. You might need to take that into account - see this MSDN artice for details.

  9. #9
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: HOW: detect the column is resize in CListCtrl

    Classwizard does not generate the correct message map entries for HDN_x messages. It adds a WM_NOTIFY using the ID of the control, not the header control. By default all CListCtrl headers have an ID of 0. If you change your message map entry control ID from the id of the control to 0, you would corretly receive the message.

    But this means that is you have multiple listctrls with HDN messages you cannot tell which control sent you the message. The easiest way to solve this problem is to do:

    m_listctrl.GetHeaderCtrl()->SetDlgCtrlID(m_listctrl.GetDlgCtrlID()); // get HDN_... messages to work correctly

    And then you can use the standard class wizard generated message map entries and have different ones for every control.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

  10. #10
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Re: HOW: detect the column is resize in CListCtrl

    Wow Roger... You are great... Your idea is great.. It seems much more simple than gstercken's link THanks

    I have tested your code, but it only works on HDN_ENDTRACK. Then how about HDN_TRACK and HDN_BEGINTRACK?

    THank YOu @!

  11. #11
    Join Date
    Sep 2003
    Location
    M...N
    Posts
    220

    Re: HOW: detect the column is resize in CListCtrl

    Quote Originally Posted by Roger Allen
    ... By default all CListCtrl headers have an ID of 0. If you change your message map entry control ID from the id of the control to 0, you would corretly receive the message.. ....

    This is too tricky!
    Anyway, it did work!

    It seems M$ doesn't try to fix this bug?

  12. #12
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: HOW: detect the column is resize in CListCtrl

    How To Sort Items in a CListCtrl in Report View documents the problem and solution described by Roger Allen. See the part that says:
    problem with header notifications for the ListView control
    I am not aware of any other place Microsoft says that, but it should be documented somewhere easier to find.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  13. #13
    Join Date
    Sep 2003
    Location
    M...N
    Posts
    220

    Re: HOW: detect the column is resize in CListCtrl

    OK, I post the article here to save everyone's time.

    MFC in Visual C++ 6.0 has a problem with header notifications for the ListView control. Although a handler can be added, in the current version it isn't called. For instance, use Class Wizard or the WizardBar to add a Windows Message Handler. If the ID for the ListView control is highlighted, a number of notification messages are available for selection. To sort the items when the header is clicked for a given column, select the notification HDN_ITEMCLICK. An ON_NOTIFY message map entry is generated, as well as a handler function. For the current example, the entry appears as follows:

    ON_NOTIFY(HDN_ITEMCLICK, IDC_LIST1, OnItemclickList1)



    The problem here is that the notification doesn't actually originate from the ListView control; instead, the Header control created by the ListView sends the notification. The message map entry listed above does not work. The fix is simple, however, since the Header control always has an ID of 0, the macro can be edited to work correctly:

    ON_NOTIFY(HDN_ITEMCLICK, 0, OnItemclickList1)

  14. #14
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: HOW: detect the column is resize in CListCtrl

    Quote Originally Posted by myron
    OK, I post the article here to save everyone's time.
    That is totally unnecessary and should not be done. Doing that could cost people time if the information changes. It is much better to post a link to things.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured