Implement one-choice checkbox in clistctrl

Source: Internet
Author: User
ArticleDirectory
    • Ajay Kalra posted on Wednesday, January 14,200 9 AM
    • Asoni1 posted on Tuesday, January 13,200 9 pm
    • Ian Semmel posted on Tuesday, January 13,200
    • Tom serface posted on Tuesday, January 13,200 9
    • Asoni1 posted on Wednesday, January 14,200 9 AM
    • Sanoop das K posted on Saturday, February 28,200 9 pm

Http://www.eggheadcafe.com/software/aspnet/33811658/detect-changes-in-clistctrl-control-with-checkbox.aspx

detect changes in clistctrl control with checkboxajay Kalra posted on Wednesday, January 14,200 9 AM
 On Jan 13, 11: 31 = a0am, asoni12 
         
           Take A Look At listview_getcheckstate: http://msdn.microsoft.com/en-us/lib=rary/bb761250 (vs.85 ). aspxand lvn_itemchanging: http://msdn.microsoft.com/en-us/library/bb774847 (. = 85 ). aspx -- Ajay 
         

reply

detect changes in clistctrl control with checkboxasoni1 posted on Tuesday, January 13,200 9
 Hi Ajay, thanks for the quick reply. we get a pointer to an nmlistview structure in case of both errors and lvn_itemchanged Event Handlers but with this structurehow can we make sure whether items â € S checked/unchecked state has beentoggled or something else has changed? I mean is there any bit in this structure member which is set/unset when thestate gets toggled? 

reply

In the lvn_itemchanged handler you can putint NS = pnmlistview-> unewstate & Ian Semmel posted on Tuesday, January 13,200
In the lvn_itemchanged handler you can putint NS = pnmlistview-> unewstate & lvis_stateimagemask; If (NS & 0x2000 )! = 0) // checkbox setelse if (NS & 0x1000 )! = 0) // checkbox unsetelse // something else happened

Reply

Detect changes in clistctrl control with checkboxtom serface posted on Tuesday, January 13,200 9
On_policy (nm_click, idc_list, & cspanrestoredlg: onnmclicklist) // check or uncheck item. if more than one item is selected then use theone from the // hit test to determine how we are setting the others (I. E ., if it is offwe turn the other // selected ones on ). void cmydlg: onnmclicklist (nmhdr * pnmhdr, lresult * presult) {nmlistview * pnmlistview = (nm_listview *) pnmhdr; lvhittestinfo hitinfo; * presult = 0; B OOl bchecked = false; // copy click pointhitinfo.pt = pnmlistview-> ptaction; // make the hit test...int nitem = m_clist.hittest (& hitinfo); If (hitinfo. Flags! = Lvht_onitemstateicon) return; // didn't click on an iconif (m_clist.getitemstate (nitem, lvis_selected )! = Lvis_selected) {// They clicked on one that is not selected... just change it //... do something herebchecked = m_clist.getcheck (nitem); bchecked =! Bchecked; m_clist.setcheck (nitem, bchecked); * presult = 1; return;} // get the checked state from the one they clicked on, but change allthe ones that are selecteduint uselectedcount = m_clist.getselectedcount (); // update all of the selected items. if (uselectedcount> 0) {nitem =-1; m_clist.setredraw (false); For (uint I = 0; I <uselectedcount; I ++) {nitem = m_clist.getnextitem (nitem, lvni_selected); m_clist.setcheck (nitem, bchecked);} * presult = 1; m_clist.invalidate (); m_clist.setredraw ();} Tom

Reply

