videoshow.cpp

来自「用vb实现在线考试系统」· C++ 代码 · 共 980 行 · 第 1/2 页

CPP
980
字号
// VideoShow.cpp : implementation file
//

#include "stdafx.h"
#include "Cli_SoftAndHard.h"
#include "VideoShow.h"
#include "hikclient.h"
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mmsystem.h>
#include <fcntl.h>
#include <sys\stat.h> 

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

int		logFile;
int		LogWrite(const char *Format, ...);
int		gShowMode;

extern int	iCurrentWin;	//当前通道号

//extern LPSHOWPARAMS gShowParams;
extern long pDeviceTotal;
extern LPSHOWPARAMS ShowParams;
extern LPSWITCHSHOW SwitchParams;
/////////////////////////////////////////////////////////////////////////////
// CVideoShow dialog


CVideoShow::CVideoShow(CWnd* pParent /*=NULL*/)
	: CDialog(CVideoShow::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVideoShow)
	//}}AFX_DATA_INIT
}


void CVideoShow::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVideoShow)
	DDX_Control(pDX, IDC_STATIC19, m_Static19);
	DDX_Control(pDX, IDC_STATIC9, m_Static9);
	DDX_Control(pDX, IDC_STATIC8, m_Static8);
	DDX_Control(pDX, IDC_STATIC7, m_Static7);
	DDX_Control(pDX, IDC_STATIC6, m_Static6);
	DDX_Control(pDX, IDC_STATIC24, m_Static24);
	DDX_Control(pDX, IDC_STATIC23, m_Static23);
	DDX_Control(pDX, IDC_STATIC22, m_Static22);
	DDX_Control(pDX, IDC_STATIC21, m_Static21);
	DDX_Control(pDX, IDC_STATIC20, m_Static20);
	DDX_Control(pDX, IDC_STATIC18, m_Static18);
	DDX_Control(pDX, IDC_STATIC17, m_Static17);
	DDX_Control(pDX, IDC_STATIC16, m_Static16);
	DDX_Control(pDX, IDC_STATIC15, m_Static15);
	DDX_Control(pDX, IDC_STATIC14, m_Static14);
	DDX_Control(pDX, IDC_STATIC13, m_Static13);
	DDX_Control(pDX, IDC_STATIC12, m_Static12);
	DDX_Control(pDX, IDC_STATIC11, m_Static11);
	DDX_Control(pDX, IDC_STATIC10, m_Static10);
	DDX_Control(pDX, IDC_STATIC5, m_Static5);
	DDX_Control(pDX, IDC_STATIC4, m_Static4);
	DDX_Control(pDX, IDC_STATIC3, m_Static3);
	DDX_Control(pDX, IDC_STATIC2, m_Static2);
	DDX_Control(pDX, IDC_STATIC1, m_Static1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CVideoShow, CDialog)
	//{{AFX_MSG_MAP(CVideoShow)
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
	ON_MESSAGE(WM_MYCOMMAND,OnMyCommand)
	ON_MESSAGE(WM_MYSINGLEMODE,OnSingleMode)
	ON_MESSAGE(WM_MYMULTIMODE,OnMultiMode)
	ON_WM_DESTROY()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_STATIC1, OnStatic1)
	ON_BN_CLICKED(IDC_STATIC2, OnStatic2)
	ON_BN_CLICKED(IDC_STATIC3, OnStatic3)
	ON_BN_CLICKED(IDC_STATIC4, OnStatic4)
	ON_BN_CLICKED(IDC_STATIC5, OnStatic5)
	ON_BN_CLICKED(IDC_STATIC6, OnStatic6)
	ON_BN_CLICKED(IDC_STATIC7, OnStatic7)
	ON_BN_CLICKED(IDC_STATIC8, OnStatic8)
	ON_BN_CLICKED(IDC_STATIC9, OnStatic9)
	ON_BN_CLICKED(IDC_STATIC10, OnStatic10)
	ON_BN_CLICKED(IDC_STATIC11, OnStatic11)
	ON_BN_CLICKED(IDC_STATIC12, OnStatic12)
	ON_BN_CLICKED(IDC_STATIC13, OnStatic13)
	ON_BN_CLICKED(IDC_STATIC14, OnStatic14)
	ON_BN_CLICKED(IDC_STATIC15, OnStatic15)
	ON_BN_CLICKED(IDC_STATIC16, OnStatic16)
	ON_BN_CLICKED(IDC_STATIC17, OnStatic17)
	ON_BN_CLICKED(IDC_STATIC18, OnStatic18)
	ON_BN_CLICKED(IDC_STATIC19, OnStatic19)
	ON_BN_CLICKED(IDC_STATIC20, OnStatic20)
	ON_BN_CLICKED(IDC_STATIC21, OnStatic21)
	ON_BN_CLICKED(IDC_STATIC22, OnStatic22)
	ON_BN_CLICKED(IDC_STATIC23, OnStatic23)
	ON_BN_CLICKED(IDC_STATIC24, OnStatic24)
	ON_BN_CLICKED(IDC_STATIC25, OnStatic25)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVideoShow message handlers

