MFC dynamically created control message processing

zhaozj2021-02-16  58

MFC dynamically created control message processing

A few days ago, someone asked how to respond to the news after dynamically create Treectrl, so I wrote my own experience. Now I will finish it.

This example is dynamically created in the View in View and responds to its NM_Click message, first write the code that is dynamically created:

A new SDI project, add a member to view variable: CListCtrl m_list; it was created in the OnCreate view of: if (m_list.Create (WS_BORDER | WS_CHILD | WS_VISIBLE | LVS_ICON | LVS_AUTOARRANGE | LVS_SHOWSELALWAYS | LVS_EDITLABELS, CRect (10,10,310,210! ), this, id_listctrl) {trace0 ("failed to create listctrl window / n"); return -1;} // Add some item CString Str; for (int i = 0; i <10; i ) {STR. Format ("item% d", i); m_list.insertitem (i, str);} The id_listctrl is the ID of this control, of course you can use the value directly, but for the program clearing or defining a constant In the dialog box pop-up in the main menu view-> Resource Symbols, click the New button below Name, enter ID_ListCtrl.

After the creation, you can run after the compile link, but how do you click it without reacting, of course, because we have not written the message processing code. The usual practice is to manually write message processing functions and message mappings, at least three steps: 1. Define the prototype of the message processing function in the header file, 2, implement this function in the CPP, 3, write between begin_MESSAGE_MAP and End_MAP () The message mapping. If it is a single hand, then you can endure, the message is not only troublesome. So I take the following method: 1. Open the About dialog resource, put it in a listCtrl control to the dialog box, and set its ID to ID_ListCtrl. 2.ctrl w, change the Class Name from the original Caboutdlg to cxxxView, Select ID_ListCtrl in the Object IDs on the left, then the corresponding notification message will appear on the right. At this time, you can double-click the added message to map. Hey, is it easy to follow the message in the dialog box? One thing to pay attention to, only the id_listctrl will appear in the Class Wizard when the Ctrl W is turned on when you open the control, and if you have released the ListCtrl control on the dialog.

转载请注明原文地址:https://www.9cbs.com/read-24236.html

New Post(0)