Thanks Ian. asoni1 posted on Wednesday, January 14,200 9 AM
Thanks Ian. I did it this way and it works fine for me-I just wanted to confirm, since I am using constant 0x2000 and 0x1000 here, can I be sure that these checks will not be bricked in some other environmentlike other version of Windows OS or Visual Studio? Int oldstate =-1; int newstate =-1; int changedstate =-1; int NS1 = pnmlv-> uoldstate & lvis_stateimagemask; int int32 = pnmlv-> unewstate & lvis_stateimagemask; if (NS1 & 0x2000 )! = 0) // find the previous state {// checkbox setoldstate = 1;} else if (NS1 & 0x1000 )! = 0) {// checkbox unsetoldstate = 0;} If (-1! = Oldstate) // If got the previous state then find the new State {If (NS2. 0x2000 )! = 0) {// checkbox setnewstate = 1;} else if (NS2. 0x1000 )! = 0) {// checkbox unsetnewstate = 0;} If (-1! = Newstate) & (oldstate! = Newstate) {changedstate = newstate-oldstate; if (1 = changedstate) {afxmessagebox (_ T ("item has been checked "));} else if (-1 = changedstate) {afxmessagebox (_ T ("item has been unchecked "));}}}

Reply

Detect changes in clistctrl control with checkboxsanoop das K posted on Saturday, February 28,200 9 pm
Http://msdn.microsoft.com/en-us/library/bb761250.aspx===========================

Through the classwizard attribute page or wizardbar, classwizard can create an on_notify message ing entity and provide a processing function body. For more information about classwizard, seeMapping messages to functions of Visual C ++ programmer's guide.

On_notify message ing macro format:

On_policy (wnotifycode, ID, memberfxn)

Wnotifycode

TheCode, Such as lvn_keydown.

ID

ID of the control that sends the reminder message

Memberfxn

Reminder Message Processing Function

The prototype of the processing function is as follows:

Afx_msg void memberfxn (nmhdr * pnotifystruct, lresult * result );

Pnotifystruct

Parameter struct described above

Result

Return code that should be set before function return

Example

To enable the onkeydownlist1 function to process the lvn_keydown message sent by clistctrl whose ID is idc_list1, you can use classwizard to add the following code to the Message ing:

On_policy (lvn_keydown, idc_list1, onkeydownlist1)

The function body provided by classwizard is:

Void cmessagereflectiondlg: onkeydownlist1 (nmhdr * pnmhdr, lresult * presult)

{

Lv_keydown * plvkeydow = (lv_keydown *) pnmhdr;

// Todo: add your control notification Handler

// Code here

* Presult = 0;

}

Note: classwizard automatically provides parameter pointers. You can directly use pnmhdr or plvkeydow to access the reminder struct.

On_policy_range
To process the same wm_notify message for a group of controls, you can use on_policy_range instead of on_policy. For example, a group of buttons can perform the same operation for a notification message.

When on_policy_range is used, you must specify a group of consecutive control IDs to specify the start ID and end ID of the control group.

Classwizard does not process on_policy_range. to use it, you need to manually add message ing.

The message ing entity and function of on_policy_range are as follows:

On_policy_range (wnotifycode, ID, idlast, memberfxn)

Wnotifycode

The code of the reminder message to be processed, such as lvn_keydown.

ID

Start ID of the control group

Idlast

End ID of the control group

Memberfxn

Reminder Message Processing Function

The prototype of the processing function is as follows:

Afx_msg void memberfxn (nmhdr * pnotifystruct, lresult * result );

Pnotifystruct

Parameter struct described above

Result

Return code that should be set before function return

On_policy_ex, on_policy_ex_range
If you want to process reminder messages by multiple objects, you can use on_policy_ex (or on_policy_ex_range) instead of on_policy (or on_policy_range ). The difference between the ex version and the conventional version is that the ex version of the processing function has a bool type return value to determine whether the message processing should continue. If false is returned, the message can be processed by multiple objects.

Classwizard does not process on_policy_ex or on_policy_ex_range. to use them, you need to manually add message ing.

The message ing entity and function prototype of on_policy_ex and on_policy_ex_range are issued. The parameter meanings are consistent with those of the general version:

On_policy_ex (ncode, ID, memberfxn)

On_policy_ex_range (wnotifycode, ID, idlast, memberfxn)

Both functions are prototype:

Afx_msg bool memberfxn (uint ID, nmhdr * pnotifystruct, lresult * result );

Id indicates the ID of the control that sends the reminder.

If the reminder message has been processed, the function should return true; otherwise, if further processing is required, the function returns false.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wsxz_wsxz/archive/2010/02/27/5332412.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.