RemoteDesktopDlg.cpp
资源名称:Visualhk.rar [点击查看]
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:13k
源码类别:
网络截获/分析
开发平台:
Visual C++
- // RemoteDesktopDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyClient.h"
- #include "RemoteDesktopDlg.h"
- #include "TcpTran.h"
- #include "comm.h"
- #include "FullScreenTitleBar.h"
- #include "resource.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /*
- 作者:海啸 lyyer English Name: Jack
- blog:http://lyyer.blog.sohu.com
- website:http://www.cnGSG.com
- 海啸网络安全组织
- */
- HANDLE g_hImageCapThread =NULL;
- //BOOL m_bDlgScreen = FALSE; //已打开抓图窗口
- BOOL g_bImageLogging = FALSE;
- BOOL g_bImageExit = FALSE;
- DWORD g_dwImageCapID;
- //#define IDC_GET_SCREEN WM_USER + 300
- /////////////////////////////////////////////////////////////////////////////
- // CRemoteDesktopDlg dialog
- CRemoteDesktopDlg *m_remotedesktopdlg= NULL;
- CRemoteDesktopDlg::CRemoteDesktopDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CRemoteDesktopDlg::IDD, pParent)
- {
- m_remotedesktopdlg = this;
- //{{AFX_DATA_INIT(CRemoteDesktopDlg)
- m_bChkContinue = FALSE;
- //}}AFX_DATA_INIT
- }
- void CRemoteDesktopDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRemoteDesktopDlg)
- DDX_Control(pDX, IDC_STATIC_PIC, m_picStatArea);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CRemoteDesktopDlg, CDialog)
- //{{AFX_MSG_MAP(CRemoteDesktopDlg)
- ON_BN_CLICKED(IDC_CHECK_CAP, OnCheckCap)
- ON_BN_CLICKED(IDC_BUTTON_SCREEN, OnButtonScreen)
- ON_BN_CLICKED(IDC_BUTTON_FULLSCR, OnButtonFullscr)
- ON_COMMAND(ID_MENUITEM_CLOSE, OnMenuitemClose)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRemoteDesktopDlg message handlers
- DWORD WINAPI Set_BackGroud_Image()
- {
- if (m_remotedesktopdlg->m_lpImageData==NULL) return 1;
- HWND hWnd=m_remotedesktopdlg->GetSafeHwnd();
- CRect rc ;
- m_remotedesktopdlg->m_picStatArea.GetWindowRect(&rc);//GetWindowRect (&rc);
- //m_remotedesktopdlg->ClientToScreen(&rc);
- CDC *theDC = m_remotedesktopdlg->m_picStatArea.GetWindowDC ();
- //CDC *theDC=m_remotedesktopdlg->GetDlgItem(IDC_STATIC_PIC)->GetDC();
- if(theDC!= NULL)
- {
- int left = m_remotedesktopdlg->m_nLeft; //-m_hScrollBar.GetScrollPos();
- int top = m_remotedesktopdlg->m_nTop; //-m_vScrollBar.GetScrollPos();
- BYTE *tmp = m_remotedesktopdlg->m_lpImageData;
- // set up a DIB
- BITMAPINFOHEADER bmiHeader;
- bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmiHeader.biWidth = m_remotedesktopdlg->m_nBmpWidth; //1024/2;//
- bmiHeader.biHeight =m_remotedesktopdlg->m_nBmpHeight; // 768/2;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = 24; //24
- bmiHeader.biCompression = BI_RGB;
- bmiHeader.biSizeImage = 0;
- bmiHeader.biXPelsPerMeter = 0;
- bmiHeader.biYPelsPerMeter = 0;
- bmiHeader.biClrUsed = 0;
- bmiHeader.biClrImportant = 0;
- /*
- int StretchDIBits(
- HDC hdc, // 设备上下文句柄
- int XDest, // 目的区域左上角X轴坐标
- int YDest, // 目的区域左上角Y轴坐标
- int nDestWidth, // 目的区域的宽度
- int nDestHeight, // 目的区域的高度
- int XSrc, // 源区域左上角X轴坐标
- int YSrc, // 源区域左上角Y轴坐标
- int nSrcWidth, // 源区域的宽度
- int nSrcHeight, // 源区域的高度
- CONST VOID *lpBits, // 指向位图的比特数据,即像素数据数组
- CONST BITMAPINFO *lpBitsInfo, // 位图头部信息的指针,包含了该DIB的信息
- UINT iUsage, // usage options
- DWORD dwRop // raster operation code
- );
- */
- int lines = StretchDIBits(theDC->m_hDC,
- //rc.left, rc.top,
- left,top,
- rc.Width(),//bmiHeader.biWidth,//1024/2,//rc.Width(),//bmiHeader.biWidth/2,
- rc.Height(),//bmiHeader.biHeight,//768/2,//rc.Height(),///bmiHeader.biHeight/2,
- 0,0,
- bmiHeader.biWidth,
- bmiHeader.biHeight,
- tmp,
- (LPBITMAPINFO)&bmiHeader,
- DIB_RGB_COLORS,
- SRCCOPY);
- ReleaseDC(hWnd,*theDC);
- }
- return 0;
- }
- int Get_Screen_Data(LPVOID lpBmpData,LPCOMMAND lpMsg)
- {
- //step 1:设置显示区域大小
- BYTE *lpData = NULL, *lpData1 = NULL;
- COMMAND msg;
- CRect rcOld;
- lpData = (BYTE *)lpBmpData;
- rcOld.top = m_remotedesktopdlg->m_nTop;//lpMsg->rcArea.top;
- rcOld.bottom = m_remotedesktopdlg->m_nbottom;
- rcOld.left = m_remotedesktopdlg->m_nLeft;
- rcOld.right = m_remotedesktopdlg->m_nRight;
- //rcOld.Height() = m_remotedesktopdlg->m_nHeight;
- //rcOld.Width() = m_remotedesktopdlg->m_nWidth;
- //memcpy()
- if (rcOld.left < 0 || rcOld.top < 0 )
- int i = 0;
- //step 2: jpeg 解码
- lpData = m_remotedesktopdlg->m_Jpeg.JpegFileToRGB((BYTE *)lpBmpData+lpMsg->dwBmpInfoSize,
- lpMsg->dwBmpSize,
- (UINT *)&m_remotedesktopdlg->m_nBmpWidth,
- (UINT *)&m_remotedesktopdlg->m_nBmpHeight);
- if (lpData == NULL) return 1;
- m_remotedesktopdlg->m_Jpeg.BGRFromRGB(lpData, m_remotedesktopdlg->m_nBmpWidth, m_remotedesktopdlg->m_nBmpHeight);
- m_remotedesktopdlg->m_Jpeg.VertFlipBuf(lpData, m_remotedesktopdlg->m_nBmpWidth * 3, m_remotedesktopdlg->m_nBmpHeight);
- m_remotedesktopdlg->m_nBmpTop= lpMsg->rcArea.top;
- m_remotedesktopdlg->m_nBmpLeft = lpMsg->rcArea.left;
- UINT m_widthDW;
- m_remotedesktopdlg->m_lpImageData = m_remotedesktopdlg->m_Jpeg.MakeDwordAlignedBuf((BYTE *)lpData,
- m_remotedesktopdlg->m_nBmpWidth,
- m_remotedesktopdlg->m_nBmpHeight,
- &m_widthDW);
- //step 3:进入bmp图片显示线程
- Set_BackGroud_Image ();
- return 0;
- }
- //打开抓图线程
- DWORD WINAPI ImageCapThread()
- {
- COMMAND SendMsg;
- CRect ClientRect = CRect(0,0,1024,768);
- CTcpTran m_tcptran;
- g_bImageLogging = TRUE;
- g_bImageExit = FALSE;
- HGLOBAL hPackData = NULL, hBmpData = NULL, hBmpScr = NULL;
- LPVOID lpPackData = NULL, lpBmpData = NULL, lpBmpScr = NULL;
- DWORD dwOldSize = 0, dwSize, dwBmpInfoSize, dwMaxSize = -1;
- char *lpData;
- CString strtmp;
- int nFirst = 0;
- loop001:
- while(g_bImageLogging)
- {
- //Step 2:Send Get image command
- memset(&SendMsg, 0, sizeof(COMMAND));
- SendMsg.wCmd = CMD_SCREEN_MANAGE;
- SendMsg.rcArea = ClientRect;
- SendMsg.nArea = 0;
- SendMsg.nBits = 24;
- SendMsg.nDelay = 1000;
- SendMsg.nCompress = 2;
- SendMsg.nCell = nFirst;
- SendMsg.nJpegQ = 80;
- //Step 1: Send command
- if(!g_bImageLogging) goto Exit01;
- if (m_tcptran.mysend(m_remotedesktopdlg->ClientSocket,(char *)&SendMsg, sizeof(COMMAND),0,60) < 0)
- goto Err01;
- //Step 2: Get image struct
- memset(&SendMsg,0, sizeof(COMMAND));
- if(!g_bImageLogging) goto Exit01;
- if (m_tcptran.myrecv(m_remotedesktopdlg->ClientSocket, (char *)&SendMsg, sizeof(COMMAND),0,60,0,false) < 0)
- goto Err01;
- if(SendMsg.dwBmpSize == 0) //图象无变化
- {
- Get_Screen_Data(0,&SendMsg);
- goto loop001;
- }
- //分配内存
- dwBmpInfoSize = SendMsg.dwBmpInfoSize;
- dwSize = SendMsg.dwBmpSize;
- if (dwSize > dwMaxSize || lpBmpData == NULL)
- {
- if (lpBmpData) GlobalFree (lpBmpData);
- lpBmpData = GlobalAlloc (GMEM_FIXED, dwSize);
- dwMaxSize = dwSize;
- }
- if(lpBmpData == NULL) goto Err02;
- lpData = (char *)lpBmpData;
- if(!g_bImageLogging) goto Exit01;
- if (m_tcptran.myrecv(m_remotedesktopdlg->ClientSocket, lpData, dwSize,0,60,0,false) < 0) goto Err01;
- nFirst = 1;
- //Step 5: Show image
- lpData = (char *)lpBmpData;
- Get_Screen_Data(lpBmpData, &SendMsg);
- if(!g_bImageLogging) goto Exit01;
- //Sleep(m_remotedesktopdlg->m_nEdtSecond);
- Sleep(1500);
- } //end while
- Exit01:
- Sleep(1000);
- if (lpBmpData)
- GlobalFree(lpBmpData);
- g_bImageExit = TRUE;
- return 0;
- Err02:
- goto Exit01;
- Err01:
- goto Exit01;
- }
- BOOL CRemoteDesktopDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- IsFullScreen=FALSE;
- m_bChkContinue = FALSE;
- GetDlgItem(IDC_CHECK_CAP)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_BUTTON_SCREEN)->ShowWindow(SW_SHOW);
- GetDlgItem(IDC_BUTTON_FULLSCR)->ShowWindow(SW_SHOW);
- // m_nWidth = 0;
- // m_nTop = 0;
- // m_nHeight = 0;
- // m_nLeft = 0;
- /*
- //初始化窗口的大小(默认值1024*768 * 3/4)
- unsigned int m_nLeft=0;
- unsigned int m_nTop =0;
- unsigned int m_nWidth=1024 ; //512
- unsigned int m_nHeight = 768; //384
- CRect clientRect;
- m_picStatArea.GetClientRect (&clientRect);
- CRect rc = CRect(m_nLeft,m_nTop,m_nWidth,m_nHeight);
- m_picStatArea.GetWindowRect (&rc);
- DWORD threadid=0;
- g_hImageCapThread =CreateThread(NULL,0,ImageCapThread,(LPVOID)rc,0,&threadid);
- */
- return true;
- }
- int SysEndImage()
- {
- int i = 100;
- if(g_bImageLogging==FALSE)
- return 0;
- g_bImageLogging=FALSE; //退出
- if(WaitForSingleObject(g_hImageCapThread,5000)==WAIT_OBJECT_0)
- while(g_bImageExit==FALSE) {
- Sleep(15); //等待退出
- i--;
- if (i == 0) TerminateProcess(g_hImageCapThread, 0);
- }
- return -1;
- }
- int SysStartImage()
- {
- if(g_bImageLogging == TRUE)
- return -1;
- g_hImageCapThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ImageCapThread,
- 0,0,
- &g_dwImageCapID);
- if(g_hImageCapThread==NULL)
- return -1;
- return 0;
- }
- void CRemoteDesktopDlg::OnCheckCap()
- {
- // TODO: Add your control notification handler code here
- //BOOL bStatus;
- //m_rcArea =CRect(m_nLeft,m_nTop,m_nWidth,m_nHeight);
- m_bChkContinue=TRUE;
- if(m_bChkContinue)
- {
- SysStartImage();
- //bStatus = FALSE;
- }
- else
- {
- SysEndImage();
- //bStatus =TRUE;
- }
- }
- void CRemoteDesktopDlg::OnButtonScreen()
- {
- // TODO: Add your control notification handler code here
- CTcpTran m_tcptran;
- COMMAND SendMsg;
- memset(&SendMsg, 0, sizeof(COMMAND));
- SendMsg.wCmd = CMD_GET_SCREEN_INFO;
- int tmp = m_tcptran.mysend(m_remotedesktopdlg->ClientSocket,(char *)&SendMsg,sizeof(COMMAND),0,60);
- if (tmp)
- {
- memset(&SendMsg, 0, sizeof(COMMAND));
- m_tcptran.myrecv(m_remotedesktopdlg->ClientSocket,(char *)&SendMsg,sizeof(COMMAND),0,60,0,false);
- m_nTop = SendMsg.rcArea.top;
- m_nLeft = SendMsg.rcArea.left;
- m_nbottom = SendMsg.rcArea.bottom;
- m_nRight = SendMsg.rcArea.right;
- CString ffff;
- ffff.Format("%d - %d - %d - %d",m_nTop,m_nLeft,m_nbottom,m_nRight);
- AfxMessageBox(ffff);
- }
- }
- void CRemoteDesktopDlg::OnButtonFullscr()
- {
- // TODO: Add your control notification handler code here
- //Header
- //Eg in OnInitDialog() procedure
- TitleBar=new CTitleBar(AfxGetInstanceHandle(), this->GetSafeHwnd());
- if(IsFullScreen==FALSE)
- SetFullScreen(TRUE); //Set fullscreen on!
- else
- SetFullScreen(FALSE); //Set fullscreen on!
- // GetDlgItem(IDC_CHECK_CAP)->ShowWindow(SW_HIDE);
- // GetDlgItem(IDC_BUTTON_SCREEN)->ShowWindow(SW_HIDE);
- // GetDlgItem(IDC_BUTTON_FULLSCR)->ShowWindow(SW_HIDE);
- }
- void CRemoteDesktopDlg::SetFullScreen(BOOL OnOff)
- {
- LONG style = GetWindowLong(m_hWnd, GWL_STYLE);
- if(OnOff==TRUE)
- {
- ::ShowWindow(m_hWnd, SW_MAXIMIZE);
- style = GetWindowLong(m_hWnd, GWL_STYLE);
- style &= ~(WS_DLGFRAME | WS_THICKFRAME);
- SetWindowLong(m_hWnd, GWL_STYLE, style);
- int cx = GetSystemMetrics(SM_CXSCREEN);
- int cy = GetSystemMetrics(SM_CYSCREEN);
- ::SetWindowPos(m_hWnd, HWND_TOPMOST, -1, -1, cx+3, cy+3, SWP_FRAMECHANGED);
- IsFullScreen=TRUE;
- TitleBar->DisplayWindow(TRUE, TRUE);
- ::InvalidateRect(m_hWnd,NULL,TRUE);
- }
- else //OFF!
- {
- style |= WS_DLGFRAME | WS_THICKFRAME;
- SetWindowLong(m_hWnd, GWL_STYLE, style);
- ::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0,0,100,100, SWP_NOMOVE | SWP_NOSIZE);
- ::ShowWindow(m_hWnd, SW_NORMAL);
- IsFullScreen=FALSE;
- TitleBar->DisplayWindow(FALSE, TRUE);
- ::InvalidateRect(m_hWnd,NULL,TRUE);
- }
- }
- //DEL void CRemoteDesktopDlg::OnMenuitemRestore()
- //DEL {
- //DEL // TODO: Add your command handler code here
- //DEL
- //DEL ::ShowWindow(this->GetSafeHwnd(), SW_RESTORE);
- //DEL //break;
- //DEL }
- //DEL void CRemoteDesktopDlg::OnMenuitemClose()
- //DEL {
- //DEL // TODO: Add your command handler code here
- //DEL // HWND Window=this->GetSafeHwnd();
- //DEL // ::DestroyWindow(Window);
- //DEL
- //DEL delete TitleBar;
- //DEL
- //DEL HWND Window=this->GetSafeHwnd();
- //DEL ::DestroyWindow(Window);
- //DEL PostQuitMessage(0);
- //DEL }
- //DEL BOOL CRemoteDesktopDlg::DestroyWindow()
- //DEL {
- //DEL // TODO: Add your specialized code here and/or call the base class
- //DEL
- //DEL delete TitleBar;
- //DEL return CDialog::DestroyWindow();
- //DEL }
- void CRemoteDesktopDlg::OnMenuitemClose()
- {
- // TODO: Add your command handler code here
- ::SendMessage((HWND)this,WM_CLOSE,0,0);
- }