相关部分代码如下:// If the user hit <ENTER>
if (nChar == 13)
{
// Figure out what line we're on
CEdit& ed = GetEditCtrl();
int iStart=0, iEnd=0;
ed.GetSel(iStart, iEnd);
int iLine = ed.LineFromChar(iStart);
if (iLine > -1)
{
static char szLine[256];
memset(szLine, 0, sizeof(szLine));
// Get the whole line
int iNdx = ed.GetLine(iLine, szLine, sizeof(szLine)-1);
if (iNdx > 0)
{
// and Send() it out our socket
strcat(szLine, "\r\n");
m_pSocket->Send(szLine, strlen(szLine));
}
}
}我看了一下szLine的长度是7,后面两个字符的值是16、76,请问是什么原因呢?
if (nChar == 13)
{
// Figure out what line we're on
CEdit& ed = GetEditCtrl();
int iStart=0, iEnd=0;
ed.GetSel(iStart, iEnd);
int iLine = ed.LineFromChar(iStart);
if (iLine > -1)
{
static char szLine[256];
memset(szLine, 0, sizeof(szLine));
// Get the whole line
int iNdx = ed.GetLine(iLine, szLine, sizeof(szLine)-1);
if (iNdx > 0)
{
// and Send() it out our socket
strcat(szLine, "\r\n");
m_pSocket->Send(szLine, strlen(szLine));
}
}
}我看了一下szLine的长度是7,后面两个字符的值是16、76,请问是什么原因呢?
另外我看了一下iLine的值是3
{
if ( VK_RETURN == pMsg->wParam )
{
// Figure out what line we're on
//CEdit& ed = GetEditCtrl();
int iStart=0, iEnd=0;
m_edit1.GetSel(iStart, iEnd);
int iLine = m_edit1.LineFromChar(iStart);
if (iLine > -1)
{
char szLine[256];
memset(szLine, 0, sizeof(szLine));
// Get the whole line
int iNdx = m_edit1.GetLine(iLine, szLine, sizeof(szLine)-1);
if (iNdx > 0)
{
// and Send() it out our socket
strcat(szLine, "\r\n");
//m_pSocket->Send(szLine, strlen(szLine));
}
}
}
}我做了个模拟程序,取出某行没问题。
晕,真的是跟static有关呢,去掉就可以啦,谢谢啦