16,471
社区成员
发帖
与我相关
我的任务
分享
// use ON_MESSAGE(a,b)
void CUload::OnCommNotify(WPARAM wParam,LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
int nLength;
BYTE abIn[6000];// for 115200 needs 4096 and more
DWORD totalrecv;
CString txt;
switch(wParam)
{
case 0:// from CommWatchCTS()
SetCTSIcon();
SetEvent(m_hPostEventRead);// tell watcher that CommNotify has been done
break;
case 1:// from CommWatchRead()
// append on each entry
CFile uldFile(UpLoadFileName,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
uldFile.SeekToEnd( );
if (m_bConnected)
{
if(nLength=ReadCommBlock(abIn,BUFLEN))// 38400 needs 1024
{ // save into file
if (!m_bStart)
{ // only 1st
m_bStart=1;
InforOut("Receiving "+UpLoadFileName);
}
uldFile.Write(abIn,nLength);
}
}
uldFile.Close();
// get total bytes received
m_uldINs.GetText(0,txt);
totalrecv=atol(txt.GetBuffer(40));
totalrecv+=nLength;
txt.Format("%d",totalrecv);
m_uldINs.ResetContent();
m_uldINs.AddString(txt);
if (nLength>128)
{
Animate();
// reset "time waiting"
m_Elapse.ResetContent();
m_Elapse.AddString("0 s");
}
// tell watcher that CommNotify has been done
SetEvent(m_hPostEventRead);
break;
}
}