CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    [RESOLVED] How to send an LVN_COLUMNCLICK message?

    Hello

    I read it on MSDN that it should be sent through WM_NOTIFY.

    And that the iSubItem number has to be put in a NMLISTVIEW structure.

    But where do I put the NMLISTVIEW structure to tell it to which column to click on?

    Code:
    NMHDR nmh;
    nmh.code = LVN_COLUMNCLICK;    // Message type defined by control.
    nmh.idFrom = GetDlgCtrlID(hListView);
    nmh.hwndFrom = hListView;
     
    NMLISTVIEW nmlv = {0};
    nmlv.iItem = -1;
    nmlv.iSubItem = 1;
     
    SendMessage(hwnd, WM_NOTIFY, nmh.idFrom,(LPARAM)&nmh);
    https://docs.microsoft.com/en-us/win...rols/wm-notify

    https://docs.microsoft.com/en-us/win...vn-columnclick

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: How to send an LVN_COLUMNCLICK message?

    LVN_COLUMNCLICK is not a message, but a notification received via the WM_NOTIFY message when a column header is clicked.

    An example of use from some code is:

    Code:
    LPNMHDR tc;
    LPNMLISTVIEW pnmlv;
    DWORD subitm;
    
    // g_hwndLV is the window handle to the list view control
    
    case WM_NOTIFY:
        tc = (LPNMHDR)lParam;
    
        if ((tc->hwndFrom == g_hwndLV) && (tc->code == LVN_COLUMNCLICK)) {
            pnmlv = (LPNMLISTVIEW)lParam;
            subitm = pnmlv->iSubItem;
            // ...
        }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: How to send an LVN_COLUMNCLICK message?

    Try
    Code:
    NMLISTVIEW nmlv = {0};
    
    nmlv.nmh.code = LVN_COLUMNCLICK;    // Message type defined by control.
    nmlv.nmh.idFrom = GetDlgCtrlID(hListView);
    nmlv.nmh.hwndFrom = hListView;
     
    nmlv.iItem = -1;
    nmlv.iSubItem = 1;
     
    SendMessage(hwnd, WM_NOTIFY, nmh.idFrom,(LPARAM)&nmlv);
    Victor Nijegorodov

  4. #4
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: How to send an LVN_COLUMNCLICK message?

    Of course, how could I miss it that NMHDR hdr; was also a member of NMLISTVIEW structure.

    Ive learned something and its working, thank you very much Victor!

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: How to send an LVN_COLUMNCLICK message?

    You are welcome!
    Victor Nijegorodov

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