⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdlg.cpp

📁 EVC做的Windows Mobile 的H263网络视频
💻 CPP
字号:
// TestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Test.h"
#include "TestDlg.h"

#define IMAGE_WIDTH 176
#define IMAGE_HEIGHT 144

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog

int count=0;
int retvalue=0;
unsigned char cdata[10000];
unsigned char vdata[30000];
int cbuffer_size=10000;
unsigned char rgbdata[80000];
int buffersize=80000;

CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_BN_CLICKED(IDC_TEST, OnTest)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_MESSAGE(WM_NET_DATA_ARRIVE,OnDataArrivedMsg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers

BOOL CTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here

	m_hBitmap=0;

	m_Timer1=NULL;

	// Initialize decompressor
	InitH263Decoder();
	
	// Adjust display windows
	CWnd *wnd,*bwnd;
	CRect rect,brect;

	// For remote video display window
	wnd=this->GetDlgItem(IDC_REMOTEVIDEO);	// Video display window
   	bwnd=this->GetDlgItem(IDC_REMOTEBORDER); // Border window...
   	bwnd->GetWindowRect(brect);
	ScreenToClient(brect);

	remote_wnd_x=brect.TopLeft().x+(brect.Width()-IMAGE_WIDTH)/2;
	remote_wnd_y=brect.TopLeft().y+(brect.Height()-IMAGE_HEIGHT)/2;
	
	// Centre the remote video window
	wnd->SetWindowPos(&wndTop,remote_wnd_x-4,remote_wnd_y-4,IMAGE_WIDTH+9,IMAGE_HEIGHT+9,SWP_SHOWWINDOW | SWP_DRAWFRAME);


	m_pClient=new CNetClient;

	m_bConnected=FALSE;


	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CTestDlg::OnTest() 
{	
	if(!m_bConnected)
	{
		Busy=FALSE;
		m_Timer1=SetTimer(1,50,NULL);
		CString Ip;
		GetDlgItemText(IDC_EDIT_IP,Ip);
		char *ip;
		ip=new char[Ip.GetLength()];
		for(int i=0;i<Ip.GetLength();i++)
		{
			ip[i]=Ip.GetAt(i);
		}
		m_pClient->Init(OnDataArrive,ip,8765,(DWORD)this);
		delete ip;
		SetDlgItemText(IDC_TEST,L"断开连接");
		m_bConnected=TRUE;
	}
	else
	{
		m_pClient->UnInit();
		Busy=FALSE;
		KillTimer(m_Timer1);		
		SetDlgItemText(IDC_TEST,L"连接");
		m_bConnected=FALSE;
	}
	
}

void CTestDlg::DisplayRemoteFrame(unsigned char *data,int size)
{
	int retvalue;
	int x,y;

	retvalue=DecompressFrame(data,size,rgbdata,buffersize);

	if(!retvalue)
	{
		return;
	}

	unsigned char temp;
	for(y=0;y<144;y++)
	{
		for(x=0;x<88;x++)
		{			
			temp=rgbdata[(176*y+x)*3];
			rgbdata[(176*y+x)*3]=rgbdata[(176*y+176-x)*3];
			rgbdata[(176*y+176-x)*3]=temp;

			temp=rgbdata[(176*y+x)*3+1];
			rgbdata[(176*y+x)*3+1]=rgbdata[(176*y+176-x)*3+1];
			rgbdata[(176*y+176-x)*3+1]=temp;

			temp=rgbdata[(176*y+x)*3+2];
			rgbdata[(176*y+x)*3+2]=rgbdata[(176*y+176-x)*3+2];
			rgbdata[(176*y+176-x)*3+2]=temp;
		}
	}
	for(x=0;x<38016;x++)
	{
		temp=rgbdata[x];
		rgbdata[x]=rgbdata[76032-x];
		rgbdata[76032-x]=temp;
	}
	
	CBitmap bitmap;
	
	bitmap.CreateBitmap(176,144,1,24,rgbdata);

	CWnd* pWnd=GetDlgItem(IDC_REMOTEVIDEO);
	pWnd->UpdateWindow();

	CDC* pDC=pWnd->GetDC();
	CDC bitmapDC;
	
	bitmapDC.CreateCompatibleDC(pDC);
	CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);
	//pDC->StretchBlt(0,0,176,144,&bitmapDC,0,0,176,144,SRCCOPY);
	pDC->BitBlt(0,0,176,144,&bitmapDC,0,0,SRCCOPY);
	bitmapDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
}

void CTestDlg::OnTimer(UINT nIDEvent) 
{
	if(!Busy)
	{
		m_pClient->SendMsg("a",1);
		Busy=TRUE;
	}
	
	CDialog::OnTimer(nIDEvent);
}

void CTestDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	if(m_Timer1)
	{
		KillTimer(m_Timer1);
	}

	m_pClient->UnInit();
	delete m_pClient;
	
}

void CTestDlg::OnDataArrive(char * pData,unsigned long DataLength,DWORD userdata)
{
	CTestDlg* pDlg=(CTestDlg*)userdata;
	if(pData)
	{
		pDlg->SendMessage(WM_NET_DATA_ARRIVE,(WPARAM)pData,(LPARAM)DataLength);
	}
}

LONG CTestDlg::OnDataArrivedMsg(WPARAM wParam,LPARAM DataLength)
{
	DisplayRemoteFrame((unsigned char*)wParam,(int)DataLength);

	Busy=FALSE;

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -