1. Add
Int
Combobox_addstring (
Hwnd hwndctl, // window handle
Lpctstr lpsz // content to be added
);
The difference between the two lies in the second parameter: one can add content to the specified position, and the other cannot.
2. Determine the index of the current option:
Int combobox_getcursel (
Hwnd hwndctl // the unique parameter is the control handle, and the return value is the index number of the string displayed on the handle ';
);
The return value of cur: currentsel: selection is the number of the current item, starting from 0.
What we get is not a string like "Beijing", but an index (number). If no project is selected, the iindex value returned from the function is cb_err. Make an example
3. delete items:
Int combobox_deletestring (
Hwnd hwndctl, // control handle,
Int index // the index number you want to delete (a bit like the number of braces in the array, also starting from scratch ),
);
The return value is the number of strings left after deletion;
4. Obtain the value of an item.
Int getlbtext (
Int nindex, // contains the index of the string starting from scratch in the list box to be copied.
Lptstr lpsztext // point to the buffer that receives the string. The buffer must have enough space for this string and a null character to terminate.
) Const;
Void getlbtext (
Int nindex,
Cstring & rstring // rstring pairCstring.
) Const;
Return Value: a string of length (in bytes), excluding the end null character. If nindex does not specify a valid index, the returned value isCb_err.
Note: The second form of the member function contains the text of the Project loaded by
CstringObject.
Example:
Cstring str1, str2;
Int N;
For (INT I = 0; I <m_pcombobox-> getcount (); I ++)
{
N = m_pcombobox-> getlbtextlen (I );
M_pcombobox-> getlbtext (I, str1.getbuffer (n ));
Str1.releasebuffer ();
Str2.format (_ T ("item % d: % s \ r \ n"), I, str1.getbuffer (0 ));
Afxdump (str2 );
}