On_policy processes listControl messages
The message ing of the list control also uses the ON_NOTIFY macro in the form of ON_NOTIFY (wyycode, id, memberFxn). wNotifyCode is the notification code and id is the window ID that generates the message, memberFxn is a processing function. The prototype of the function is like void OnXXXList (NMHDR * pNMHDR, LRESULT * pResult). pNMHDR is a data structure and needs to be converted to other types of structures during use. The values of the list control and the corresponding data structure are as follows:
· LVN _ BEGINLABELEDIT is sent when a character is edited. The structure used is NMLVDISPINFO.
· LVN _ ENDLABELEDIT is sent when an edit character is completed. The structure used is NMLVDISPINFO.
· LVN _ GETDISPINFO is sent when you need to obtain certain information (for example, to obtain the display characters of a certain item). The structure used is NMLVDISPINFO.
================ Repost the above theory, the application example is as follows ========================
Example: Double-click list item to rename an item
// In_message_map (CPage, CDialog) ON_NOTIFY (NM_DBLCLK, IDC_LIST, & CPage: Success) ON_NOTIFY (success, IDC_LIST, & CPage :: onLvnEndlabeleditList) END_MESSAGE_MAP () implements void CPage: OnNMDblclkList (NMHDR * pNMHDR, LRESULT * pResult) {// double-click the event to generate the edit Control, editLabel first determines whether the list is setFocus * pResult = 0; POSITION Pos = counter (); int tIndex = m_List_Tip.GetNextSelectedItem (pos); if (tIndex> = 0) {m_List_Tip.SetFocus (); CEdit * pEdit = m_List_Tip.EditLabel (tIndex );}} invalid void CTipTrapPage: OnLvnEndlabeleditListTip (NMHDR * pNMHDR, LRESULT * pResult) {// edit the end event parameter NMHDR * pNMHDR forcibly converted to the corresponding structure NMLVDISPINFO // you can get the current list NMLVDISPINFO * pDispInfo = reinterpret_cast <NMLVDISPINFO *> (pNMHDR); * pResult = 0; CString pName = pDispInfo-> item. pszText; int tIndex = pDispInfo-> item. iItem; m_List.SetFocus (); if ((! PName. IsEmpty () & tIndex> = 0) {m_List.SetItemText (tIndex, 0, pName );}}
Finally, do not forget to hook up the property: list Control-> property-> Styles-> Edit labels;