CComBox关于 SelectString使用误区
int SelectString(int nStartAfter,LPCTSTR lpszString);
这个nStarAafter=-1,表示整个列表
但是这个是字符串包含关系,模糊匹配
如果,CComBox中的字符串顺序是
【新楼层2】
【新楼层】
【主楼层】
如果当前已经是hi选择了【新楼层】,再次用SelectString(1, L"新楼层"); 是选择不到新楼层的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | void CMFCApplication3Dlg::OnCbnSelchangeCombo2() { int isel = m_combo.GetCurSel(); if (isel < 0) { return ; } CString strText = _T( "" ); m_combo.GetLBText(isel, strText); strText.Trim(); m_combo.ResetContent(); int idx=0; m_combo.InsertString(idx++, L "新建层2" ); m_combo.InsertString(idx++, L "新建层" ); m_combo.InsertString(idx++, L "主楼层" ); m_combo.SelectString(-1, strText); //是模糊匹配,这句话是错误的,需要for循环查找对应字符串 } |
name每次点选择【新楼层】的时候,会从0开始查找,查到【新楼层2】的时候,不再查找 【新楼层】
所以如果CComBox中有字符串重合部分的,不要用这个函数
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现