1. How to add images in the dialog box
To use the picture Control in MFC, follow these steps:
Add a bitmap file to resource management;
In the dialog box, add a picture Control and set the type attribute of the control to bitmap;
Then, select the added bitmap resource ID in the image attribute.
2. How to display a table in the dialog box
Implement Excel-like tables for Data Display
To use the list control, follow these steps:
Add a list control Control in the dialog box and set its attribute view to report );
Add a list control object to the original file and associate it with the List Control in the dialog box;
Add a list to the space that calls the function insertcolumn;
Set the style of the list;
The original code is as follows:
In the header file: clistctrl m_listctrl;
In the source file: ddx_control (PDX, idc_list_data, m_listctrl );
Crect mrect;
M_listctrl.getwindowrect (& mrect); // obtain the rectangular area of the control.
Int Kuan = mrect. Width ();
M_listctrl.insertcolumn (0, _ T ("Serial Number"), lvcfmt_left, Kuan/7,-1 );
M_listctrl.insertcolumn (1, _ T ("name"), lvcfmt_center, Kuan/7,-1 );
M_listctrl.insertcolumn (2, _ T ("Age"), lvcfmt_center, Kuan/7,-1 );
M_listctrl.insertcolumn (3, _ T ("class"), lvcfmt_center, Kuan/7,-1 );
M_listctrl.insertcolumn (4, _ T ("student ID"), lvcfmt_center, Kuan/7,-1 );
M_listctrl.insertcolumn (5, _ T (""), lvcfmt_center, Kuan/7,-1 );
M_listctrl.insertcolumn (6, _ T ("gender"), lvcfmt_center, Kuan/7,-1 );
DWORD dwstyle = m_listctrl.getextendedstyle (); // get the current extended Style
Dwstyle | = lvs_ex_fullrowselect; // select an exercise to highlight the entire line (Report Style)
Dwstyle | = lvs_ex_gridlines; // gridline (Report Style)
Dwstyle | = lvs_ex_checkboxes; // the checkbox control is generated before the item.
M_listctrl.setextendedstyle (dwstyle); // you can specify the extended style.
3. How to set and obtain the current item of the ComboBox control
Set the current ComboBox item: ccombobox: setcursel (INT) to the selected item sequence number. The item sequence number starts from 0.
Obtain the number of the current item: ccombobox: getcursel (). The returned value is the number of the current item, int type.
Obtain the text of the current item: ccombobox: getlbtext (nselect, STR). The first parameter is the serial number of the current item, and the second parameter is the text of the corresponding item.
4. How to set the text on the static text Control
Getdlgitem (idc_static_state1)-> setwindowtext (_ T ("set successfully") the parameter in the getdlgitem function is the Control ID.
5. How to write data to the listctrl Control
First, set the view attribute of the listctrl control to report (Report form)
Note: The data in listctrl is string type, so the type conversion problem must be involved when displaying numbers.
Convert int type to cstring type method: cstring: Format (_ T ("% d"), int I) convert int type variable I to a decimal string
In addition, the two cstrings can be directly added to meet the data display requirements in the list, such as _ T ("0") + _ T ("1 ") we get _ T ("01 ")
M_listctrl.insertitem (INT nitem, stritem); // insert data in the first column of the row nitem. The data is stritem, And the return value is the next row nitem + 1.
M_listctrl.setitemtext (INT nitem, 1, data1); // set data in a column of a row. Here, the data is in the 2nd column of the int nitem row (the first sentence of the first column has been written) write Data data1
M_listctrl.setitemtext (INT nitem, 2, data2); // write data to data1 in Column 2nd of the nrow row (the first few sentences have been written)
6. How to wrap the font on the button
When the word on the button is too long, a line break is required. The implementation is as follows:
Set the multiline attribute of the button to true.
Add \ n before the text to be wrapped. For example, "Shenma button" is written as "Shenma \ n button"
7. delete data in listctrl
Delete all: clistctrl: deleteallitems ()
8. Obtain a data in the listctrl list.
Obtain the data in the nsubitem column of the nitem row: clistctrl: getitemtext (INT nitem, int nsubitem). The returned value is of the cstring type.
9. The listctrl scroll wheel is automatically displayed to the last row of the list.
Clistctrl: ensurevisible (INT nitem, false );
That is, the last row of the row with the serial number nitem in the visible area.