BOOL CVideoShow::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_bPaint = false;
	m_SwitchNum = 0;

	/*日志初始化*/
	char filename[20];
	sprintf(filename,"myMessage.txt");
	logFile = _open(filename,  _O_CREAT | _O_WRONLY |S_IREAD | S_IWRITE);
	LogWrite("Init....\n");

	gShowMode = VIDEO_MULTI_MODE;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CVideoShow::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;
	}
	else
	{
		CDialog::OnPaint();
	}

	MP4_ClientRestoreSurface_Card();
}

HBRUSH CVideoShow::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
	int i;
	CWnd* pSubWnd[25];
	
	for(i=0; i<25; i++)
	{
		pSubWnd[i]=GetDlgItem(IDC_STATIC1+i);
		
		if((pWnd->m_hWnd==pSubWnd[i]->m_hWnd))
		{
			HBRUSH hBrush=::CreateSolidBrush(COLORREF(0xff00ff));
			return hBrush;
		}
	}

	
/*
	CWnd* pSubWnd1=GetDlgItem(IDC_STATIC1);
	CWnd* pSubWnd2=GetDlgItem(IDC_STATIC2);
	CWnd* pSubWnd3=GetDlgItem(IDC_STATIC3);
	CWnd* pSubWnd4=GetDlgItem(IDC_STATIC4);
	CWnd* pSubWnd5=GetDlgItem(IDC_STATIC5);
	CWnd* pSubWnd6=GetDlgItem(IDC_STATIC6);
	CWnd* pSubWnd7=GetDlgItem(IDC_STATIC7);
	CWnd* pSubWnd8=GetDlgItem(IDC_STATIC8);
	CWnd* pSubWnd9=GetDlgItem(IDC_STATIC9);
	CWnd* pSubWnd10=GetDlgItem(IDC_STATIC10);
	CWnd* pSubWnd11=GetDlgItem(IDC_STATIC11);
	CWnd* pSubWnd12=GetDlgItem(IDC_STATIC12);
	CWnd* pSubWnd13=GetDlgItem(IDC_STATIC13);
	CWnd* pSubWnd14=GetDlgItem(IDC_STATIC14);

	if((pWnd->m_hWnd==pSubWnd1->m_hWnd))
	{
		HBRUSH hBrush=::CreateSolidBrush(COLORREF(0xff00ff));
		return hBrush;
	}

    if((pWnd->m_hWnd==pSubWnd2->m_hWnd))
	{
		HBRUSH hBrush=::CreateSolidBrush(COLORREF(0xff00ff));
		return hBrush;
	}
	
	if((pWnd->m_hWnd==pSubWnd3->m_hWnd))
	{
		HBRUSH hBrush=::CreateSolidBrush(COLORREF(0xff00ff));
		return hBrush;
	}
	
	if((pWnd->m_hWnd==pSubWnd4->m_hWnd))
	{
		HBRUSH hBrush=::CreateSolidBrush(COLORREF(0xff00ff));
		return hBrush;
	}

*/
	return hbr;
}

