CCOMBOBOX control details

xiaoxiao2021-03-05  27

Original my URL

Http://blog.9cbs.net/hsuyuan/ Welcome to discuss learning

The CCOMBOX control is also called a combination box control, which is available for selection.

Common Setting Attribute Description of the CCOMBOBOX control:

TYPE properties: There are three options inside. It is the three forms. We often use the latter two forms, which is the DropDown's editing area for editable controls, and Droplist is a static control.

DATA properties: When the program is initialized, the drop-down list will display the content in its properties, and the content is separated by a semicolon. Its attribute only supports the post-second form,

Sort properties: Automatically sort the data added to the drop-down list box, if you don't want him to change your display sequence, set him into false.

The control is a window. The base class is CWnd. So CCOMBOBOX can also use some of the CWnd's functions, and its own functions have more than 30 kinds. I wrote a demonstration program, demonstrate some common functions, you can refer to its code See its function.

Note: m_cbox is the associated variable of the CCOMBOBOX control, and the associated variable of M_end is an edit control.

1.getcount () function: Used to get the number of options in the list box. Int getCount () const; (this is the function prototype, I will list the following example below is the code in each button in each button.

INT I;

CString Str;

i = m_cbox.getcount ();

Str.Format ("% d", i);

M_END = "A total of" STR "data";

Updatedata (FALSE);

2.Getcurseel () function: Used to get the index value of the data in the drop-down list box. The return value is the beginning of the 0, if no option will return -1 int getcursel () Const

INT I;

CString Str;

i = m_cbox.getcursel ();

Str.Format ("% D", i 1);

IF (i == - 1) m_end = "You have nothing to do";

Else M_END = "You choose the" STR "item;

Updatedata (FALSE);

3.Setcurseel function: Select an option in the list box, the index starts from 0, why is all the options. When you need to empty the content you have selected in the list box;

IF (m_i <3) m_cbox.setcurseel (m_i ); // m_i is INT type variable to count

Else {

m_cbox.setcurseel (-1);

m_i = 0;

}

4.SetEteditsel function: Set the length of the blue selected field in the editing area,

Bool setEditsel (int

NStartchar,

int

Nendchar); NStartChar is the starting position, when set to -1, NEndChar is the end position. There is also a corresponding function getEditsel to achieve its location where it is not detailed.

m_cbox.seteditsel (3, 5); // Passed a string number in the edit box to see the effect in the button

// The role is to select the 3rd to 5th characters as a hot spot.

5. CTEAR () CUT () Paste () Copy () I put together, because they are all functions that edit the text selected in the edit box, many beginners don't understand these 4 Functions, use these functions, there is no effect, in fact, these functions are not processed in the edit box, and he really handles the content you use in the mouse, which is incorrect in a lot of books in the clear () function. Many books in his explanation is to clear the currently selected text. I think this explanation is that there is a discrimination. The real explanation is to release the text you just selected, which is not selected, not to delete the selected delete. The function of the true delete selected text is cut (), and copy () is a copy selected text. Paste () is pasted to the cursor. It is not written in the program, interested friends can try themselves. 6 .LimitText () function. Their role is to limit the text length typed in the edit box, Bool LimitText (Int nmaxchars); when nmaxchars is 0, not input, but the length is maximized to 65535 bytes

7.GetlbText () function. Its prototype is void getlbtext (int

NINDEX, CSTRING &

rstring) .NINDEX is the index value of the data in the list box, RString is a string, which is to put the index number NINDEX in the RString variable. Corresponding to GetlbTextlen (Int)

Nindex) function is to get the length of the data in NINDEX

m_cbox.getlbtext (2, m_end); // getlbtext button

Updatedata (0);

CString Str; // GetlbTextlen button

INT i = m_cbox.getlbtextlen (2);

Str.Format ("% d", i);

M_END = STR;

Updatedata (FALSE);

8.Addstring () deleteString () InsertString () resetContent () four functions are put together, they are the processing function for the drop-down list box, addString (LPCTSTR

lpszstring) Add a data to the tail of the list box, parameter is a string. deleteString (UINT

NINDEX) To delete the data specified index as Nindex. InsertString (INT

Nindex

LPCTSTR

Lpszstring) Inserts Ipszstring content at index NINDEX. RESETCONTENT () is all the contents in the list box.

9

.SetDroppedWidth (UINT)

NWIDTH) function. Used to set the minimum width of the drop-down list box, when the data in the drop-down list box is long unable to display, we can use this function to set the width of the list box. The same getDroppedWidth () is returned The width of the list box.

The following is a summary of the issues used in the CCOMBBOX controls in major forums. And give a positive solution.

1. Questions about the CCOMBOBOX in the dialog box without a drop-down project

A: The vertical range of the CCOMBOBOX component in the resource editor pulls down, just see the font, see the down black arrow, point him pull, 嘿嘿 It is so simple.

2. How can I let CCOMBOBOX remember the user's input. There is still a next time.

A: You need to use the INI file to record the content, see the article read and written in the INI file.

3. How CCOMBOBOX makes it read only and cannot be edited

A: I read this article. Maybe you know now, CCOMBOBOX has three types, choose what you need!

4. I want the interface to display the default data in the COMBO box.

A: You have to add the setcurseel () function I mentioned above in OnInitDialog.

5. How to assign the selected content to the variable

A: First set a CCOMBOBOX to add an event handler CBN_ SELCHANGE. Use Updatedata (false).

6. In the CCOMBOBOX combo box, the alignment of the entry is left aligned, can you set it to the middle or right?

A: There is no direct method, you must align yourself, such as the maximum length is 10INT I;

String.Format ("% 10D", i);

CCOMBOBOX-> AddString

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

New Post(0)