msg.cpp
来自「简单的远程控制工具,分为服务器与客户斋,让你了解socket编程的知识.」· C++ 代码 · 共 185 行
CPP
185 行
// msg.cpp : implementation of the CMsg class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "Resource.h"
#include "msg.h"
#include "huffman.h"
#include "SendKey.H"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMsg
IMPLEMENT_DYNCREATE(CMsg, CObject)
/////////////////////////////////////////////////////////////////////////////
// CMsg construction/destruction
CMsg::CMsg()
{
Init();
}
CMsg::~CMsg()
{
}
/////////////////////////////////////////////////////////////////////////////
// CMsg Operations
void CMsg::Init()
{
m_wCmd = CMD_SOCKET_WAIT;
m_strText = _T("");
m_strParam = _T("");
m_strPassword = _T("");
m_rcArea = CRect(0,0,100,100);
m_nBits = 8;
m_lpBmpData = NULL;
m_dwBmpSize = 0;
m_dwBmpInfoSize = 0;
m_lpFileData = NULL;
m_dwFileSize = 0;
m_dwSize = 0;
m_dwPoint = 0;
}
/////////////////////////////////////////////////////////////////////////////
// CMsg serialization
void CMsg::Serialize(CArchive& ar)
{
HANDLE lpMem;
if (ar.IsStoring()) //Send
{
ar << (WORD)m_wCmd;
ar << m_strPassword;
switch(m_wCmd)
{
case CMD_GET_SCREEN:
ar << m_rcArea;
ar << m_nBits;
ar << m_bCompress;
// ar << m_dwSize;
break;
case CMD_SOCKET_CLOSE:
case CMD_STATE_INFO:
ar << m_strText;
break;
case CMD_FILE_SEND:
ar << m_strParam;
ar << m_dwFileSize;
ar.Write (m_lpFileData,m_dwFileSize);
break;
case CMD_KEY_HOOK:
case CMD_MOUSE_HOOK:
ar << m_dwHookFlags;
ar << m_dwHookParam1;
ar << m_dwHookParam2;
break;
case CMD_KEY_MOUSE_BUFFER:
ar << m_iSendPoint;
ar.Write(m_vsSendKey, m_iSendPoint * sizeof(SENDKEY));
break;
default :
ar << m_strParam;
} //end switch
}//end if
else //Receive
{
ar >> m_wCmd;
switch (m_wCmd)
{
case CMD_GET_SCREEN :
//-------------- 没有压缩
ar >> m_dwBmpInfoSize;
ar >> m_dwBmpSize;
ar >> m_dwFileSize;
ar >> m_bCompress;
// ar >> m_dwSize;
// ar >> m_dwPoint;
if (m_dwBmpSize > 0 ) //0 is Error
{
lpMem = GlobalAlloc (GHND,m_dwBmpSize);
if (lpMem == NULL)
{ m_dwBmpSize = 0;
return;
}
m_lpBmpData = (LPSTR)GlobalLock (lpMem);
if (m_lpBmpData == NULL)
{
GlobalFree(lpMem);
m_dwBmpSize = 0;
return;
}
if (ar.Read (m_lpBmpData,m_dwBmpSize) != m_dwBmpSize)
{
GlobalUnlock(m_lpBmpData);
GlobalFree(lpMem);
m_dwBmpSize = 0;
return;
}
}//end if
break;
case CMD_GET_SCREEN_INFO:
ar >> m_nBits;
ar >> m_rcArea;
break;
case CMD_FILE_RECEIVE:
ar >> m_dwFileSize;
m_lpFileData = GlobalAlloc (GMEM_FIXED,m_dwFileSize);
if (m_lpFileData == NULL)
{
GlobalFree(m_lpFileData);
m_dwFileSize = 0;
return;
}
if (ar.Read (m_lpFileData,m_dwFileSize) != m_dwFileSize)
{
GlobalFree(m_lpFileData);
m_dwFileSize = 0;
return;
}
break;
case CMD_STATE_INFO:
case CMD_SOCKET_CLOSE:
ar >> m_strText;
} //end switch
}//end else
}//end function
/////////////////////////////////////////////////////////////////////////////
// CMsg diagnostics
#ifdef _DEBUG
void CMsg::AssertValid() const
{
CObject::AssertValid();
}
void CMsg::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
}
#endif //_DEBUG
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?