#include "stdafx.h"
#include "devwdm.h"
#include "VCsample.h"
#include "VCsampleDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CAboutDlg : public CDialog
{
public:
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()
/
// CVCsampleDlg dialog
CVCsampleDlg::CVCsampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVCsampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVCsampleDlg)
m_chkMirror = FALSE;
m_chkFlip = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVCsampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVCsampleDlg)
DDX_Control(pDX, IDC_BUTTON_FREEZE, m_btnFreeze);
DDX_Control(pDX, IDC_BUTTON_CAPTURE, m_btnCapture);
DDX_Control(pDX, IDC_BUTTON_SNAP, m_btnSnap);
DDX_Control(pDX, IDC_BUTTON_START, m_btnStartPreview);
DDX_Control(pDX, IDC_VIDEO_WND, m_hVideoCapture);
DDX_Check(pDX, IDC_CHECK1, m_chkMirror);
DDX_Check(pDX, IDC_CHECK2, m_chkFlip);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVCsampleDlg, CDialog)
//{{AFX_MSG_MAP(CVCsampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_BUTTON_SNAP, OnButtonSnap)
ON_BN_CLICKED(IDC_BUTTON_CAPTURE, OnButtonCapture)
ON_BN_CLICKED(IDC_BUTTON_FREEZE, OnButtonFreeze)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CVCsampleDlg message handlers
BOOL CVCsampleDlg::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
LONG lRet, ntotalcard = 0;
LONG bright, contrast, satu, hue;
LONG lMax, lMin, lDefault;
DWORD dwMirror, dwFlip;
m_boOpen = FALSE;
m_boCapture = FALSE;
m_nSlot = 0;
m_hVideoCapture.MoveWindow(0, 0, 352, 288);
ntotalcard = devwdm_InitCard(m_nSlot, m_hVideoCapture.m_hWnd, 240, 180);
if ( ntotalcard > 0 )
{
lRet = devwdm_SetMirror(m_nSlot, &dwMirror, 1);
lRet = devwdm_SetFlip(m_nSlot, &dwFlip, 1);
lRet = devwdm_GetBrightNess(m_nSlot, &bright, &lMax, &lMin, &lDefault);
CSliderCtrl* pSc=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_BRIGHTNESS);
pSc->SetRange(lMin,lMax);
pSc->SetPos(bright);
lRet = devwdm_GetContrast(m_nSlot, &contrast, &lMax, &lMin, &lDefault);
pSc=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_CONTRAST);
pSc->SetRange(lMin,lMax);
pSc->SetPos(contrast);
lRet = devwdm_GetSaturation(m_nSlot, &satu, &lMax, &lMin, &lDefault);
pSc=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_SATURATION);
pSc->SetRange(lMin,lMax);
pSc->SetPos(satu);
lRet = devwdm_GetHue(m_nSlot, &hue, &lMax, &lMin, &lDefault);
pSc=(CSliderCtrl*)GetDlgItem(IDC_SLIDER_HUE);
pSc->SetRange(lMin,lMax);
pSc->SetPos(hue);
m_boOpen = TRUE;
}
m_boFreeze = FALSE;
m_chkMirror = dwMirror;
m_chkFlip = dwFlip;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CVCsampleDlg::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 CVCsampleDlg::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 CVCsampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVCsampleDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CVCsampleDlg::OnCancel()
{
// TODO: Add extra cleanup here
LONG lRet = devwdm_CloseCard(m_nSlot);
CDialog::OnCancel();
}
void CVCsampleDlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
LONG lRet=0;
if (m_boOpen)
{
//
lRet = devwdm_StartVideoPreview(m_nSlot);
lRet = devwdm_RouteOutPin(m_nSlot, 3);
m_btnStartPreview.EnableWindow(FALSE);
m_btnSnap.EnableWindow(TRUE);
m_btnCapture.EnableWindow(TRUE);
}
}
void CVCsampleDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
LONG curPos, lRet;
CSliderCtrl* pSc2=(CSliderCtrl*)pScrollBar;
if ( !m_boOpen )
return;
switch (pScrollBar->GetDlgCtrlID())
{
case IDC_SLIDER_BRIGHTNESS :
curPos = pSc2->GetPos();
lRet = devwdm_SetBrightNess(m_nSlot,curPos);
break;
case IDC_SLIDER_CONTRAST:
curPos = pSc2->GetPos();
lRet = devwdm_SetContrast(m_nSlot, curPos);
break;
case IDC_SLIDER_HUE:
curPos =pSc2->GetPos();
lRet = devwdm_SetHue(m_nSlot, curPos);
break;
case IDC_SLIDER_SATURATION:
curPos = pSc2->GetPos();
lRet = devwdm_SetSaturation(m_nSlot, curPos);
break;
//case IDC_IMGPARAM_SHARPNESS: m_sharp = pSc2->GetPos(); break;
}
//capSetSharpNess(m_sharp);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CVCsampleDlg::OnButtonSnap()
{
// TODO: Add your control notification handler code here
CString strFileName;
strFileName = "c:\\capture.bmp";
LONG lRet = devwdm_SaveBmpFile(m_nSlot, (char*)(LPCTSTR)strFileName);
}
void CVCsampleDlg::OnButtonCapture()
{
// TODO: Add your control notification handler code here
LONG lRet ;
if ( !m_boCapture)
{
lRet = devwdm_StartCaptureMp4(m_nSlot, "c:\\capture.avi");
m_btnSnap.EnableWindow(FALSE);
m_btnCapture.SetWindowText("停止捕捉");
m_boCapture = TRUE;
}
else
{
//lRet = capStopCapture();
lRet = devwdm_stopCaptureMp4(m_nSlot);
m_btnCapture.SetWindowText("动态捕捉");
m_btnSnap.EnableWindow(TRUE);
m_boCapture = FALSE;
}
}
void CVCsampleDlg::OnButtonFreeze()
{
// TODO: Add your control notification handler code here
LONG hr ;
if (m_boFreeze == FALSE)
{
hr = devwdm_PreviewPause(m_nSlot);
m_boFreeze = TRUE;
}
else
{
hr = devwdm_PreviewResume(m_nSlot);
m_boFreeze = FALSE;
}
}
void CVCsampleDlg::OnCheck1()
{
// TODO: Add your control notification handler code here
LONG lRet = 0;
DWORD mirror;
UpdateData(TRUE);
if (m_chkMirror)
mirror = 1;
else
mirror = 0;
lRet = devwdm_SetMirror(m_nSlot, &mirror, 0);
}
void CVCsampleDlg::OnCheck2()
{
// TODO: Add your control notification handler code here
LONG lRet = 0;
DWORD Flip;
UpdateData(TRUE);
if (m_chkFlip)
Flip = 1;
else
Flip = 0;
lRet = devwdm_SetFlip(m_nSlot, &Flip, 0);
}
void CVCsampleDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}