📄 multicard.cpp
字号:
// Multicard.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Multicard.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//======== Add for ver5.2, begin =================
typedef struct tagSAVEDATA
{
VideoStandard standard;
int source;
long brightness;
long contrast;
long hue;
long saturation;
VideoSubType subtype;
LONG width;
LONG height;
} SAVEDATA;
//将卡的属性设置成上次退出时的状态
bool ResetParame(int iCardID)
{
SAVEDATA SaveData;
HRESULT hr;
BOOL bConnectOk;
VIDEOSTREAMINFO vsi;
FILE * fp;
char szFileName[20];
hr = DSStream_IsConnected(iCardID, &bConnectOk);
if(FAILED(hr) || !bConnectOk)
return false;
//从文件读入数据
sprintf(szFileName, "c:\\SaveData.%02d", iCardID);
fp = fopen(szFileName, "rb");
if(!fp)
return false;
fread(&SaveData, sizeof(SAVEDATA), 1, fp);
fclose(fp);
//设置视频制式
DSStream_SetVideoStandard(iCardID, SaveData.standard);
//设置视频源
DSStream_RouteInPinToOutPin(iCardID, SaveData.source, 0);
//设置视频属性:亮度、对比度、色度、饱和度
DSStream_SetVideoPropertyValue(iCardID, VideoProperty_Brightness, SaveData.brightness);
DSStream_SetVideoPropertyValue(iCardID, VideoProperty_Contrast, SaveData.contrast);
DSStream_SetVideoPropertyValue(iCardID, VideoProperty_Hue, SaveData.hue);
DSStream_SetVideoPropertyValue(iCardID, VideoProperty_Saturation, SaveData.saturation);
//设置视频格式:视频格式、宽、高
DSStream_GetVideoInfo(iCardID, &vsi, PREVIEW);
vsi.subtype = SaveData.subtype;
vsi.bmiHeader.biWidth = SaveData.width;
vsi.bmiHeader.biHeight= SaveData.height;
DSStream_DisconnectPin(iCardID, PREVIEW);
DSStream_SetVideoInfo(iCardID, vsi, PREVIEW);
DSStream_ConnectPin(iCardID, PREVIEW);
return true;
}
//保存卡的当前属性,以备下次连接时重新设回
bool SaveParame(int iCardID)
{
SAVEDATA SaveData;
HRESULT hr;
BOOL bConnectOk;
VIDEOSTREAMINFO vsi;
VIDEOPROPERTYRANGE vpr;
FILE * fp;
char szFileName[20];
hr = DSStream_IsConnected(iCardID, &bConnectOk);
if(FAILED(hr) || !bConnectOk)
return false;
//保存视频格式:视频格式、宽、高
DSStream_GetVideoInfo(iCardID, &vsi, PREVIEW);
SaveData.subtype = vsi.subtype;
SaveData.width = vsi.bmiHeader.biWidth;
SaveData.height = vsi.bmiHeader.biHeight;
//保存视频制式
DSStream_GetVideoStandard(iCardID, &SaveData.standard, NULL);
//保存视频源
DSStream_WhatInPinRouteToOutPin(iCardID, 0, (long*)&SaveData.source);
//保存亮度
DSStream_GetVideoPropertyValue(iCardID, VideoProperty_Brightness, &vpr);
SaveData.brightness = vpr.lValue;
//保存对比度
DSStream_GetVideoPropertyValue(iCardID, VideoProperty_Contrast, &vpr);
SaveData.contrast = vpr.lValue;
//保存色度
DSStream_GetVideoPropertyValue(iCardID, VideoProperty_Hue, &vpr);
SaveData.hue = vpr.lValue;
//保存饱和度
DSStream_GetVideoPropertyValue(iCardID, VideoProperty_Saturation, &vpr);
SaveData.saturation = vpr.lValue;
//保存参数到文件
sprintf(szFileName, "c:\\SaveData.%02d", iCardID);
fp = fopen(szFileName, "wb");
if(!fp)
return false;
fwrite(&SaveData, sizeof(SAVEDATA), 1, fp);
fclose(fp);
return true;
}
//======== Add for ver5.2, end ===================
/////////////////////////////////////////////////////////////////////////////
// CMulticardApp
BEGIN_MESSAGE_MAP(CMulticardApp, CWinApp)
//{{AFX_MSG_MAP(CMulticardApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_COMMAND(ID_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMulticardApp construction
CMulticardApp::CMulticardApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMulticardApp object
CMulticardApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMulticardApp initialization
BOOL CMulticardApp::InitInstance()
{
HRESULT hr;
int iCardNumber;
//初始化SDK
DSStream_Initialize();
hr = DSStream_GetCardNumber(&iCardNumber);
if(FAILED(hr) || iCardNumber<=0)
{
AfxMessageBox("SDK初始化失败 或 无可用的卡", MB_OK|MB_ICONSTOP, 0);
ExitInstance();
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.
CMDIFrameWnd* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
// create main MDI frame window
if (!pFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
// try to load shared MDI menus and accelerator table
//TODO: add additional member variables and load calls for
// additional menu types your application may need.
HINSTANCE hInst = AfxGetResourceHandle();
m_hMDIMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_MULTICTYPE));
m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_MULTICTYPE));
// The main window has been initialized, so show and update it.
m_nCmdShow = SW_SHOWMAXIMIZED;
pFrame->SetWindowText("10Moons SDK2000 & 4Video(Plus) 开发包 VC++ Sample [ver 5.2]");
pFrame->ShowWindow(m_nCmdShow);
pFrame->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMulticardApp message handlers
int CMulticardApp::ExitInstance()
{
//释放SDK资源
DSStream_Uninitialize();
//TODO: handle additional resources you may have added
if (m_hMDIMenu != NULL)
FreeResource(m_hMDIMenu);
if (m_hMDIAccel != NULL)
FreeResource(m_hMDIAccel);
return CWinApp::ExitInstance();
}
void CMulticardApp::OnFileNew()
{
CChildFrame * pChildFrame;
HRESULT hr;
int id;
BOOL bIsConnected = TRUE;
int iCardNumber;
char szDeviceName[MAX_DEVICE_NUM][MAX_DEVICE_NAME_LEN];
const char sz10Moons[] = {"10Moons"};
//寻找可用的卡,剔除非10Moons卡
hr = DSStream_EnumVideoCaptureDev(szDeviceName, &iCardNumber);
if(FAILED(hr))
{
AfxMessageBox("枚举失败", MB_OK, 0);
return;
}
for(id=0; id<iCardNumber; id++)
{
szDeviceName[id][7] = '\0';
hr = DSStream_IsConnected(id, &bIsConnected);
if(FAILED(hr))
{
bIsConnected = TRUE;
break;
}
if(_stricmp(szDeviceName[id], sz10Moons) != 0)
{
bIsConnected = TRUE;
continue;
}
if(!bIsConnected)
break;
}
//无可用的卡
if(bIsConnected || id>=iCardNumber)
{
AfxMessageBox("无可用的卡", MB_OK, 0);
return;
}
//连接卡:默认使用 Preview 模式
const BOOL bOverlay = FALSE;
hr = DSStream_ConnectDevice(id, bOverlay);
if(FAILED(hr))
{
AfxMessageBox("连接视频卡失败!", MB_OK, 0);
return;
}
// create a new MDI child window
CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
pChildFrame = (CChildFrame *) pFrame->CreateNewChild(
RUNTIME_CLASS(CChildFrame), IDR_MULTICTYPE, m_hMDIMenu, m_hMDIAccel);
//将卡号传给 CChildFrame 类的成员变量 m_iCardID
if(pChildFrame && IsWindow(pChildFrame->m_hWnd))
{
pChildFrame->m_iCardID = id;
pChildFrame->m_bOverlay = bOverlay;
DSStream_SetOwnerWnd(id, pChildFrame->m_hWnd);
DSStream_SetMessageDrain(id, pChildFrame->m_hWnd);
DSStream_SetNotifyWindow(id, pChildFrame->m_hWnd, UM_VIDEO_ERROR_NOTIFY);
//======== Add for ver5.2, begin =================
//将卡的属性设置成上次退出时的状态
ResetParame(id);
//======== Add for ver5.2, end ===================
pChildFrame->SendMessage(WM_COMMAND, ID_NORMALSIZE);
char szCaption[10];
sprintf(szCaption, "%d号卡", id);
pChildFrame->SetWindowText(szCaption);
}
}
/////////////////////////////////////////////////////////////////////////////
// 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)
// No message handlers
//}}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()
// App command to run the dialog
void CMulticardApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CMulticardApp message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -