刚开始在vc6里用多文档编写一个类似cterm的登陆UNIX下BBS的程序,采用casyncsocket。现在已经能用socket连接上bbs服务器并接收数据,但是发现一个问题,用下面的代码接收数据时,在pview的视图里只能显示一行登陆画面,把视图窗口拉大些,一行就显示多一些,缩小些,一行就显示少一些,不会自动换行。不知何解。
void CMySocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
static int i=0; i++; TCHAR buff[10000];
int nRead;
nRead = Receive(buff, 10000);
switch (nRead)
{
case 0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
break;
default:
buff[nRead] = 0; //terminate the string
CString szTemp(buff);
szTemp.Replace("\n","\n\r");
m_strRecv += szTemp;
// MessageBox(NULL,m_strRecv,NULL,NULL);
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = pFrame->MDIGetActive(); CMytermView *pView = (CMytermView *) pChild->GetActiveView();
pView->Invalidate();
}
CAsyncSocket::OnReceive(nErrorCode);
}
但如果改用messagebox,则登陆画面会分成多个消息框弹出。
另外,没有用过带外数据。请教写这样的程序是否需要用到带外数据也就是FS_OOB?谢谢。
void CMySocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
static int i=0; i++; TCHAR buff[10000];
int nRead;
nRead = Receive(buff, 10000);
switch (nRead)
{
case 0:
Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Error occurred");
Close();
}
break;
default:
buff[nRead] = 0; //terminate the string
CString szTemp(buff);
szTemp.Replace("\n","\n\r");
m_strRecv += szTemp;
// MessageBox(NULL,m_strRecv,NULL,NULL);
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = pFrame->MDIGetActive(); CMytermView *pView = (CMytermView *) pChild->GetActiveView();
pView->Invalidate();
}
CAsyncSocket::OnReceive(nErrorCode);
}
但如果改用messagebox,则登陆画面会分成多个消息框弹出。
另外,没有用过带外数据。请教写这样的程序是否需要用到带外数据也就是FS_OOB?谢谢。
解决方案 »
- installshield12 卸载 重启问题
- VC6左侧选项卡窗口如何实现
- 有关CListCtrl控件问题
- 关于设置时间间隔
- 如何去掉FormView右下角的调整大小三角形符号?
- 怎么样让一个ActiveX返回个字符串给JS?控件是用ATL开发的
- 关于键盘钩子,功能基本实现,最后只差一点点请高手再指点一下
- 请问,如何实现一个Smtp服务器。
- 还是关于昨天的问题,既结构的内存实际分配与预计的内存分配不符的问题。非常感谢
- 在按照网上弄个NPAPI插件的时候发现出现了如下问题,为什么SDK标准头文件会出现这些问题!
- 严重菜的问题:点击按钮打开一文件或者执行一文件,竟然搞不出来!!
- 桌面上图像显示与消去
应该是 szTemp.Replace("\n","\r\n"); 2. 分多次显示很正常,TCP协议就是分次发给你。这种程序也不适合MessageBox,程序老被MessageBox打断还了得?3. OOB不是必须得
2.用messagebox是因为我听人说unix和windows的控制符不同,我为了试验windows能否自动识别这种不同而用messagebox做实验。结果我发现mssagebox能接收到大部分登陆画面数据而pview只能显示一行。以下是view相关代码,不知道是不是代码的问题:
void CMytermView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
CClientDC dc(this);
dc.TextOut(0,0,theApp.sock.m_strRecv);
}
谢谢