cli_softandhard.cpp
来自「用vb实现在线考试系统」· C++ 代码 · 共 874 行 · 第 1/2 页
CPP
874 行
// Cli_SoftAndHard.cpp : Defines the initialization routines for the DLL.
//
/*********************************************************
* v1: update on 6/16/2004
*
*
*
*
*********************************************************/
#include "stdafx.h"
#include "Cli_SoftAndHard.h"
#include "hikclient.h"
#include "VideoShow.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef unsigned int UINT;
#define WM_MYCOMMAND WM_USER+1
/*************************
定义全局变量定义
**************************/
CLIENT_VIDEOINFO aa5;
int nn1=-1;
BOOL g_bCapPic;
WORD testnum=0;
char filename[256];
int count;
HWND hWnd1,hWnd2,hWnd3,hWnd4,hWnd5,hWnd6,hWnd7,hWnd8;
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;
UINT remains=0;
long channelcount;
long pDeviceTotal;
LPSWITCHSHOW SwitchParams;
LPSHOWPARAMS ShowParams;
CVideoShow* pdlg;
bool bInitDlg = false;
int iCurrentWin;
HWND myHwnd; //发送消息的句柄
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CCli_SoftAndHardApp
BEGIN_MESSAGE_MAP(CCli_SoftAndHardApp, CWinApp)
//{{AFX_MSG_MAP(CCli_SoftAndHardApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCli_SoftAndHardApp construction
CCli_SoftAndHardApp::CCli_SoftAndHardApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCli_SoftAndHardApp object
CCli_SoftAndHardApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CCli_SoftAndHardApp initialization
BOOL CCli_SoftAndHardApp::InitInstance()
{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
COleObjectFactory::RegisterAll();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// Special entry points required for inproc servers
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxDllGetClassObject(rclsid, riid, ppv);
}
STDAPI DllCanUnloadNow(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxDllCanUnloadNow();
}
// by exporting DllRegisterServer, you can use regsvr.exe
STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
COleObjectFactory::UpdateRegistryAll();
return S_OK;
}
////////////////////////////////////////////////////////////////////
/***************************************
抓图回调函数
*****************************************/
void CALLBACK CapPicFun(long nPort,\
char * pBuf,long nSize,\
long nWidth,long nHeight,\
long nStamp,long nType,long nReceaved)
{
//g_bCapPic为false,ipos为0
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;
}
/*********************************************
获取客户端状态。
StockHandle:MP4_ClientStart成功返回的值。
-1:无效
1:正在连接
2:开始接收图象
3:异常退出
4:接收完毕,退出
5:无法联系服务端
**********************************************/
long _stdcall Cli_ClientGetState(LONG StockHandle)
{
return MP4_ClientGetState(StockHandle);
}
/****************************************
初始化解码卡,得到解码卡通道个数
******************************************/
int _stdcall Cli_ClientInitDevice_Card()
{
int i;
i = MP4_ClientInitDevice_Card(&pDeviceTotal);
// CString tmpStr;
// tmpStr.Format("MP4_ClientInitDevice_Card函数返回值为: %d 个数为%d", i, pDeviceTotal);
// AfxMessageBox(tmpStr);
return pDeviceTotal;
}
/**********************************************
释放解码卡资源
***********************************************/
int _stdcall Cli_ClientReleaseDevice_Card()
{
return MP4_ClientReleaseDevice_Card();
}
/********************************************
初始化解码卡使用的OVERLAY表面
*********************************************/
int _stdcall Cli_ClientInitDDraw_Card(HWND hWnd)
{
return MP4_ClientInitDDraw_Card(hWnd,COLORREF(0xff00ff));
}
/*********************************************
停止客户端。
StockHandle:MP4_ClientStart成功返回的值。
返回TRUE表示成功,返回FALSE表示失败。
***********************************************/
bool _stdcall Cli_ClientStop(LONG StockHandle)
{
return MP4_ClientStop(StockHandle);
}
/*************************************************
获取服务端的通道数。
返回0表示失败,其他值表示通道数。
m_sIPAddress:服务端的IP地址。
**************************************************/
int _stdcall Cli_GetServerChannelNum(char *ip)
{
return MP4_ClientGetServerChanNum(ip);
}
/****************************************************
给服务端发送命令字符串。
返回0表示失败,其他值表示通道数。
m_sIPAddress:服务端的IP地址。
m_sCommand:消息缓冲区指针。
m_wLen:消息缓冲区长度。 m_wLen必须小于900字节
*****************************************************/
bool _stdcall Cli_SendMessageToServer(char *ip,char *Message)
{
char ctemp[256];
char sendcont[500];
MP4_ClientSetWait(3000,10);
for(int i=0;i<100;i++)
{
memset(sendcont,0,500);
sprintf(ctemp,"%s",ip);
sprintf(sendcont,"%s send content %d",Message,testnum);
testnum++;
if (testnum > 200)
testnum=0;
return MP4_ClientCommandtoServer((LPCTSTR)ctemp,sendcont,400);
Sleep(100);
}
}
/************************************************************
恢复解码卡使用的OVERLAY表面
*************************************************************/
int _stdcall Cli_ClientRestoreSurface_Card()
{
return MP4_ClientRestoreSurface_Card();
}
int _stdcall Cli_ClientRefreshSurface_Card()
{
return MP4_ClientRefreshSurface_Card();
}
/*****************************************************
软件播放函数的实现
******************************************************/
long _stdcall Cli_PlaySoft(HWND hWnd,char m_bRemoteChannel,
char m_linktype,char *ip,
char *m_sUserName,char *m_sUserPassword,
bool m_bUserCheck)
{
CLIENT_VIDEOINFO aa5;
aa5.m_bRemoteChannel = m_bRemoteChannel;
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;
default:
aa5.m_bSendMode = TCPMODE;
break;
}
aa5.m_sIPAddress = ip;
aa5.m_hShowVideo = hWnd;
aa5.m_sUserName = m_sUserName;
aa5.m_sUserPassword=m_sUserPassword;
aa5.m_bUserCheck = m_bUserCheck;
MP4_ClientSetTTL(64);
nn1 = MP4_ClientStart(&aa5,NULL);
return nn1;
}
/*******************************************
硬件播放的实现
********************************************/
long _stdcall Cli_PlayHard(char m_bRemoteChannel,char m_linktype,
char *ip,char *m_sUserName,
char *m_sUserPassword,
bool m_bUserCheck,
long left,
long top,
long width,
long height)
{
CLIENT_CARDINFO aa5;
aa5.m_bRemoteChannel = m_bRemoteChannel;
switch(m_linktype)
{
case 0:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?