//
void CVideoShow::OnMyCommand(WPARAM wParam, LPARAM lParam)
{
	char ctemp[1000];
	switch((BYTE)wParam)
	{
	case RECDATAERR:
		{
			CTime time;
			time = CTime::GetCurrentTime();
			break;
		}
	case PLAYERR:
		{
			CTime time;
			time = CTime::GetCurrentTime();
			break;
		}
	case REFUSED:
		{
			CTime time;
			time = CTime::GetCurrentTime();
			break;
		}
	case VERSIONERR:
		{
			CTime time;
			time = CTime::GetCurrentTime();
			break;
		}
	case GETSTRING:
		{
			WORD tlen;
			char ips[30];
			memset(ctemp,0,1000);
			
			MP4_ClientReadLastMessage(ips,ctemp,&tlen);
			sprintf(&(ctemp[tlen]),"\r\n");

			CString tmpStr;
			tmpStr.Format("%s:%s\n", ips, ctemp);
			LogWrite(tmpStr);

			break;
		}

	default:
		{
			break;
		}
	}
}

//初始化硬件卡
long CVideoShow::InitCard()
{
	MP4_ClientSetNetPort(5050 , 6050);	
	bool bStartup;
	CString tmpStr;

	bStartup = MP4_ClientStartup(WM_MYCOMMAND, this->m_hWnd);
    	
	if (bStartup=0)
	{
		tmpStr.Format("MP4_ClientStartup error!");
		AfxMessageBox(tmpStr);
	}
	
	MP4_ClientInitDevice_Card(&pDeviceTotal);
	MP4_ClientInitDDraw_Card(this->m_hWnd,COLORREF(0xff00ff));
	
	splitRect(pDeviceTotal);
	return pDeviceTotal;
}

//视频显示
void CVideoShow::StartShow()
{
	//UpdateData(TRUE);

	oldShowParams = ShowParams;
	/*
	if(!m_bPaint)
	{
		OnPaint();
		bOnPaint=true;
	}*/
	
	int i, nn1;
	int a; 
	CRect rectVideo; 
	CLIENT_CARDINFO cliVideo;
	
	for(i=0; i<MAX_CHANNELS; i++)
	{
		m_Values[i][0] = ShowParams->bShow[i];
		m_Values[i][1] = ShowParams->ipos[i];
		m_Values[i][2] = ShowParams->localChannel[i];
		m_Values[i][3] = ShowParams->m_linktype[i];
		m_Values[i][4] = ShowParams->remoteChannel[i];
		//m_Values[i][5] = ShowParams->result[i];
		m_remoteIP[i] = ShowParams->remoteIP[i]; 
	}

	CString strTmp;
	strTmp.Format("StartShow:%d %s %d %s", iCurrentWin, ShowParams->remoteIP[iCurrentWin], ShowParams->remoteChannel[iCurrentWin], m_remoteIP[iCurrentWin]);  
	//AfxMessageBox(strTmp);

	for(i=0; i<MAX_CHANNELS; i++)
	{
		//是否显示
		//if(ShowParams->bShow[i]==1)
		//{
			cliVideo.m_bRemoteChannel = ShowParams->remoteChannel[i];
		
			switch(ShowParams->m_linktype[i])
			{
			case 0:
				cliVideo.m_bSendMode = TCPMODE;
				break;
			case 1:
				cliVideo.m_bSendMode = UDPMODE;
				break;
			case 2:
				cliVideo.m_bSendMode = MULTIMODE;
				break;
			case 3:
				cliVideo.m_bSendMode = DIALING;
				break;
			default:
				cliVideo.m_bSendMode = TCPMODE;
				break;
			}
			

			GetDlgItem(IDC_STATIC1+ShowParams->ipos[i])->GetWindowRect(&rectVideo);
			ScreenToClient((LPPOINT)&rectVideo);
			ScreenToClient((LPPOINT)&rectVideo+1);
						
			cliVideo.m_sIPAddress = ShowParams->remoteIP[i];

			cliVideo.m_sUserName = "123";
			cliVideo.m_sUserPassword="w";
			cliVideo.m_bUserCheck = TRUE;

			cliVideo.displaypara.nLeft =rectVideo.left;
			cliVideo.displaypara.nTop = rectVideo.top;
			cliVideo.displaypara.nWidth =rectVideo.Width();
			cliVideo.displaypara.nHeight =rectVideo.Height();

			cliVideo.displaypara.bToScreen = ShowParams->bShow[i];
			cliVideo.displaypara.bToVideoOut = 1;
			cliVideo.displaypara.format =vfYUV422Planar;

			MP4_ClientSetTTL(64);

			nn1 = MP4_ClientStart_Card(&cliVideo, ShowParams->localChannel[i] , NULL);
			a = MP4_ClientGetState(nn1);
			ShowParams->result[i] = nn1;
		//}
	}
}

