📄 unit2.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall TRecvThread::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TRecvThread::TRecvThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TRecvThread::Execute()
{unsigned long Mask,Transer;
bool OK;
OVERLAPPED ee;
Form1->Receive=true;
memset(&ee,0,sizeof(ee));
ee.hEvent=CreateEvent(NULL,true,false,NULL);
if(ee.hEvent==NULL) return;
while(Form1->Receive){
Mask=0; Transer=0;
if(!SetCommMask(Form1->hb,EV_RXCHAR))return;
/*Form1->Memo1->Lines->Add("Mask1="+IntToStr(Mask));*/
/*Form1->Memo1->Lines->Add("Transer="+IntToStr(Transer));*/
if(!WaitCommEvent(Form1->hb,&Mask,&ee))
{ /*Form1->Memo1->Lines->Add("Mask2=ww"); */
if(ERROR_IO_PENDING==GetLastError())
GetOverlappedResult(Form1->hb,&ee,&Transer,true);
/*Form1->Memo1->Lines->Add("Mask3="+IntToStr(Mask)); */
}
if((Mask&EV_RXCHAR)==EV_RXCHAR)
{ /*Form1->Memo1->Lines->Add("Mask1=wq"); */
WaitForSingleObject(Form1->Post,INFINITE);
ResetEvent(Form1->Post);
OK=PostMessage(Form1->Handle,WM_COMMNOTIFY,(unsigned int)(Form1->hb),0);
if(!OK){ShowMessage("消息传送出错");return;}
} /*Form1->Memo1->Lines->Add("Mask4="+IntToStr(Mask)); */
}/*Form1->Memo1->Lines->Add("Mask1=q"); */
CloseHandle(ee.hEvent);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -