dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: How to Get messages for a checked Item

  1. #1
    Join Date
    May 2005
    Posts
    364

    How to Get messages for a checked Item

    Hi,

    After creating check boxes,

    I tried searching for the messages generated when the user checks the check box of an item in the list control

    But no such message is being found in the class wizard.

    I searched msdn to get :

    GetCheck function

    Is there any way of generating a call to message function, when the user selects a check box in the list control instead of ourselves keep polling for any checked item.
    Dan

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,593

    Re: How to Get messages for a checked Item

    You don't need any polling.
    What you should do is handling the LVN_ITEMCHANGED notification, then check the uChanged and uNewState members of NMLISTVIEW structure passed to the message handler.
    If uNewState contains LVIS_STATEIMAGEMASK - then checkbox state was changed - call GetCheck to know the new state!
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: How to Get messages for a checked Item

    You use BN_CLICKED and then check state with GetCheck

  4. #4
    Join Date
    May 2005
    Posts
    364

    Re: How to Get messages for a checked Item

    Quote Originally Posted by VictorN
    What you should do is handling the LVN_ITEMCHANGED notification, then check the uChanged and uNewState members of NMLISTVIEW structure passed to the message handler.
    If uNewState contains LVIS_STATEIMAGEMASK - then checkbox state was changed - call GetCheck to know the new state!
    I did the same like this code below:

    Code:
    void CTestDlg::OnItemchangedlstTest1(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    	int iRet;
    
    	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    
    	if(pNMListView->uNewState == LVIS_STATEIMAGEMASK)
    	{
    		iRet = pl->GetCheck(pNMListView->iItem);
    
    		if(iRet)
    		{
    			MessageBox("Item is selected");
    		}
    		else
    		{
    			MessageBox("Item is Not selected");
    		}
    	}
    
    	*pResult = 0;
    }
    But found after debugging that pNMListView->uNewState is not matching with LVIS_STATEIMAGEMASK.

    I am doing anything wrong!
    Dan

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

    Re: How to Get messages for a checked Item

    Quote Originally Posted by danandu
    I did the same like this code below:

    Code:
    	if(pNMListView->uNewState == LVIS_STATEIMAGEMASK)
    	{
    		....
    But found after debugging that pNMListView->uNewState is not matching with LVIS_STATEIMAGEMASK.

    I am doing anything wrong!
    Yes, unfortunately....
    The item sate (pNMListView->uNewState) is always a combination of many states lime LVIS_STATEIMAGEMASK, LVIS_SELECTED, LVIS_FOCUSED, ...
    So you must write your comparison like:
    Code:
    if(pNMListView->uNewState & LVIS_STATEIMAGEMASK)
    Victor Nijegorodov

  6. #6
    Join Date
    May 2005
    Posts
    364

    Re: How to Get messages for a checked Item

    It worked

    Thank you,

    But How did you know this..?

    How do we know that a state has to be bit Anded to another value?
    Dan

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,593

    Re: How to Get messages for a checked Item

    I read it in MSDN.
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)