CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    5

    How to catch LVN_COLUMNCLICK in a subclassing ListViewCtrl

    As I created an ActiveX control which subclassed Windows control SysListView32, I tried to catch the message LVN_COLUMNCLICK which generated when i clicked the header of my listview control, but OnOcmCommand failed, it is not even called.

    Can anyone give me some help? I also want to catch the message of mouse click and double click.

    thank you very much!


  2. #2
    Guest

    Re: How to catch LVN_COLUMNCLICK in a subclassing ListViewCtrl

    This works for me:

    In the CPP file:

    BEGIN_MESSAGE_MAP(MyListCtrl, CListCtrl)
    //{{AFX_MSG_MAP(MyListCtrl)
    ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()


    // This is a reflected message handler, which means that this control
    // handles this message instead of the parent window. Any handler
    // for this message in the parent window will override this handler
    // (unless it calls this handler first, of course).
    void MyListCtrl::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
    {
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*) pNMHDR;

    DoCoolStuffLikeSortColumn(pNMListView->iSubItem);
    *pResult = 0;
    }

    ... and in the H file:

    afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);

    HTH!



  3. #3
    Join Date
    Apr 1999
    Posts
    5

    Re: I've found the solution

    LVN_COLUMNCLICK is a WM_NOTIFY format message rather than a WM_COMMAND one, and can not be caught by OnOcmCommand.

    Here are some code of mine, wish it will be helpful to someone:

    ON_MESSAGE(OCM_NOTIFY, OnOcmNotify)

    LRESULT CMyListCtrl::OnOcmNotify(WPARAM wParam, LPARAM lParam)
    {
    NMHDR * pNMHDR = (NMHDR *)lParam;
    UINT nNotifyCode = pNMHDR->code;
    switch (nNotifyCode)
    {
    case LVN_COLUMNCLICK:
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lParam;
    ......
    break;
    }

    return 0;
    }



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