// ICubeSDKSampleDlg.cpp : Implementierungsdatei
//

#include "stdafx.h"
#include "ICubeSDKSample.h"
#include "ICubeSDKSampleDlg.h"
#include "NET_ICube_API.h"

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

//---------------------------------------------------------------------
// Globals

ROI_PROPERTY	roi_prop;


int g_ModIndexCam[10];

int g_iCurrentCam	= 0;
int g_iCurrentFormat= 0;
int g_iBinSkipParam	= BIN_SKIP_OFF;
int g_iBinSkipMode	= MODE_BIN;
int g_iTriggerMode	= TRIG_SW_START;

unsigned long g_iTriggerDelay	= 0;

bool bGrabCallback=false;

static struct symbolic_list formatlist[] = {
	{ "320x240" },
	{ "640x480" },
	{ "752x480" },
	{ "800x600" },
	{ "1024x768" },
	{ "1280x1024" },
	{ "1600x1200" },
	{ "2048x1536" },
	{ "2592x1944" }, 
	{ "3840x2748" }, 
	{ "1920x1200" }, 
	{ NULL }
};
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg-Dialogfeld für Anwendungsbefehl "Info"

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialogfelddaten
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// Vom Klassenassistenten generierte Überladungen virtueller Funktionen
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterstützung
	//}}AFX_VIRTUAL

// Implementierung
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)
		// Keine Nachrichten-Handler
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CICubeSDKSampleDlg Dialogfeld

CICubeSDKSampleDlg::CICubeSDKSampleDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CICubeSDKSampleDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CICubeSDKSampleDlg)
	//}}AFX_DATA_INIT
	// Beachten Sie, dass LoadIcon unter Win32 keinen nachfolgenden DestroyIcon-Aufruf benötigt
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CICubeSDKSampleDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CICubeSDKSampleDlg)
	DDX_Control(pDX, IDC_COMBO_FORMAT, m_ComboFormat);
	DDX_Control(pDX, IDC_COMBO_CAM, m_ComboCam);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CICubeSDKSampleDlg, CDialog)
	//{{AFX_MSG_MAP(CICubeSDKSampleDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDOPEN, OnButtonOpen)
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
	ON_BN_CLICKED(IDC_BUTTON_INIT, OnButtonInit)
	ON_CBN_SELCHANGE(IDC_COMBO_FORMAT, OnSelchangeComboFormat)
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
	ON_BN_CLICKED(IDC_BUTTON_SAVE_BMP, OnButtonSaveBmp)
	ON_BN_CLICKED(IDC_BUTTON_GRAB_CALLBACK, OnButtonGrabCallback)
	ON_BN_CLICKED(IDC_CHECK_ENABLE_TRIGGER, OnCheckEnableTrigger)
	ON_BN_CLICKED(IDC_RADIO_SOFTWARE_TRIGGER, OnRadioSoftwareTrigger)
	ON_BN_CLICKED(IDC_RADIO_HARDWARE_TRIGGER, OnRadioHardwareTrigger)
	ON_BN_CLICKED(IDC_BUTTON_DO_SW_TRIGGER, OnButtonDoSwTrigger)
	ON_BN_CLICKED(IDC_BUTTON_VID_CONTROLS, OnButtonVidControls)
	ON_BN_CLICKED(IDC_CHECK_HOR, OnCheckHor)
	ON_BN_CLICKED(IDC_CHECK_VER, OnCheckVer)
	ON_BN_CLICKED(IDC_BUTTON_VIEW_MODE, OnButtonViewMode)
	ON_MESSAGE(WM_VIEWMODE_DLG,OnViewModeDlgMsg)
	ON_MESSAGE(WM_VIDCONTROL_DLG,OnVidControlDlgMsg)
	ON_BN_CLICKED(IDC_BUTTON_TRIG_DELAY, OnButtonTrigDelay)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_BUTTON_Save_AVI, OnBUTTONSaveAVI)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CICubeSDKSampleDlg Nachrichten-Handler

BOOL CICubeSDKSampleDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Hinzufügen des Menübefehls "Info..." zum Systemmenü.

	// IDM_ABOUTBOX muss sich im Bereich der Systembefehle befinden.
	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);
		}
	}

	// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt
	//  wenn das Hauptfenster der Anwendung kein Dialogfeld ist
	SetIcon(m_hIcon, TRUE);			// Großes Symbol verwenden
	SetIcon(m_hIcon, FALSE);		// Kleines Symbol verwenden
	
	CheckRadioButton( IDC_RADIO_SOFTWARE_TRIGGER,IDC_RADIO_HARDWARE_TRIGGER, IDC_RADIO_SOFTWARE_TRIGGER);

	memset(&roi_prop,  0,sizeof(ROI_PROPERTY));

#ifndef LIBFILE
	if ( LoadICubeApi("ICubeSDK.dll") != IC_SUCCESS )
	{
		AfxMessageBox("Can not find ICubeSDK.dll");
		PostMessage(WM_QUIT, NULL, NULL);
		return FALSE;
	}
#endif	

	SetTimer(1, 100, 0);


	return TRUE;  // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}

void CICubeSDKSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// Wollen Sie Ihrem Dialogfeld eine Schaltfläche "Minimieren" hinzufügen, benötigen Sie 
//  den nachstehenden Code, um das Symbol zu zeichnen. Für MFC-Anwendungen, die das 
//  Dokument/Ansicht-Modell verwenden, wird dies automatisch für Sie erledigt.

void CICubeSDKSampleDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // Gerätekontext für Zeichnen

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Symbol in Client-Rechteck zentrieren
		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;

		// Symbol zeichnen
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// Die Systemaufrufe fragen den Cursorform ab, die angezeigt werden soll, während der Benutzer
//  das zum Symbol verkleinerte Fenster mit der Maus zieht.
HCURSOR CICubeSDKSampleDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CICubeSDKSampleDlg::OnClose() 
{

	KillTimer(1);
	
	OnButtonClose();	// try close

#ifndef LIBFILE
	UnloadICubeApi();
#endif

	CDialog::OnClose();
}

//---------------------------------------------------------------------
//
// callback which is used for grabbing raw or RGB24 data from camera.
//
long CALLBACK MyCallbackFunc(BYTE * pBuffer, long lBufferSize,PVOID pContext )
{
	
	if(bGrabCallback==true)
	{
		bGrabCallback=false;

		FILE *fp;
		char fname[40];
		sprintf(fname, "sample.raw");
		fp = fopen(fname, "wb");
		fwrite(pBuffer, sizeof(BYTE), lBufferSize, fp);
		fclose(fp);
	}

	return 42;
}
//---------------------------------------------------------------------
// 
void CICubeSDKSampleDlg::OnButtonInit() 
{
int numDevices = 0;
int nStat;
int nlist=10;

	numDevices=ICubeSDK_Init ();
	if(numDevices<1)
	{
		AfxMessageBox("No Devices!");
		return;
	}

	CString s;
	char CamName[NETCAM_NAME_LENGTH];

	m_ComboCam.ResetContent();
	for(int i=0; i<numDevices; i++)
	{
		nStat = ICubeSDK_GetName(i, CamName);
		if ( nStat != IC_SUCCESS )
		{
			if(nStat ==IC_DRIVER_VERSION)
				DispError("Error driver version mismatch ", nStat);
			else
				DispError("Error getting model name ", nStat);
			return;
		}
		s.Format("%d. %s", i+1, CamName);
		m_ComboCam.AddString(s);
	}
	g_iCurrentCam = 0;
	m_ComboCam.SetCurSel(0);	
}
//---------------------------------------------------------------------
// 
void CICubeSDKSampleDlg::OnButtonOpen() 
{
int nStat;
int nlist=10;

	g_iCurrentCam = m_ComboCam.GetCurSel();		// get the Camera to open

	nStat=ICubeSDK_Open(g_iCurrentCam);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error open Cam", nStat);
			return;
	}  	
  
	nStat=ICubeSDK_GetModeList(g_iCurrentCam,&nlist,g_ModIndexCam);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error GetModeList", nStat);
			return;
	}

	m_ComboFormat.ResetContent();
	for(int i = 0 ;i< nlist ;i++)
	{
		m_ComboFormat.InsertString(i,formatlist[g_ModIndexCam[i]].name);
		m_ComboFormat.SetItemData(i, (int)g_ModIndexCam[i]);
	}
	
	nStat=ICubeSDK_GetMode(g_iCurrentCam,&g_iCurrentFormat);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error GetMode", nStat);
			return;
	}

	for (i = 0; i < nlist; i++)
		{
			if ( (int)g_iCurrentFormat == (int)m_ComboFormat.GetItemData(i) )
			{
				m_ComboFormat.SetCurSel(i);
				break;
			}
		}

	InitTriggerDelay();
}
//---------------------------------------------------------------------
// 
void CICubeSDKSampleDlg::OnSelchangeComboFormat() 
{
	(int)g_iCurrentFormat = (int)m_ComboFormat.GetItemData(m_ComboFormat.GetCurSel());	
}
//---------------------------------------------------------------------
// 
void CICubeSDKSampleDlg::OnButtonClose() 
{
	m_ComboFormat.ResetContent();

	if(ICubeSDK_IsOpen(g_iCurrentCam))
	{
		int nStat=ICubeSDK_Close(g_iCurrentCam);
		if ( nStat != IC_SUCCESS )
		{
				DispError("Error close Cam", nStat);
				return;
		} 	
	}
}
//---------------------------------------------------------------------
// 
void CICubeSDKSampleDlg::OnButtonStart() 
{
	StartCamera();		
}
//---------------------------------------------------------------------
// 
// ICubeSDK_SetMode() sets the basis format (e.g. 640x480)
// ICubeSDK_SetBinSkip() sets Binning/Skipping on the basis format.
// If ICubeSDK_SetBinSkip->nParameter==0, ICubeSDK_SetBinSkip has
// no effect.
// ICubeSDK_SetResolution sets the Region of interest.
// If roi_prop.bEnabled==0,ICubeSDK_SetResolution has
// no effect.  
// It is not possible to set bin/skip and Roi.
// 
void CICubeSDKSampleDlg::StartCamera(void)
{
int nStat;
	
	// optional to set format, different from highest format
	nStat=ICubeSDK_SetMode(g_iCurrentCam,g_iCurrentFormat);
	if ( nStat != IC_SUCCESS ){
			DispError("Error SetMode", nStat);
			return;
	}

	// optional to set bin skip mode
	nStat=ICubeSDK_SetBinSkip(g_iCurrentCam,g_iBinSkipParam,g_iBinSkipMode);
	if ( nStat != IC_SUCCESS ){
			DispError("Error SetBinSkip", nStat);
			return;
	}

	// optional to set region of interest mode
	nStat=ICubeSDK_SetResolution(g_iCurrentCam,&roi_prop);
	if ( nStat != IC_SUCCESS ){
			DispError("Error SetRoi", nStat);
			return;
	}

	// necessary, if Callback-Flag==true 
	//nStat=ICubeSDK_SetCallback(g_iCurrentCam,CALLBACK_RAW,MyCallbackFunc,NULL);
	nStat=ICubeSDK_SetCallback(g_iCurrentCam,CALLBACK_RGB,MyCallbackFunc,NULL);
	if ( nStat != IC_SUCCESS ){
			DispError("Error SetCallback", nStat);
			return;
	}

    nStat=ICubeSDK_Start(g_iCurrentCam,NULL,true,true);
	//nStat=ICubeSDK_Start(g_iCurrentCam,NULL,true,false);
	if ( nStat != IC_SUCCESS ){
			DispError("Error Start", nStat);
			return;
	}

}
//---------------------------------------------------------------------
// 
void CICubeSDKSampleDlg::OnButtonStop() 
{
	int nStat=ICubeSDK_Stop(g_iCurrentCam);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error Stop", nStat);
			return;
	}	

	// Stop resets the trigger
	int nTrigMode;
	nStat=ICubeSDK_GetTrigger(g_iCurrentCam,&nTrigMode);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error GetTrigger", nStat);
			return;
	}	
	if(nTrigMode==TRIG_STOP)
	{
			CButton		*pCheckBox;
			pCheckBox = (CButton *)GetDlgItem(IDC_CHECK_ENABLE_TRIGGER);
			pCheckBox->SetCheck(0);
	}

}
//---------------------------------------------------------------------
// Grab controls

void CICubeSDKSampleDlg::OnButtonSaveBmp() 
{
	// Filename-extension defines the file-format (jpg||bmp||tif)

	int nStat=ICubeSDK_SaveToFile(g_iCurrentCam,"test.bmp");
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error Save", nStat);
			return;
	}	
}

void CICubeSDKSampleDlg::OnButtonGrabCallback() 
{
	// Enable grab in callback

	bGrabCallback=true;	
}
//---------------------------------------------------------------------
// Trigger controls

void CICubeSDKSampleDlg::OnCheckEnableTrigger() 
{
int nStat;

	if(IsDlgButtonChecked(IDC_CHECK_ENABLE_TRIGGER ))
	{
		nStat=ICubeSDK_SetTrigger(g_iCurrentCam,g_iTriggerMode);
		if ( nStat != IC_SUCCESS )
		{
				DispError("Error SetTrigger", nStat);
				return;
		}
	}
	else
	{
		nStat=ICubeSDK_SetTrigger(g_iCurrentCam,TRIG_STOP);
 		if ( nStat != IC_SUCCESS )
		{
				DispError("Error SetTrigger", nStat);
				return;
		}
	}
}

void CICubeSDKSampleDlg::OnRadioSoftwareTrigger() 
{
	g_iTriggerMode=TRIG_SW_START;	
}

void CICubeSDKSampleDlg::OnRadioHardwareTrigger() 
{
	g_iTriggerMode=TRIG_HW_START;	
}

void CICubeSDKSampleDlg::OnButtonDoSwTrigger() 
{
	if(g_iTriggerMode==TRIG_HW_START)
	{
		AfxMessageBox("Wrong Trigger mode!");
		return;
	}

	if(IsDlgButtonChecked(IDC_CHECK_ENABLE_TRIGGER ))
	{
		int nStat=ICubeSDK_SetTrigger(g_iCurrentCam,TRIG_SW_DO);
		if ( nStat != IC_SUCCESS )
		{
				DispError("Error SetTrigger", nStat);
				return;
		}
	}
	else
	{
		AfxMessageBox("Enable Trigger mode first!");
	}
	
}
//---------------------------------------------------------------------
// Trigger Delay (Strobe Delay,Strobe Length are working analog)

void CICubeSDKSampleDlg::InitTriggerDelay(void)
{
int nStat;

PARAM_PROPERTY param_prop;

CSliderCtrl *pSlider;

    nStat=ICubeSDK_GetCamParameterRange(g_iCurrentCam,REG_TRIGGER_DELAY,&param_prop);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error GetCamParameterRange", nStat);
			return;
	}

	if(param_prop.bEnabled)				// Control is supported
	{
		if(ICubeSDK_GetCamParameter(g_iCurrentCam,REG_TRIGGER_DELAY,&g_iTriggerDelay)!= IC_SUCCESS )
		if ( nStat != IC_SUCCESS )
		{
				DispError("Error GetCamParameter", nStat);
				return;
		}

		pSlider = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_TRIG_DELAY);
		pSlider->SetRange(param_prop.nMin,param_prop.nMax);
		pSlider->SetPos(g_iTriggerDelay);

		SetDlgItemInt(IDC_EDIT_TRIG_DELAY,g_iTriggerDelay,FALSE);
	}
}

void CICubeSDKSampleDlg::OnButtonTrigDelay() 
{

	int nStat=ICubeSDK_SetCamParameter(g_iCurrentCam,REG_TRIGGER_DELAY,g_iTriggerDelay);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error SetTrigger", nStat);
			return;
	}
}

void CICubeSDKSampleDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CSliderCtrl *pSlider = (CSliderCtrl *)pScrollBar;

	int nNewVal=pSlider->GetPos();

	switch(pSlider->GetDlgCtrlID())
	{
	case IDC_SLIDER_TRIG_DELAY:
		g_iTriggerDelay=nNewVal;
		SetDlgItemInt(IDC_EDIT_TRIG_DELAY,g_iTriggerDelay,FALSE);
		break;
	default:
		break;
	}	
	
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

//---------------------------------------------------------------------
// Flip controls

void CICubeSDKSampleDlg::OnCheckHor() 
{
	if(IsDlgButtonChecked(IDC_CHECK_HOR))		// Flip horizontal
	{
		if (ICubeSDK_SetCamParameter(g_iCurrentCam,REG_FLIPPED_H,ON)!= IC_SUCCESS )
				AfxMessageBox("Error SetCamParameter");
	}
	else
	{
		if (ICubeSDK_SetCamParameter(g_iCurrentCam,REG_FLIPPED_H,OFF)!= IC_SUCCESS )
				AfxMessageBox("Error SetCamParameter");
	}   	
}


void CICubeSDKSampleDlg::OnCheckVer() 
{
	if(IsDlgButtonChecked(IDC_CHECK_VER))		// Flip vertical
	{
		if (ICubeSDK_SetCamParameter(g_iCurrentCam,REG_FLIPPED_V,ON)!= IC_SUCCESS )
				AfxMessageBox("Error SetCamParameter");
	}
	else
	{
		if (ICubeSDK_SetCamParameter(g_iCurrentCam,REG_FLIPPED_V,OFF)!= IC_SUCCESS )
				AfxMessageBox("Error SetCamParameter");
	}   	
	
}

//---------------------------------------------------------------------
// Child Dialogs

void CICubeSDKSampleDlg::OnButtonVidControls() 
{
	if(ICubeSDK_IsOpen(g_iCurrentCam))
	{
		m_pVidControlDlg = new CICubeSDKVidControlDlg(this);
		m_pVidControlDlg->Create(IDD_DIALOG_VID_CONTROLS,this);
	}
	else
	{
		AfxMessageBox("Camera not open!");
	}

}

void CICubeSDKSampleDlg::OnButtonViewMode() 
{
	if(ICubeSDK_IsOpen(g_iCurrentCam))
	{
		m_pViewModeDlg = new CICubeSDKViewModeDlg(this);
		m_pViewModeDlg->Create(IDD_DIALOG_VIEWMODE,this);

	}
	else
	{
		AfxMessageBox("Camera not open!");
	}	
}

//---------------------------------------------------------------------
// Message Handler from Child Dialogs

LONG CICubeSDKSampleDlg::OnViewModeDlgMsg(WPARAM wP, LPARAM lP)
{

	if(wP==WM_CANCELMODE)
		{
		if (m_pViewModeDlg != NULL)
			{
				m_pViewModeDlg->DestroyWindow();
				delete m_pViewModeDlg;
				m_pViewModeDlg = NULL;
			}
		}
		else if(wP==WM_DEVMODECHANGE)
		{
			StartCamera();	// Restart Camera
		}
		
	return 0;
}

LONG CICubeSDKSampleDlg::OnVidControlDlgMsg(WPARAM wP, LPARAM lP)
{

	if (m_pVidControlDlg != NULL)
		{
			m_pVidControlDlg->DestroyWindow();
			delete m_pVidControlDlg;
			m_pVidControlDlg = NULL;
		}
		
	return 0;
}
//---------------------------------------------------------------------
//
void CICubeSDKSampleDlg::DispError(char *pstr, int code)
{
	char str[256];
	sprintf(str, "%s (Error code : %d)", pstr, code);
	AfxMessageBox(str);
}
//---------------------------------------------------------------------
//
void CICubeSDKSampleDlg::OnBUTTONSaveAVI() 
{
int nSeconds=1;

	int nStat=ICubeSDK_SaveAvi(g_iCurrentCam,"test.avi",AVI_DIB,nSeconds);
	if ( nStat != IC_SUCCESS )
	{
			DispError("Error Save Avi", nStat);
			return;
	}	
}
//---------------------------------------------------------------------
//
void CICubeSDKSampleDlg::OnTimer(UINT nIDEvent) 
{
	
	if(ICubeSDK_IsStarted(g_iCurrentCam))
    {
        int nBadFrames,nGoodFrames;
        ICubeSDK_GetBrokenFrames(g_iCurrentCam,&nBadFrames);
        ICubeSDK_GetGoodFrames(g_iCurrentCam,&nGoodFrames);

		SetDlgItemInt(IDC_BADFRAMES,nBadFrames,FALSE);
		SetDlgItemInt(IDC_GOODFRAMES,nGoodFrames,FALSE);
    }
	CDialog::OnTimer(nIDEvent);
}
//---------------------------------------------------------------------