/***********************************
 *	分屏设置
 *	Input:		iNum:分屏个数
 **********************************/
void CVideoShow::splitRect(int iNum)
{
	int i, j;
	RECT r;
	CRect showRect[25];

	GetClientRect(&r);
	int rectWidth = r.right - r.left;
	int rectHeight = r.bottom - r.top;

	m_ShowNum = iNum;

	
	//先将所有的输出区域隐藏
	for(i=0; i<25; i++)
	{
		GetDlgItem(IDC_STATIC1+i)->ShowWindow(SW_HIDE);
	}

	switch(iNum) {
	case 1:
		showRect[0].SetRect(0, 0, r.right, r.bottom);
		GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW);
		GetDlgItem(IDC_STATIC1)->MoveWindow(&showRect[0]);
		break;

	case 2:
	case 3:
	case 4:
		/*
		showRect[0].SetRect(r.left, r.top, rectWidth/2, rectHeight/2);
		showRect[1].SetRect(rectWidth/2, r.top, rectWidth, rectHeight/2);
		showRect[2].SetRect(r.left, rectHeight/2, rectWidth/2, rectHeight);
		showRect[3].SetRect(rectWidth/2, rectHeight/2, rectWidth, rectHeight); 
		*/
		
		for(j=0; j<2; j++)
		{
			for(i=0; i<2; i++)
			{
				showRect[i+2*j].SetRect(i*rectWidth/2, j*rectHeight/2, (i+1)*rectWidth/2, (j+1)*rectHeight/2);
			}
		}

		for(i=0; i<4; i++)
		{
			GetDlgItem(IDC_STATIC1+i)->ShowWindow(SW_SHOW); 
			GetDlgItem(IDC_STATIC1+i)->MoveWindow(&showRect[i]);
		}
		break;

	case 5:
	case 6:
		showRect[0].SetRect(r.left, r.top, rectWidth*2/3, rectHeight*2/3);
		showRect[1].SetRect(rectWidth*2/3, r.top, rectWidth, rectHeight/3);
		showRect[2].SetRect(rectWidth*2/3, rectHeight/3, rectWidth, rectHeight*2/3);
		showRect[3].SetRect(r.left, rectHeight*2/3, rectWidth/3, rectHeight);
		showRect[4].SetRect(rectWidth/3, rectHeight*2/3, rectWidth*2/3, rectHeight);
		showRect[5].SetRect(rectWidth*2/3, rectHeight*2/3, rectWidth, rectHeight);
		
		for(i=0; i<6; i++)
		{
			GetDlgItem(IDC_STATIC1+i)->ShowWindow(SW_SHOW); 
			GetDlgItem(IDC_STATIC1+i)->MoveWindow(&showRect[i]);
		}
		break;
	case 7:
	case 8:
	case 9:
		for(j=0; j<3; j++)
		{
			for(i=0; i<3; i++)
			{
				showRect[i+3*j].SetRect(i*rectWidth/3, j*rectHeight/3, (i+1)*rectWidth/3, (j+1)*rectHeight/3);
			}
		}

		for(i=0; i<9; i++)
		{
			GetDlgItem(IDC_STATIC1+i)->ShowWindow(SW_SHOW); 
			GetDlgItem(IDC_STATIC1+i)->MoveWindow(&showRect[i]);
		}

		break;
	case 10:
	case 11:
	case 12:
	case 13:
	case 14:
	case 15:
	case 16:
	
		for(j=0; j<4; j++)
		{
			for(i=0; i<4; i++)
			{
				showRect[i+4*j].SetRect(i*rectWidth/4, j*rectHeight/4, (i+1)*rectWidth/4, (j+1)*rectHeight/4);
			}
		}

		for(i=0; i<16; i++)
		{

⌨️ 快捷键说明

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