CSocket如何调用onReceive函数?
我在看一个编写EMAIL发送邮件例程 其中继承了一个类CESocket 重载了onReceive函数来接受发送与SMTP服务器对答的信息 可是我在程序中没有看到调用这个函数的语句啊 谁能帮我看看
// ESocket.cpp : implementation file
//
#include "stdafx.h"
#include "SendEMail.h"
#include "ESocket.h"
#include "SendEMailDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CESocket
CESocket::CESocket()
{
}
CESocket::~CESocket()
{
}
/////////////////////////////////////////////////////////////////////////////
// CESocket member functions
void CESocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
m_dlg->ReceiveMessage(m_iCount);
m_iCount++;
CSocket::OnReceive(nErrorCode);
}
void CESocket::Init(CSendEMailDlg *dlg)
{
m_dlg=dlg;
m_iCount=0;
}
// SendEMailDlg.cpp : implementation file
#include "stdafx.h"
#include "SendEMail.h"
#include "SendEMailDlg.h"
#include "MessBox.h"
void CSendEMailDlg::OnSend()
{
// TODO: Add your control notification handler code here
GetDlgItemText(IDC_SMTP_ADDRESS,m_sSendString[0]);
GetDlgItemText(IDC_FROM_ADDRESS,m_sSendString[1]);
GetDlgItemText(IDC_TO_ADDRESS,m_sSendString[2]);
m_sSendString[0].TrimLeft(" ");
m_sSendString[0].TrimRight(" ");
m_sSendString[1].TrimLeft(" ");
m_sSendString[1].TrimRight(" ");
m_sSendString[2].TrimLeft(" ");
m_sSendString[2].TrimRight(" ");
if(m_sSendString[0].IsEmpty())
{
AfxMessageBox("请输入SMTP服务器地址(IP)");
return;
}
if(m_sSendString[1].IsEmpty())
{
AfxMessageBox("请输入你的EMail地址");
return;
}
if(m_sSendString[2].IsEmpty())
{
AfxMessageBox("请输入收件人的EMail地址");
return;
}
m_sSendString[0]="HELO " + m_sSendString[0] + "\r\n";
m_sSendString[1]="MAIL FROM:" +m_sSendString[1] + "\r\n";
m_sSendString[2]= "RCPT TO:" + m_sSendString[2] + "\r\n";
m_sSendString[3]="DATA\r\n";
GetDlgItemText(IDC_EMAIL_CONTENT,m_sSendString[4]);
m_sSendString[4]=m_sSendString[4]+ "\r\n\r\n.\r\n";
m_sSendString[5]="QUIT\r\n";
CString temp;
GetDlgItemText(IDC_SMTP_ADDRESS,temp);
if(m_socket.Connect(LPCSTR(temp),25)==FALSE)
{
AfxMessageBox("Error connect to the SMTP Server");
int i=GetLastError();
switch(i)
{
}
}
m_sReceivedData="";
}
void CSendEMailDlg::ReceiveMessage(int count)
{
if(count>=6)
{
AfxMessageBox("Unknown Received Data");
m_socket.Close();
return;
}
char sBuffer[255];
int len=m_socket.Receive(sBuffer,sizeof(sBuffer));
sBuffer[len]=NULL;
m_sReceivedData=m_sReceivedData+sBuffer;
m_sReceivedData=m_sReceivedData+m_sSendString[count];
m_socket.Send(m_sSendString[count],m_sSendString[count].GetLength());
}
void CSendEMailDlg::OnShow()
{
// TODO: Add your control notification handler code here
CMessBox dlg;
dlg.m_sMessage=m_sReceivedData;
dlg.DoModal();
}
OnSend的发送按钮的消息相应
问题点数:100、回复次数:3Top
1 楼mynamelj(风之羽翼)回复于 2006-07-02 16:25:28 得分 30
OnReceive是系统自已调用的,只要你注册了FD_READ事件Top
2 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-07-02 16:44:07 得分 40
对,如楼上所说。
看来WinSocket编程才刚入门呀。
www.codeproject.com/internetTop
3 楼nuaawenlin(飘人)回复于 2006-07-02 21:11:06 得分 30
系统自己调用的消息函数
就像WM_PAINT消息会调用OnPaint一样Top




