📄 screenchattingclientdlg.cpp
字号:
// ScreenChattingClientDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ScreenChattingClient.h"
#include "ScreenChattingClientDlg.h"
//#include "WinBmpEx.h"
#include "VFWWrapper.h"
#include "MyDib.h"
/*
#include "ScreenCapture.h"
#include "JPEGEncoderEx.h"
#include "JPEGDecoderEx.h"
*/
#define XMD_H
extern "C"
{
#include "jpeglib.h"
#include "jdatadst.c"
#include "jpegint.h"
#include "jcmainct.c"
#include "rdjpgcom.c"
//#include "jdmarker.c"
}
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
FILE * infile; /* source stream */
JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
} my_source_mgr;
/* Reload the local copies --- used only in MAKE_BYTE_AVAIL */
#define INPUT_RELOAD(cinfo) \
( next_input_byte = datasrc->next_input_byte, \
bytes_in_buffer = datasrc->bytes_in_buffer )
/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
* Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
* but we must reload the local copies after a successful fill.
*/
#define MAKE_BYTE_AVAIL(cinfo,action) \
if (bytes_in_buffer == 0) { \
if (! (*datasrc->fill_input_buffer) (cinfo)) \
{ action; } \
INPUT_RELOAD(cinfo); \
}
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
#define INPUT_VARS(cinfo) \
struct jpeg_source_mgr * datasrc = (cinfo)->src; \
const JOCTET * next_input_byte = datasrc->next_input_byte; \
size_t bytes_in_buffer = datasrc->bytes_in_buffer
/* Read a byte into variable V.
* If must suspend, take the specified action (typically "return FALSE").
*/
#define INPUT_BYTE(cinfo,V,action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
bytes_in_buffer--; \
V = GETJOCTET(*next_input_byte++); )
/* Unload the local copies --- do this only at a restart boundary */
#define INPUT_SYNC(cinfo) \
( datasrc->next_input_byte = next_input_byte, \
datasrc->bytes_in_buffer = bytes_in_buffer )
typedef my_source_mgr * my_src_ptr;
BYTE* BGRToRGB(BYTE* pByteBGR,int nByteSize);
void jpeg_mem_src (j_decompress_ptr cinfo,JOCTET * pData,int FileSize,JMETHOD(void, notifyCppWorld, (j_common_ptr)));
void init_source (j_decompress_ptr cinfo);
void term_source (j_decompress_ptr cinfo);
void skip_input_data (j_decompress_ptr cinfo, long num_bytes);
void error_exit (j_common_ptr pcinfo);
BYTE* decodeRGB( jpeg_decompress_struct *cinfo,int w,int h,int * pDestBPP);
BYTE* decodeGray( jpeg_decompress_struct *cinfo,int w,int h,int * pDestBPP);
void JNotification (j_common_ptr cinfo);
BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB);
HANDLE DDBToDIB( CBitmap& bitmap, DWORD dwCompression, CPalette* pPal ,BYTE *pData);
long GetBitsMemNeeded
( LONG width,
LONG height,
WORD BitsPerPixel
);
long GetBytesPerLine
(LONG width,
LONG height,
WORD BitsPerPixel);
boolean fill_input_buffer (j_decompress_ptr cinfo);
boolean next_marker (j_decompress_ptr cinfo);
HANDLE JpegBufferToDib(BYTE *pJpegData,
int nBufferSize,
CString* pcsMsg,int &iWidth, int &iHeight); //Error msg to return
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#define TIMERID_CAPTURE 1010
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScreenChattingClientDlg dialog
CScreenChattingClientDlg::CScreenChattingClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CScreenChattingClientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CScreenChattingClientDlg)
m_uPortNum = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CScreenChattingClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CScreenChattingClientDlg)
DDX_Control(pDX, IDI_SERVERADDR, m_ipAddressCtrl);
DDX_Text(pDX, IDE_PORTNUM, m_uPortNum);
DDV_MinMaxUInt(pDX, m_uPortNum, 0, 100000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CScreenChattingClientDlg, CDialog)
//{{AFX_MSG_MAP(CScreenChattingClientDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDB_CONNECT, OnConnect)
ON_BN_CLICKED(IDR_TCP, OnTcp)
ON_BN_CLICKED(IDR_UDP, OnUdp)
ON_WM_TIMER()
ON_BN_CLICKED(IDB_CHANGESIZE, OnChangesize)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CScreenChattingClientDlg message handlers
BOOL CScreenChattingClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_curMethod=TCP;
((CButton *)GetDlgItem(IDR_UDP))->SetCheck(1);
m_pSendFrameSocket=new CSendFrameSocket(this);
// have PaintLib perform I/O instead of Serialization
/*
CRect rect;
CWnd *pWndChatting=GetDlgItem(IDS_CHATTINGWINDOW);
pWndChatting->GetWindowRect(&rect);
m_pScreenCapture=new CScreenCapture;
m_pVFWWrapper=(CVFWWrapper*)new CVFWWrapper;
if (!m_pVFWWrapper->Initialize(TRUE,CRect(rect.Width()/2-80,rect.Height()/2-60,rect.Width()/2+80,rect.Height()/2+60),this)) return FALSE;
OnChangesize();
SetTimer(TIMERID_CAPTURE,50,NULL);
*/
m_ipAddressCtrl.SetAddress(127,0,0,1);
m_uPortNum=3165;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CScreenChattingClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CScreenChattingClientDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CScreenChattingClientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CScreenChattingClientDlg::OnConnect()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
BYTE a0,a1,a2,a3;
m_ipAddressCtrl.GetAddress(a0,a1,a2,a3);
CString strAddress;
strAddress.Format("%d.%d.%d.%d",a0,a1,a2,a3);
BOOL bReuseAddr=TRUE;
if (m_curMethod==UDP)
{
if (!m_pSendFrameSocket->Create(0,SOCK_DGRAM))
{
CString strErrMsg;
strErrMsg.Format("Error Code In Create %d",m_pSendFrameSocket->GetLastError());
AfxMessageBox(strErrMsg);
return ;
}
}
else if (m_curMethod==TCP)
{
if (!m_pSendFrameSocket->Create())
{
CString strErrMsg;
strErrMsg.Format("Error Code In Create %d",m_pSendFrameSocket->GetLastError());
AfxMessageBox(strErrMsg);
return ;
}
}
if (!m_pSendFrameSocket->SetSockOpt(SO_REUSEADDR,&bReuseAddr,sizeof(BOOL)))
{
CString strErrMsg;
strErrMsg.Format("Error Code In SetSockOpt %d",m_pSendFrameSocket->GetLastError());
AfxMessageBox(strErrMsg);
return ;
}
if (!m_pSendFrameSocket->Connect(strAddress,m_uPortNum))
{
CString strErrMsg;
strErrMsg.Format("Error Code In SetSockOpt %d",m_pSendFrameSocket->GetLastError());
AfxMessageBox(strErrMsg);
return ;
}
}
void CScreenChattingClientDlg::OnTcp()
{
// TODO: Add your control notification handler code here
if (m_curMethod==UDP)
{
m_curMethod=TCP;
((CButton *)GetDlgItem(IDR_TCP))->SetCheck(1);
}
}
void CScreenChattingClientDlg::OnUdp()
{
// TODO: Add your control notification handler code here
if (m_curMethod==TCP)
{
m_curMethod=UDP;
((CButton *)GetDlgItem(IDR_UDP))->SetCheck(1);
}
}
void CScreenChattingClientDlg::OnChangesize()
{
// TODO: Add your control notification handler code here
m_pVFWWrapper->ChangeFormat();
CRect rect;
CWnd *pWndChatting=GetDlgItem(IDS_CHATTINGWINDOW);
pWndChatting->GetWindowRect(&rect);
int nWidthDiv2=m_pVFWWrapper->m_capStatus.uiImageWidth/2;
int nHeightDiv2=m_pVFWWrapper->m_capStatus.uiImageHeight/2;
m_pVFWWrapper->m_pCapWnd->MoveWindow(rect.Width()/2-nWidthDiv2,rect.Height()/2-nHeightDiv2,m_pVFWWrapper->m_capStatus.uiImageWidth,m_pVFWWrapper->m_capStatus.uiImageHeight,TRUE);
}
void CScreenChattingClientDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
/* static int i=0;
if (!m_pVFWWrapper->CaptureIt()) return;
CWinBmpEx *pWinBmpEx=m_pScreenCapture->CaptureIt(m_pVFWWrapper->m_pCapWnd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -