
// MultipleCameraDlg.h : header file

#pragma once
#include "afxwin.h"
#include <stdio.h>
#include "MVFGControl.h"
#include <list>

#define MAX_DEVICE_NUM          6
#define MAX_STREAM_NUM          4
#define BUFFER_NUMBER           3
#define TIMEOUT                 1000
#define DEVICE_INFO_LEN         256
#define MAX_LOGINFO_LEN         1024
using namespace std;

typedef struct _CAMERA_INFO_
{
    IFHANDLE          hInterface;               // ch:采集卡句柄
    DEVHANDLE         hDevice;                  // 相机句柄
    unsigned int      nCurIndex;                // 采集卡上的索引值
}CAMERA_INFO;

// CMultipleCameraDlg dialog
class CMultipleCameraDlg : public CDialog
{
// Construction
public:
	CMultipleCameraDlg(CWnd* pParent = NULL);	        // Standard constructor

// Dialog Data
	enum { IDD = IDD_MULTIPLECAMERA_DIALOG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

	HICON           m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

private:
    CComboBox               m_ctrlInterfaceCombo;                 // ch:枚举到的Interface | en:Enumerated Interface

    BOOL                    m_bCamCheck[MAX_DEVICE_NUM];
    BOOL                    m_bOpenIF;
    BOOL                    m_bOpenDevice;
    BOOL                    m_bStartGrabbing;
    int                     m_nTriggerMode;

    unsigned int            m_nInterfaceNum;
    IFHANDLE                m_hInterface;                              // ch:采集卡句柄

    CAMERA_INFO             m_stDevHandle[MAX_DEVICE_NUM];              // 设备句柄
    unsigned int            m_nDeviceNum;                               // 设备数量

    STREAMHANDLE            m_hStream[MAX_DEVICE_NUM];                    // 流通道句柄
    HWND                    m_hwndDisplay[MAX_DEVICE_NUM];              // 显示句柄
    CRect                   m_hwndRect[MAX_DEVICE_NUM];                // 显示窗口
    void*                   m_hGrabThread[MAX_DEVICE_NUM];              // 取流线程

    CListBox                m_ctrlListBoxInfo;

public:
    int                     m_nCurCameraIndex;

public:
    afx_msg void OnBnClickedEnumDevicesButton();
    afx_msg void OnBnClickedOpenDevicesButton();
    afx_msg void OnBnClickedCloseDevicesButton();
    afx_msg void OnBnClickedStartGrabbingButton();
    afx_msg void OnBnClickedStopGrabbingButton();
    afx_msg void OnClose();
    afx_msg void OnLbnDblclkOutputInfoList();

    virtual BOOL PreTranslateMessage(MSG* pMsg);

    void ThreadFun(int nCurCameraIndex);
    void PrintMessage( const char* pszFormat, ... );

    void ShowErrorMsg(CString csMessage, int nErrorNum);
private:
    bool PrintInterfaceInfo(unsigned int nInterfaceNum);
    bool PrintDeviceInfo(IFHANDLE hInterface, unsigned int nDeviceNum);
    void EnableControls(BOOL bIsCameraReady);

public:
    afx_msg void OnBnClickedEnumInterfaceButton();
    afx_msg void OnBnClickedOpenInterfaceButton();
    afx_msg void OnBnClickedCloseInterfaceButton();
};
