MFC controls using--list control

Source: Internet
Author: User

"Previous Words"

The first experiment of compiling principle--the lexical analyzer acceptance, the teacher asked for the final results in the form of GUI expression. To be sure, the black-and-white console application interface is not as GUI-friendly as the user does. GUI interface is also a trend. I am now mastering the basic syntax of three languages--c/c++, Java, and Python. Python has learned a long time ago and then forget, recently wanted to write web crawler to see again, for Python writing GUI is not a good thing, do not consider. Since the Java write GUI is more convenient, but the experimental code has been written in C, so the final decision to use MFC to do this GUI.

to the sophomore Xia Lu continued to do a number of MFC, each time with a new control is on- line various search and then XJBG to complete. Every time you want to use the time to find, so that every learning a control to write an essay systematically record how to use and experience.

Nonsense not to say, the use of the list control below.

"List Control"

In the console can be used #include<iomanip> SETW () to set the format of the output, originally thought that the MFC controls in the edit control also output a bit, the result is to make the effect is this:

It seems that using the SETW () method does not get the desired effect, and the text in the edit control can be changed arbitrarily, so I want to find a control like the list to display as output.

Finally get this effect, it is necessary to use today to introduce the list control.

The display after dragging to the dialog box is this:

With the control selected, modify the view item in the skin from icon to report, then resize.

Then right-click the Class Wizard, member variables, set such as:

The column properties of the list are then initialized and set in the OnInitDialog () function of the CProjectNameDlg.cpp file:

        DWORD dwstyle = m_list. GetExtendedStyle ();             | = lvs_ex_fullrowselect;        | = Lvs_ex_gridlines;        M_list. SetExtendedStyle (dwstyle);

The first sentence gets m_list style.

Lvs_ex_fullrowselect is selected for the entire row, and the entire row is selected when the mouse clicks a cell.

Lvs_ex_gridlines to add a grid line.

The forth sentence adds our configured style to the m_list.

Next, set the properties for each column:

M_list. InsertColumn (0, _t (" "), Lvcfmt_left, -); M_list. InsertColumn (1, _t ("Word"), Lvcfmt_left, -); M_list. InsertColumn (2, _t ("Two-dollar sequence"), Lvcfmt_left, the); M_list. InsertColumn (3, _t ("type"), Lvcfmt_left, the); M_list. InsertColumn (4, _t ("position (row, column)"), Lvcfmt_left, -);

I follow my own understanding of the use of the function. InsertColumn (the column that is set is the number of columns, the property name of the column, the format of the property name, and the column width).
Then it is displayed in the list control after a control is triggered. This can be triggered by pressing a button or reading into a file Balabala ...

        m_list. InsertItem (n, CStr1);         1 , CSTR2);         2 , CSTR3);         3 , CSTR4);         4

InsertItem (n, CStr) is adding CStr to the No. 0 column of nth row. Here n is also counted starting from 0.
Setitemtext (n, line, CSTR) is the addition of CStr in row N. But if you join the No. 0 column with Setitemtext, the element is not effective.

My understanding is to use InsertItem () to apply for a row of the list is available, the latter can be used Setitemtext () to join.

Two functions insert the element in list must be of type CString. I usually turn everything into a string and use CString CStr (String.c_str ()) to solve it ...

Then Cy told me a very useful thing: StringStream. Later with more than also write an essay summary under the good.

Finally, the list control clears the method: M_list. Deleteallitems ().

MFC controls using--list control

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.