list view doesn't receive LBN_SELCHANGE messages

This is a discussion on list view doesn't receive LBN_SELCHANGE messages within the Windows Programming forums, part of the Platform Specific Boards category; Hi all. My list view is a child window of my main window created with the following Code: hListView = ...

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    list view doesn't receive LBN_SELCHANGE messages

    Hi all.

    My list view is a child window of my main window created with the following
    Code:
    hListView = CreateWindowEx(0,
                       WC_LISTVIEW,
                       NULL,
                       WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |
                       LBS_NOTIFY | LVS_SORTASCENDING | LBS_NOREDRAW,
                       0, 0, 0, 0,
                       hwnd,
                       (HMENU) IDC_SERVLIST,
                       hInstance,
                       NULL);
    when an item is selected, I'm not recieving any messages from my list box.
    I thought that having the LBS_NOTIFY flag directed all list view messages to the parent window.

    I do however receive WM_NOTIFY messages when an item is double clicked.

    Any ideas what is going wrong? I'm use windows not dialogs.

    For reference, here is my main window creation code
    Code:
    hMainWnd = CreateWindowEx(
    	    0,
    	    ClassName,
    	    _T("Test List View"),
    	    WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
    	    CW_USEDEFAULT, CW_USEDEFAULT, 650, 450,
    	    NULL, NULL, hInstance, NULL);
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    LBN_SELCHANGE is received through the WM_COMMAND message. Does your code look something like this:
    Code:
    case WM_COMMAND:
    {
        if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_SERVLIST)
        {
              // do something...
        }
    }

  3. #3
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    yes. Here is my code :

    Code:
    case WM_COMMAND:
    
        switch(LOWORD(wParam))
        {
            case IDC_SERVLIST:
                switch (HIWORD(wParam))
                {
                    case LBN_SELCHANGE:
                        MessageBox(NULL, _T("sel changed"), _T("note"), MB_ICONEXCLAMATION | MB_OK);
                }
            break;
    ...
    Putting a break point on WM_COMMAND doesn't fire up the debugger when changing seletion in the list view. WM_COMMAND messages do not seem to be getting to the parent window, or are not being generated by the list view.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Do list view controls generate LBN_* notifications? (And for that matter, do List View's accept LBS_* styles?) I'm unsing Spy++ on one of my apps with a list view (which I granted the LBS_NOTIFY style for testing), and it's not sending any WM_COMMANDs either. It is sending WM_NOTIFY's though, with some with LVN_ITEMCHANGED.

    The LVN_ITEMCHANGED notification gives a NM_LISTVIEW structure, detailing the change. I get a bunch of them too... I assume one saying that the item isn't selected for the old selection, and one saying that the new selection is selected. The state member of the LV_ITEM structure contains info on whether or not that item is selected.
    At any rate, LVN_ITEMCHANGED should tell you, with the NM_LISTVIEW.uChanged member being LVIS_SELECTED (hopefully...), but you might get two of these. (One when the original selection is deselected, etc. Might not matter.) Perhaps this is what you want...

    Edit: My app also needs to check selection state as it turns out, so I tried my above method, no go. I get LVN_ITEMCHANGED notifications ok, but the uChanged member makes no sense... it's set to 8, which is LVIS_DROPHILITE, when I select things. (Hell, my ListView doesn't even let me drag & drop stuff...)
    Last edited by Cactus_Hugger; 01-16-2006 at 03:43 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Do list view controls generate LBN_* notifications?
    Nice catch Cactus_Hugger! LBN_ notifications are obviously for list boxes.
    My app also needs to check selection state as it turns out, so I tried my above method, no go. I get LVN_ITEMCHANGED notifications ok, but the uChanged member makes no sense... it's set to 8, which is LVIS_DROPHILITE, when I select things. (Hell, my ListView doesn't even let me drag & drop stuff...)
    The uChanged member contains a mask of which members of the LVITEM structure for the item have changed. 0x0008 is LVIF_STATE, meaning that LVITEM.state has changed. When uChanged includes LVIF_STATE, you can look at uNewState and uOldState to check whether the selection has changed. A selected item will have the LVIS_SELECTED bit set.

    Something like this:
    Code:
    case WM_NOTIFY:
    {
    	NMHDR* nm = (NMHDR*) lParam;
    
    	if ( nm->idFrom == IDC_MYLISTVIEW &&
    	     nm->code == LVN_ITEMCHANGED )
    	{
    		LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
    
    		if ( (pnmv->uChanged & LVIF_STATE) &&
    		     (pnmv->uNewState & LVIS_SELECTED) != (pnmv->uOldState & LVIS_SELECTED) )
    		{
    			// pnmv->iItem has been selected or deselected.
    
    			if (pnmv->uNewState & LVIS_SELECTED)
    				PRINT("Item number %d has been selected\n", pnmv->iItem);
    			else
    				PRINT("Item number %d has been deselected\n", pnmv->iItem);
    		}
    	}
    }

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Ah, you're exactly right! I entirely misread the help on uChanged. I was expecting it to have the same flags as the state member (LVIS_*), when it says (in bold, admittidly...) same flags as the mask member... (LVIF_*). Problem solved for me, hopefully for eth0 too.

    Thanks for that info! (Hope I didn't hijack your thread eth0... ;-) )
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #7
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Quote Originally Posted by Cactus_Hugger
    (Hope I didn't hijack your thread eth0... ;-) )
    Nope, I got my answer and learned something else too.
    Thanks guys
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 11:30 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 09:16 AM
  4. List View problem
    By pinkcheese in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2003, 01:09 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21