我通过如下代码进行屏幕捕捉,但我想通过某个按钮,使Socket发送停止,且释放所申请的内存资源,那该按钮的代码应如何写啊
服务端:
void CRemoteCtrlServerDlg::CatchScreen()
{// protect类型 只用于内部函数的调用
//截获屏幕位图信息和数据信息分别放在btm和lpdata
CDC dc;
dc.CreateDC("DISPLAY",NULL,NULL,NULL);
CBitmap bm;
int Width=GetSystemMetrics(SM_CXSCREEN);
int Height=GetSystemMetrics(SM_CYSCREEN);
bm.CreateCompatibleBitmap(&dc,Width,Height);
CDC tdc;
tdc.CreateCompatibleDC(&dc);
CBitmap*pOld=tdc.SelectObject(&bm);
tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
tdc.SelectObject(pOld);bm.GetBitmap(&btm);
size=btm.bmWidthBytes*btm.bmHeight;lpData=new char[size]; 
/////////////////////////////////////////////
BITMAPINFOHEADER bih;
bih.biBitCount=btm.bmBitsPixel;
bih.biClrImportant=0;
bih.biClrUsed=0;
bih.biCompression=0;
bih.biHeight=btm.bmHeight;
bih.biPlanes=1;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biSizeImage=size;
bih.biWidth=btm.bmWidth;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
///////////////////////////////////
GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);}void CRemoteCtrlServerDlg::SendBITMAP()
{
//发送位图结构信息
CatchScreen();
m_sockClient.Send(&btm,sizeof(BITMAP),0);
}void CRemoteCtrlServerDlg::SendBitData()
{  
//发送位图数据信息
int nBytesSent=0;
int nByetsThisTime;
char *pch=lpData;
do{       
//发送大量的数据时 采用循环 直到发送完要发送的数据为止 
nByetsThisTime=m_sockClient.Send(pch,size);
nBytesSent+=nByetsThisTime;
pch+=nByetsThisTime;
}while(nBytesSent<size);
  
delete lpData; //发送完毕时删除位图的数据信息,清理申请的内存
lpData=NULL;
size=0;
}
可户端:
CMainFrame* wMainFrame=(CMainFrame*)AfxGetApp()->GetMainWnd();
if(!wMainFrame->m_bOver) 
return;
//if(wMainFrame->m_sockClient==NULL) return;
if(lpData!=NULL)
{
delete lpData;
lpData=NULL;
}
CString strSend=_T("BITMAP");
strSend+="\r\n";
    wMainFrame->m_bScreen=true;
   int BTMInfoSize=24;
   char BTMInfoBuf[24];
   wMainFrame->m_sockClient.AttachWnd(this->m_hWnd);
   wMainFrame->m_sockClient.Send((LPCTSTR)strSend,strSend.GetLength());
   int ret=wMainFrame->m_sockClient.Receive(BTMInfoBuf,sizeof(BITMAP));
   if (ret!=24)
{
MessageBox("failed recive 24"); 
return;
   }
   BITMAP *BTMBUF=(BITMAP *)BTMInfoBuf;
   btm.bmBits=BTMBUF->bmBits;
   btm.bmBitsPixel=BTMBUF->bmBitsPixel;
   btm.bmHeight=BTMBUF->bmHeight;
   btm.bmPlanes=BTMBUF->bmPlanes;
   btm.bmType=BTMBUF->bmType;
   btm.bmWidth=BTMBUF->bmWidth;
   btm.bmWidthBytes=BTMBUF->bmWidthBytes;
   strSend=_T("BITDATA");
   strSend+="\r\n";
   wMainFrame->m_sockClient.Send((LPCTSTR)strSend,strSend.GetLength());
   int size=btm.bmWidthBytes*btm.bmHeight;
   lpData=new char[size];
   if(lpData==NULL)
MessageBox("faile memery");
   char *pch=lpData ;
   int nBytesRec=0;
   int nBytesThisTime;
   do{                               //发送的内容较大采用循环发送完成为止
nBytesThisTime=wMainFrame->m_sockClient.Receive(pch,size-nBytesRec);
nBytesRec+=nBytesThisTime;
pch+=nBytesThisTime;
}while(nBytesRec<size);
if (nBytesRec!=(int)size)
{
MessageBox("failed recive data"); 
return;
}
wMainFrame->m_bScreen=false;
GetDocument()->UpdateAllViews(NULL,NULL,NULL);//更新视图}