📄 clientdemodlg.cpp
字号:
// clientdemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "clientdemo.h"
#include "clientdemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_MYCOMMAND WM_USER+1
#define DEFAULTVAL 64
//#define RECORD_ONLY
int count;
HWND hWnd1,hWnd2,hWnd3,hWnd4,hWnd5,hWnd6,hWnd7,hWnd8;
//int filecount=20;
DWORD num1;
UINT timers;
int ipos=0;
BOOL bpos=FALSE;
RECT rinit;
CRect m_OldRect;
int filecount=0;
UINT filetimer=0;
int capcount=0;
CRect orirc;
BOOL blarged=FALSE;
WORD testnum=0;
BOOL bmode=FALSE;
BOOL g_bCapPic=FALSE;
UINT remains=0;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CClientdemoDlg dialog
CClientdemoDlg::CClientdemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClientdemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClientdemoDlg)
m_linktype = 0;
m_ipadd = _T("192.0.0.40");
m_shownum = 1;
m_delaytype = -1;
m_showmode = -1;
m_bframenum = -1;
m_frameshow = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClientdemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClientdemoDlg)
DDX_Control(pDX, IDC_SLIDER4, m_hue);
DDX_Control(pDX, IDC_SLIDER3, m_saturation);
DDX_Control(pDX, IDC_SLIDER2, m_contrast);
DDX_Control(pDX, IDC_SLIDER1, m_brightness);
DDX_Control(pDX, IDC_COMBO1, m_windowCtrl);
DDX_Control(pDX, IDC_STATIC8, m_video8);
DDX_Control(pDX, IDC_STATIC7, m_video7);
DDX_Control(pDX, IDC_STATIC6, m_video6);
DDX_Control(pDX, IDC_STATIC5, m_video5);
DDX_Radio(pDX, IDC_TCP, m_linktype);
DDX_Text(pDX, IDC_IPADDRESS, m_ipadd);
DDX_Text(pDX, IDC_SHOWNUM, m_shownum);
DDX_Radio(pDX, IDC_DELAY1, m_delaytype);
DDX_Radio(pDX, IDC_SHOWMODE1, m_showmode);
DDX_Radio(pDX, IDC_RADIOBFRAM0, m_bframenum);
DDX_Text(pDX, IDC_STATICFRAME, m_frameshow);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CClientdemoDlg, CDialog)
ON_MESSAGE(WM_MYCOMMAND,OnMyCommand)
//{{AFX_MSG_MAP(CClientdemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_STATIC5, OnStatic5)
ON_BN_CLICKED(IDC_STATIC7, OnStatic7)
ON_BN_CLICKED(IDC_STATIC6, OnStatic6)
ON_BN_CLICKED(IDC_STATIC8, OnStatic8)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_WM_HSCROLL()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_SHOWMODE2, OnShowmode2)
ON_BN_CLICKED(IDC_SHOWMODE1, OnShowmode1)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_RADIOBFRAM0, OnRadiobfram0)
ON_BN_CLICKED(IDC_RADIOBFRAM1, OnRadiobfram1)
ON_BN_CLICKED(IDC_RADIOBFRAM2, OnRadiobfram2)
ON_BN_CLICKED(IDC_BUTTON_CLEAN_BUFFER, OnButtonCleanBuffer)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER2, OnReleasedcaptureSlider2)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER3, OnReleasedcaptureSlider3)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER4, OnReleasedcaptureSlider4)
ON_CONTROL(STN_DBLCLK,IDC_STATIC5,OnDbStatic1)
ON_CONTROL(STN_DBLCLK,IDC_STATIC6,OnDbStatic2)
ON_CONTROL(STN_DBLCLK,IDC_STATIC7,OnDbStatic3)
ON_CONTROL(STN_DBLCLK,IDC_STATIC8,OnDbStatic4)
ON_BN_CLICKED(IDC_BUTTONDEFAULT, OnButtondefault)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientdemoDlg message handlers
void CALLBACK DrawFun(LONG StockHandle,HDC hDc,LONG nUser)
{
// if (StockHandle == 0)
{
//直接写
// TextOut(hDc,5,5,"abcdef",5);
}
}
void CALLBACK CapPicFun(long nPort,\
char * pBuf,long nSize,\
long nWidth,long nHeight,\
long nStamp,long nType,long nReceaved)
{
if(!((g_bCapPic) && (nPort == ipos)))
return;
CString csFile;
switch(nType)
{
case T_UYVY:
csFile="c:\\uyvy.bmp";
break;
case T_YV12:
csFile="c:\\yv12.bmp";
break;
case T_RGB32:
csFile="c:\\rgb.bmp";
break;
default:
return ;
}
MP4_ClientSavePicFile(pBuf,nSize,nWidth,nHeight,nType,csFile.GetBuffer(csFile.GetLength()));
g_bCapPic=FALSE;
}
BOOL CClientdemoDlg::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
MP4_ClientSetNetPort(5050,6050);
MP4_ClientStartup(WM_MYCOMMAND,this->m_hWnd);
// m_playtryl.SetRange(1,100,TRUE);
m_delaytype =3;
m_showmode = 0;
m_bframenum = 2;
UpdateData(FALSE);
nn1=nn2=nn3=nn4=-1;
m_iWndNum = -1;
m_windowCtrl.SetCurSel(m_iWndNum);
m_brightness.SetRange(0, 128,TRUE);
m_contrast.SetRange(0, 128,TRUE);
m_saturation.SetRange(0, 128,TRUE);
m_hue.SetRange(0, 128,TRUE);
m_brightness.SetPos(DEFAULTVAL);
m_contrast.SetPos(DEFAULTVAL);
m_saturation.SetPos(DEFAULTVAL);
m_hue.SetPos(DEFAULTVAL);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CClientdemoDlg::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 CClientdemoDlg::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 CClientdemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CALLBACK ReadDataCallBack(DWORD nPort,UCHAR *pPacketBuffer,DWORD nPacketSize)
{
TRACE("%d\n",nPacketSize);
}
void CClientdemoDlg::OnButton1()
{
CWnd* pButton1;
CString csFile;
pButton1 = (CButton*)GetDlgItem(IDC_BUTTON1);
pButton1->EnableWindow(FALSE);
UpdateData(TRUE);
if (m_showmode == 0)
{
MP4_ClientSetShowMode(NORMALMODE,0);
}
else
{
MP4_ClientSetShowMode(OVERLAYMODE,COLORREF(0xff00ff));
}
nn1=nn2=nn3=nn4 = -1;
int itemp = m_shownum;
char ips[256];
sprintf(ips,"%s",m_ipadd);
hWnd5 = m_video5.GetSafeHwnd();//
aa5.m_bRemoteChannel = 0;
switch(m_linktype)
{
case 0:
aa5.m_bSendMode = TCPMODE;
break;
case 1:
aa5.m_bSendMode = UDPMODE;
break;
case 2:
aa5.m_bSendMode = MULTIMODE;
break;
case 3:
aa5.m_bSendMode = DIALING;
break;
case 4:
aa5.m_bSendMode = AUDIODETACH;
break;
default:
aa5.m_bSendMode = TCPMODE;
break;
}
aa5.m_sIPAddress = ips;
//2003.12.2
//如果想只录像,而不进行解码,可以将m_hShowVideo设置成NULL
//If you just want to record without decode on client side,
//please set m_hShowVideo as NULL
#if defined RECORD_ONLY
aa5.m_hShowVideo = NULL;
#else
aa5.m_hShowVideo = hWnd5;
#endif
// add 2003.12.2
//m_nImgFormat 指明想要获取的图像格式
//依赖服务器端的设置。如果不设置,获取的是服务器的缺省格式
//m_nImgFormat indicates the picture format you get on the client side,
//It depends on the setting of Server side.
aa5.m_nImgFormat = 0; // request CIF format
// aa5.m_nImgFormat = 1; // request QCIF format
aa5.m_sUserName = "123";
aa5.m_sUserPassword="w";
aa5.m_bUserCheck = TRUE;
MP4_ClientSetTTL(64);
nn1 = MP4_ClientStart(&aa5,ReadDataCallBack);
if (nn1 == -1)
{
MessageBox("error");
return;
}
//
BOOL breturn;
breturn = MP4_ClientRigisterDrawFun(nn1,DrawFun,0);
switch(m_delaytype)
{
case 0:
MP4_ClientSetBufferNum(nn1,40);
MP4_ClientSetPlayDelay(nn1,580);
break;
case 1:
MP4_ClientSetBufferNum(nn1,15);
MP4_ClientSetPlayDelay(nn1,40);
break;
case 2:
MP4_ClientSetBufferNum(nn1,15);
MP4_ClientSetPlayDelay(nn1,0);
break;
case 3:
MP4_ClientSetBufferNum(nn1,0);
MP4_ClientSetPlayDelay(nn1,0);
break;
}
// MP4_ClientThrowBFrame(nn1,m_bframenum);
MP4_ClientSetCapPicCallBack(nn1,CapPicFun);
itemp --;
if (itemp<=0)
goto GOTOEND;
if (m_showmode == 1)
{
goto GOTOEND;
}
Sleep(200);
hWnd6 = m_video6.GetSafeHwnd();//
aa6.m_bRemoteChannel =1;
switch(m_linktype)
{
case 0:
aa6.m_bSendMode = TCPMODE;
break;
case 1:
aa6.m_bSendMode = UDPMODE;
break;
case 2:
aa6.m_bSendMode = MULTIMODE;
break;
case 3:
aa6.m_bSendMode = DIALING;
break;
case 4:
aa6.m_bSendMode = AUDIODETACH;
break;
default:
aa6.m_bSendMode = TCPMODE;
break;
}
aa6.m_sIPAddress = ips;
#if defined RECORD_ONLY
aa6.m_hShowVideo = NULL;
#else
aa6.m_hShowVideo = hWnd6;
#endif
aa6.m_nImgFormat = 0;
aa6.m_sUserName = "123";
aa6.m_sUserPassword="w";
aa6.m_bUserCheck = TRUE;
MP4_ClientSetTTL(32);
nn2 = MP4_ClientStart(&aa6,NULL);
if (nn2 == -1)
{
MessageBox("error");
return;
}
switch(m_delaytype)
{
case 0:
MP4_ClientSetBufferNum(nn2,40);
MP4_ClientSetPlayDelay(nn2,580);
break;
case 1:
MP4_ClientSetBufferNum(nn2,15);
MP4_ClientSetPlayDelay(nn2,30);
break;
case 2:
MP4_ClientSetBufferNum(nn2,15);
MP4_ClientSetPlayDelay(nn2,0);
break;
case 3:
MP4_ClientSetBufferNum(nn2,0);
MP4_ClientSetPlayDelay(nn2,0);
break;
}
// MP4_ClientThrowBFrame(nn2,m_bframenum);
MP4_ClientSetCapPicCallBack(nn2,CapPicFun);
itemp --;
if (itemp<=0)
goto GOTOEND;
Sleep(200);
hWnd7 = m_video7.GetSafeHwnd();//
aa7.m_bRemoteChannel = 2;
switch(m_linktype)
{
case 0:
aa7.m_bSendMode = TCPMODE;
break;
case 1:
aa7.m_bSendMode = UDPMODE;
break;
case 2:
aa7.m_bSendMode = MULTIMODE;
break;
case 3:
aa7.m_bSendMode = DIALING;
break;
case 4:
aa7.m_bSendMode = AUDIODETACH;
break;
default:
aa7.m_bSendMode = TCPMODE;
break;
}
aa7.m_sIPAddress = ips;
#if defined RECORD_ONLY
aa7.m_hShowVideo = NULL;
#else
aa7.m_hShowVideo = hWnd7;
#endif
aa7.m_nImgFormat = 0;
aa7.m_sUserName = "123";
aa7.m_sUserPassword="w";
aa7.m_bUserCheck = TRUE;
MP4_ClientSetTTL(64);
nn3 = MP4_ClientStart(&aa7,NULL);
if (nn3 == -1)
{
MessageBox("error");
return;
}
switch(m_delaytype)
{
case 0:
MP4_ClientSetBufferNum(nn3,40);
MP4_ClientSetPlayDelay(nn3,580);
break;
case 1:
MP4_ClientSetBufferNum(nn3,15);
MP4_ClientSetPlayDelay(nn3,30);
break;
case 2:
MP4_ClientSetBufferNum(nn3,15);
MP4_ClientSetPlayDelay(nn3,0);
break;
case 3:
MP4_ClientSetBufferNum(nn3,0);
MP4_ClientSetPlayDelay(nn3,0);
break;
}
// MP4_ClientThrowBFrame(nn3,m_bframenum);
MP4_ClientSetCapPicCallBack(nn3,CapPicFun);
itemp --;
if (itemp<=0)
goto GOTOEND;
Sleep(200);
hWnd8 = m_video8.GetSafeHwnd();//
aa8.m_bRemoteChannel = 3;
switch(m_linktype)
{
case 0:
aa8.m_bSendMode = TCPMODE;
break;
case 1:
aa8.m_bSendMode = UDPMODE;
break;
case 2:
aa8.m_bSendMode = MULTIMODE;
break;
case 3:
aa8.m_bSendMode = DIALING;
break;
case 4:
aa8.m_bSendMode = AUDIODETACH;
break;
default:
aa8.m_bSendMode = TCPMODE;
break;
}
aa8.m_sIPAddress = ips;
#if defined RECORD_ONLY
aa8.m_hShowVideo = NULL;
#else
aa8.m_hShowVideo = hWnd8;
#endif
aa8.m_nImgFormat = 0;
aa8.m_sUserName = "123";
aa8.m_sUserPassword="w";
aa8.m_bUserCheck = TRUE;
MP4_ClientSetTTL(64);
nn4 = MP4_ClientStart(&aa8,NULL);
if (nn4 == -1)
{
MessageBox("Error");
return;
}
switch(m_delaytype)
{
case 0:
MP4_ClientSetBufferNum(nn4,40);
MP4_ClientSetPlayDelay(nn4,580);
break;
case 1:
MP4_ClientSetBufferNum(nn4,15);
MP4_ClientSetPlayDelay(nn4,30);
break;
case 2:
MP4_ClientSetBufferNum(nn4,15);
MP4_ClientSetPlayDelay(nn4,0);
break;
case 3:
MP4_ClientSetBufferNum(nn4,0);
MP4_ClientSetPlayDelay(nn4,0);
break;
}
// MP4_ClientThrowBFrame(nn4,m_bframenum);
MP4_ClientSetCapPicCallBack(nn4,CapPicFun);
GOTOEND:
// remains=SetTimer(10,1000,NULL);
pButton1 = (CButton*)GetDlgItem(IDC_BUTTON2);
pButton1->EnableWindow(TRUE);
if(nn1 >= 0)
{
m_iWndNum = 1;
m_windowCtrl.SetCurSel(m_iWndNum-1);
OnSelchangeCombo1();
}
}
void CClientdemoDlg::OnButton2()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -