www.pudn.com > zx.zip > SCREENdlg.CPP


// ScreenDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "zclient.h" 
#include "ScreenDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CScreenDlg dialog 
 
 
CScreenDlg::CScreenDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CScreenDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CScreenDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CScreenDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CScreenDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CScreenDlg, CDialog) 
	//{{AFX_MSG_MAP(CScreenDlg) 
	ON_WM_TIMER() 
	ON_WM_LBUTTONUP() 
	ON_WM_RBUTTONUP() 
	ON_WM_RBUTTONDBLCLK() 
	ON_WM_LBUTTONDBLCLK() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CScreenDlg message handlers 
 
 
void CScreenDlg::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
 
	strcpy(pDlg->chrMission,"  \0");//为命令留出一位(见readme文件) 
	pDlg->chrMission[0]=3;//设置命令 
	 
	SetWindowText ("屏幕控制 -> 正在下载数据"); 
	GetScreen (); 
	SetWindowText ("屏幕控制 -> 空闲"); 
	//CDialog::OnTimer(nIDEvent); 
} 
 
 
BOOL CScreenDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
 
	SetTimer(1,2500,NULL);// 2秒钟更新一次屏幕 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
 
 
void CScreenDlg::OnLButtonUp(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	struct _MyMouseEvent met; 
	met.dwFlags = MOUSEEVENTF_LEFTDOWN; 
	met.DoubleClick =FALSE; 
	//得到鼠标位置 
	RECT rect; 
	GetClientRect(&rect); 
 
	float dx =(float)point.x *(float)ScreenInfo.ScrX/(float)rect.right ; 
	float dy =(float)point.y *(float)ScreenInfo.ScrY/(float)rect.bottom; 
 
	met.dx=(unsigned long)dx; 
	met.dy=(unsigned long)dy; 
 
	strcpy(pDlg->chrMission,"  \0");//为命令留出一位(见readme文件) 
	pDlg->chrMission[0]=4;//设置命令 
 
	pDlg->MouseEvent (met); 
	 
 
	return; 
	 
} 
 
 
void CScreenDlg::OnRButtonUp(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	struct _MyMouseEvent met; 
	met.dwFlags = MOUSEEVENTF_RIGHTDOWN; 
	met.DoubleClick =FALSE; 
 
	//得到鼠标位置 
	RECT rect; 
	GetClientRect(&rect); 
 
	float dx =(float)point.x *(float)ScreenInfo.ScrX/(float)rect.right ; 
	float dy =(float)point.y *(float)ScreenInfo.ScrY/(float)rect.bottom; 
 
	met.dx=(unsigned long)dx; 
	met.dy=(unsigned long)dy; 
 
	strcpy(pDlg->chrMission,"  \0");//为命令留出一位(见readme文件) 
	pDlg->chrMission[0]=4;//设置命令 
 
	pDlg->MouseEvent (met); 
} 
void CScreenDlg::GetScreen()//得到屏幕截图 
{ 
	BeginWaitCursor(); 
	if(!pDlg->ConnectSocket()) 
	{	 
		EndWaitCursor(); 
		OnOK(); 
		return; 
	} 
 
	send(pDlg->sktClient,pDlg->chrMission,300,0); 
 
	//Define Variable 
	char *buf; 
	buf=new char[SENDBLOCK]; 
	int len; 
	HANDLE hDib; 
 
	BYTE *p,*p2; 
 
	//Get Bit Size 
	recv(pDlg->sktClient,(char*)&ScreenInfo,sizeof(ScreenInfo)+1,0); 
	//allocates Memory 
	hDib = GlobalAlloc(GMEM_MOVEABLE,ScreenInfo.dwSize ); 
 
	//Lock to Byte 
	p = (LPBYTE)GlobalLock(hDib); 
	p2 = p; 
	 
	//Get Dib Data 
	int StopFlag=0xFFFF; 
 
	send(pDlg->sktClient ,(char*)&StopFlag,sizeof(int)+1,0); 
 
	for(WORD i=0;i<(ScreenInfo.dwSize /SENDBLOCK);i++) 
	{ 
		len = recv(pDlg->sktClient,buf,SENDBLOCK,0); 
		CopyMemory(p2,buf,SENDBLOCK); 
		p2 = p2 + SENDBLOCK; 
		send(pDlg->sktClient ,(char*)&StopFlag,sizeof(int)+1,0); 
 
	} 
	if (ScreenInfo.dwSize %SENDBLOCK) 
	{ 
 
		len = recv(pDlg->sktClient,buf,ScreenInfo.dwSize%SENDBLOCK,0); 
		CopyMemory(p2,buf,len); 
		p2 = p2 + ScreenInfo.dwSize%SENDBLOCK; 
	} 
	p2 = p2 - ScreenInfo.dwSize; 
 
	closesocket(pDlg->sktClient); 
	 
 
	//显示 
	RECT rect; 
	HDC dc; 
	HWND hWnd=GetSafeHwnd (); 
	::GetClientRect(hWnd,&rect); 
	dc=::GetDC (hWnd); 
	// Define Colors 
	int color = (1<<((LPBITMAPINFOHEADER)p2)->biBitCount); 
	if(color>256) 
		color = 0; 
 
	// Draw Bit to Window Dc 
	StretchDIBits(dc, 0, 0, rect.right,rect.bottom,0,0, 
		((LPBITMAPINFOHEADER)p)->biWidth,  
		((LPBITMAPINFOHEADER)p)->biHeight, 
		(LPBYTE)p+(sizeof(BITMAPINFOHEADER)+color*sizeof(RGBQUAD)), 
		(LPBITMAPINFO)p,DIB_RGB_COLORS, SRCCOPY); 
 
	GlobalFree(hDib);//要在显示出图象之后才能释放 
	EndWaitCursor(); 
	delete buf; 
 
}