关于CComboBox的InsertString成员函数的一个问题

xychzq 2009-06-21 10:15:17
while ( lp->h_addr_list[i] != NULL )
{
IP = *(DWORD*)lp->h_addr_list[i++];
struct in_addr A = {0};
A.S_un.S_addr = IP;
char *p = inet_ntoa(A);
m_LocalIPList.InsertString(0,p);
}

代码如上,想要实现的功能是把几个ip地址加到CComboBox控件里面去,但只能实现写进去一行,其它几个ip无法写进去,希望大家帮忙看一下。
...全文
377 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2011-04-21
  • 打赏
  • 举报
回复
有什么错误呢?你的CComboBox是自绘的吗?
wbjiang2004 2011-04-21
  • 打赏
  • 举报
回复
CComboBox::InsertString
int InsertString( int nIndex, LPCTSTR lpszString );

返回值

The zero-based index of the position at which the string was inserted. The return value is CB_ERR if an error occurs. The return value is CB_ERRSPACE if insufficient space is available to store the new string.

返回插入项的下标。出错时返回CD_ERR。如果没有足够的内存插入项,则返回CB_ERRSPACE。

参数说明

nIndex

Contains the zero-based index to the position in the list box that will receive the string. If this parameter is ?, the string is added to the end of the list.

指定项的插入位置(下标),如果为―1,则在列表的末尾插入该项。

lpszString

Points to the null-terminated string that is to be inserted.

指向待插入的字符串(以null结尾)。
wbjiang2004 2011-04-21
  • 打赏
  • 举报
回复
同意楼上的说法,第一个参数应该是插入的位置
pcgg5244 2011-04-21
  • 打赏
  • 举报
回复
m_LocalIPList.InsertString(i,p);

第一个参数不是应该不同么?
xinxipan 2011-04-21
  • 打赏
  • 举报
回复
我也碰到这个问题,求解………………………………
xinxipan 2011-04-21
  • 打赏
  • 举报
回复
这到底是为什么?
xychzq 2009-06-22
  • 打赏
  • 举报
回复
每次执行的时候p都有值,不是为空啊!但还是出现上面的问题。
贪玩的老鼠 2009-06-22
  • 打赏
  • 举报
回复
m_LocalIPList.InsertString(0,p);
是完全可以的,你调试进去,看看m_LocalIPList.InsertString(0,p)(这样做只是把新的记录加入到最前面而已);
执行了几次每次(P)的结果是不是都有值.
问题不在于LIST,而在于你的循环执行了几次,是不是有的IP不正确导致*P=""
xychzq 2009-06-21
  • 打赏
  • 举报
回复
也不行啊,老大
skyxie 2009-06-21
  • 打赏
  • 举报
回复
m_LocalIPList.InsertString(-1,p);

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