Catching header messages in a CListView

This is a quick tip, worked out by Linus Flueeler and myself. We were having problems catching header messages in a class dervied from CListView. The first thing we fixed were the macros produced by the class wizard, the autogenerated macros use the reflect mechanism which is not correct since the messages get sent to the header controls parent, which is the listview. So we changed the macros to use ON_NOTIFY, the id is 0 which is always the case for the header control in a listview control. Unfortunately this still didn't work. Since we are using NT but not ansi build we decided to try to catch the unicode messages, which did work. Below are the macros we used (we believe the ansi ones will be necessary for a program running on 95):
	ON_NOTIFY(HDN_BEGINTRACKW, 0, OnBeginTrack)
	ON_NOTIFY(HDN_ENDTRACKW, 0, OnEndTrack)
	ON_NOTIFY(HDN_BEGINTRACKA, 0, OnBeginTrack)
	ON_NOTIFY(HDN_ENDTRACKA, 0, OnEndTrack)



Comments

  • Why OnBeginTrack can't work

    Posted by Legacy on 06/14/2001 12:00am

    Originally posted by: Bob

    Great idea. But after I add OnBeginTrack and OnEndTrack as below:
    void CListDlg::OnEndTrack(NMHDR* pNMHDR, LRESULT* pResult)
    {
    HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
    // TODO: Add your control notification handler code here

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

    *pResult = 0;
    }
    Then, add the prototype in class declare as below:
    afx_msg void OnBeginTrack(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnEndTrack(NMHDR* pNMHDR, LRESULT* pResult);
    But when I debug the code, resize the column's width, I find that OnEndTrack works fine but OnBeginTrack does NOT work at all.
    Why? Can anybody give me some advise?
    Many thanks!

    Reply
  • Message from several pushbuttons -- how to process?

    Posted by Legacy on 02/18/2000 12:00am

    Originally posted by: ME

    Please,can anyone tell how to handle a message
    
    from several pushbuttons, which are created dynamically
    with a "Create" member function of CButton class.
    The matter is the buttons have contiguous IDs
    (i.e. 10000,10001 etc) and when are clicked, this event should be handled. I've tried
    a ON_NOTIFY_RANGE(NM_CLICK,10000,10001,OnClick) but
    a handling function OnClick malfunctioned(handling
    function should take buttons' IDs -- directly or
    through NMHDR structure).
    So how to process this message ?

    Thanking you in advance!

    Eugene V. Sharavin (evgeny@sibron.ru)

    Reply
  • Unexpected UNICODE Notification Messages.Could be an Official NT Bug

    Posted by Legacy on 12/19/1999 12:00am

    Originally posted by: Sam Hobbs

    There is a documented bug in NT. See Microsoft Knowledge Base Article Q148533, "PRB: No ANSI Notifications from Control Created in OnCreate". I think it explains the problems with getting unexpected UNICODE notification messages.

    However, when I implement the solution described in that article and I add processing for a HDN_ENDTRACK reflected message, I get the problem that (under NT only) the columns of the list control do not re-size as they should when I drag a column guide.

    Reply
  • Suggested solution to NT CListCtrl-CHeaderCtrl 'feature'

    Posted by Legacy on 12/03/1999 12:00am

    Originally posted by: Richard Hazlewood

    Here's a snippet of code I use in my CListCtrl class which:
    
    

    1) Allows the use of ClassWizard's HDN_ notifications by routing them back through notification reflection,

    2) Fixes the NT header control sizing problem, when running the header control in ANSI mode (see previous comment)
    (HDN_ITEMCHANGING updates the scroll bar, HDN_ITEMCHANGED updates the list control)

    ///////////////////////////////////////////////////////

    #include <..\src\afximpl.h> //for afxData

    BOOL CAListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
    {
    //Note: even though the class wizard shows HDN_ reflect notifications
    // for CListCtrls, they don't actually work because they are really notifying
    // the child header control. This solves the problem by forcing a reflection.

    NMHDR *pNMHDR = (NMHDR*)lParam;
    CHeaderCtrl *pHeader = GetHeaderCtrl();
    if (pHeader && (pNMHDR->hwndFrom == pHeader->m_hWnd)) {
    BOOL bReflect = FALSE;
    switch (pNMHDR->code) {
    //we could route every NM_ notification here, but I only require specific items:
    case NM_RCLICK: //because HDN_ITEMCLICK only sends left button..
    bReflect = TRUE;
    break;
    case HDN_ITEMCHANGINGA:
    if (afxData.bWin95)
    break;
    //list-control bug: on NT it doesn't seem to have handlers
    // for HDN_ITEMCHANGING/HDN_ITEMCHANGED Ansi versions when
    // the header is set to Ansi mode
    pNMHDR->code = HDN_ITEMCHANGINGW; //for scrollbar update
    *pResult = SendMessage(WM_NOTIFY, wParam, (LPARAM)pNMHDR);
    return TRUE;
    case HDN_ITEMCHANGEDA:
    if (afxData.bWin95)
    break;
    pNMHDR->code = HDN_ITEMCHANGEDW; //for column update
    *pResult = SendMessage(WM_NOTIFY, wParam, (LPARAM)pNMHDR);
    return TRUE;
    default:
    ASSERT(HDN_FIRST > HDN_LAST); //numbering is backwards
    bReflect = ((pNMHDR->code >= HDN_LAST) && (pNMHDR->code <= HDN_FIRST));
    break;
    }
    if (bReflect && ReflectChildNotify(WM_NOTIFY, wParam, lParam, pResult))
    return TRUE;
    }
    return CListCtrl::OnNotify(wParam, lParam, pResult);
    }

    Reply
  • HDN_ENDTRACK and GetColumnWidth in WinNt vs. Win95

    Posted by Legacy on 08/26/1999 12:00am

    Originally posted by: Dieter Elbracht

    your suggestions work fine so far.

    A user changes the width of a Column.
    GetColumnWidth in WinNt gives the new ColumWidth
    where in Win95 it always gives the width before the change

    Reply
  • Another suggestion

    Posted by Legacy on 08/25/1999 12:00am

    Originally posted by: Steven Boswell

    In the parent dialog's OnInitDialog(), get a pointer to the CListCtrl object (call it pList), and then
    
    

    pList->GetHeaderCtrl()->SetDlgCtrlID(pList->GetDlgCtrlID());

    Then all the macros that ClassWizard generates, such as

    ON_NOTIFY(HDN_ENDTRACK, IDC_LIST1, OnEndTrack)

    will work fine.

    Reply
  • UNCODE messages are always sent!

    Posted by Legacy on 02/25/1999 12:00am

    Originally posted by: Stuart Baker

    It would appear that on my machine (NT4 Sp3) that for the Header control notification messages (HDN_xxxx) they are all sent as HDN_xxxW, that is to say the unicode versions, why? I dont know!

    Guess someone at MS screwed up some how...if you spy++ on explorer4's header ctrl that too receives unicode messages (no that the proves much though...I didn't try it on any other windows)

    Reply
  • My suggestion

    Posted by Legacy on 02/03/1999 12:00am

    Originally posted by: Gopalakrishna Pillai.K

    We have to add macros for both widecharacter and unicode.So please add
    two macros for each message like this and check which one is working
    ON_NOTIFY(HDN_BEGINTRACKW, 0, OnBeginTrack)
    ON_NOTIFY(HDN_BEGINTRACKA, 0, OnBeginTrack)

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud-based suite of productivity collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

  • The relentless march of end user organizations toward cloud services continues, despite long-standing fears about information security, the lack of visibility into cloud provider security controls, and the shortcomings of controls available to those who utilize cloud services. And while more and more security-as-a-service (SaaS) solutions and application programming interfaces (APIs) are becoming available, many cloud service providers just aren't moving fast enough to address today's enterprise needs. Read …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date