CStringArray 字符串数组的使用 以及调试时怎么Dump出其中的内容

CStringArray 应该说是术语MFC框架之外的一个分支,小的数组类

CStringArray arrCString;//Rows, Column;
	
	CString strTemp;
	CString str[5]={"1111","2222","3333","4444","5555"};

	for(int i=0;i<5;i++)
	{
		arrCString.Add(str[i]);
	}

	int elemCount= arrCString.GetSize();// 获得字符串数组中元素的个数;    elemCount=5
	int maxIndex=arrCString.GetUpperBound();//获得字符串数组中 最大下标;  maxIndex=4
	strTemp=arrCString.GetAt(1);// strTemp="2222"

	// this is important
#ifdef _DEBUG
	afxDump.SetDepth( 1 );
	afxDump << "Add example: " << &arrCString << "\n";
	/* Output中输出的内容*********************************
	Add example: a CStringArray at $12F61C
	with 5 elements
	[0] = 1111
	[1] = 2222
	[2] = 3333
	[3] = 4444
	[4] = 5555
	*/
#endif


要实现ComboBox按钮在下拉只显示指定字符串内容,可以通过以下步骤实现: 1. 在MFC窗口类的OnInitDialog()函数中,添加ComboBox控件,并设置ComboBox的样式为CBS_DROPDOWNLIST,这将使ComboBox只能从下拉列表中选择已定义的值。 2. 在OnInitDialog()函数中,使用AddString()函数向ComboBox中添加所有可选项的字符串。 3. 在ComboBox下拉事件OnCbnDropdown()中,遍历ComboBox中所有的项,如果该项的字符串不在指定字符串列表中,就使用DeleteString()函数删除该项。 以下是示例代码: ``` // 在窗口类的头文件中定义指定字符串数组 CStringArray m_arrStrings; // 在OnInitDialog()函数中添加ComboBox控件 CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBOBOX); pComboBox->ModifyStyle(0, CBS_DROPDOWNLIST); // 向ComboBox中添加所有可选项的字符串 pComboBox->AddString(_T("Option 1")); pComboBox->AddString(_T("Option 2")); pComboBox->AddString(_T("Option 3")); // 在ComboBox下拉事件OnCbnDropdown()中过滤不需要的项 void CMyDialog::OnCbnDropdownCombo() { CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBOBOX); int nCount = pComboBox->GetCount(); for (int i = nCount - 1; i >= 0; i--) { CString strText; pComboBox->GetLBText(i, strText); if (m_arrStrings.Find(strText) == -1) { pComboBox->DeleteString(i); } } } ``` 在上述示例代码中,OnCbnDropdownCombo()函数中的m_arrStrings是指定的字符串数组。在ComboBox下拉事件中,遍历ComboBox中的所有项,如果该项的字符串不在指定字符串列表中,就使用DeleteString()函数删除该项。这样ComboBox就只会显示指定字符串列表中的内容
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值