我通过如下代码进行屏幕捕捉,但我想通过某个按钮,使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);//更新视图}
服务端:
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);//更新视图}
解决方案 »
- 请教各位高手关于Edit控件问题,急!先谢谢了
- 关于grep处理0*的问题。
- 如何继承CWnd类?
- 用线程显示clistctrl内容,窗口关闭时的处理
- 已知位图的 BITMAPFILEHEADER,BITMAPINFOHEADER和位图数据iBMPBytes 怎么把位图保持到char数组中
- 高分请教!请问这样对CArray中数据进行排序为什么报错,CArray中放的是结构体,代码是。。。。。
- 帮忙解决排样算法
- 请问哪里有《深入浅出MFC》下栽??
- 一个ListView的问题,我都快被折磨死了,我也一定给分
- 打开FTP文件的问题之二(我没分了,大侠帮人帮到底吧!)
- socket不能继续发送数据
- 请问在VC中如何实现与SQL Server数据库连接。
if(!strAction.Compare("BITMAP"))
{
SendBITMAP();
return;
} else if(!strAction.Compare("BITDATA"))
{
SendBitData();
return;
}
我应怎样在保持连接的情况下,终止消息的传送啊,
各位大哥,快救小弟吧,要被炒了