⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 consoledlg.cpp

📁 This paper provides video capture and category CcaptureVideo example, in Win2K DirectX9 SDK VC6 thro
💻 CPP
字号:
// ConsoleDlg.cpp : implementation file//#include "stdafx.h"#include "Console.h"#include "ConsoleDlg.h"#include "resource.h"#include "ParaDlg.h"#include "MyPropertySheet.h"#include "..\\inc\\videodispctl.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass 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// Implementationprotected:	//{{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_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CConsoleDlg dialogCConsoleDlg::CConsoleDlg(CWnd* pParent /*=NULL*/)	: CDialog(CConsoleDlg::IDD, pParent){	//{{AFX_DATA_INIT(CConsoleDlg)		// NOTE: the ClassWizard will add member initialization here	//}}AFX_DATA_INIT	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);	bSnapEnable=FALSE;    InitFlag=FALSE;	bShowMax=FALSE;	bMoveFlag=FALSE;	//MY CODE STARTS HERE linca	m_iCardNum = (int)CG300GetCardNumber(); 	if (m_iCardNum > MAX_CARD_NUMBER)	{		m_iCardNum = MAX_CARD_NUMBER;	}	//构造各个播放器	for (int i = 0; i < m_iCardNum; i++)        	{		m_pStatic[i] = new CStaticEx(i + 1);    //(i + 1)为卡的序号,从1开始												//这里CStatic类开始构造,真难找!	}	m_hDeskTop = ::GetDesktopWindow();	}CConsoleDlg::~CConsoleDlg(){	//释放删除个播放器	for (int i = 0; i < m_iCardNum; i++)	{		delete m_pStatic[i];	}	::RedrawWindow(m_hDeskTop, NULL, NULL, RDW_ERASENOW | RDW_UPDATENOW |			     RDW_ERASE | RDW_NOINTERNALPAINT | RDW_INVALIDATE | RDW_ALLCHILDREN);}void CConsoleDlg::DoDataExchange(CDataExchange* pDX){	CDialog::DoDataExchange(pDX);	//{{AFX_DATA_MAP(CConsoleDlg)		//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CConsoleDlg, CDialog)	//{{AFX_MSG_MAP(CConsoleDlg)	ON_WM_SYSCOMMAND()	ON_WM_PAINT()	ON_WM_QUERYDRAGICON()	ON_BN_CLICKED(IDC_SET_BUTTON, OnSetButton)	ON_BN_CLICKED(IDC_CAPTURE_BUTTON, OnCaptureButton)	ON_WM_CREATE()	ON_WM_SIZE()	ON_WM_SHOWWINDOW()	ON_WM_MOVE()	ON_WM_TIMER()	//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CConsoleDlg message handlersBOOL CConsoleDlg::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			pCapButton=(CButton*) GetDlgItem(IDC_CAPTURE_BUTTON);	return TRUE;  // return TRUE  unless you set the focus to a control}void CConsoleDlg::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 CConsoleDlg::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	{		CPaintDC dc(this); // device context for painting 		//dc.LineTo(100, 100); 		CDialog::OnPaint();	}}// The system calls this to obtain the cursor to display while the user drags//  the minimized window.HCURSOR CConsoleDlg::OnQueryDragIcon(){	return (HCURSOR) m_hIcon;}void CConsoleDlg::OnSetButton() {	CMyPropertySheet aPropertySheet(_T("参数设置"),NULL, m_pStatic);	aPropertySheet.DoModal();	}void CConsoleDlg::OnCaptureButton() {   		/*	BOOL bEnable=1;	for (int i = 0; i < m_iCardNum; i++) 	{	m_pStatic[i]->CaptureToVGA(bEnable);	}	pCapButton->EnableWindow(FALSE);	pStopButton->EnableWindow(TRUE);	*/	CString str;	pCapButton->GetWindowText(str);		if(str=="采 集")	{				str="停 止";		pCapButton->SetWindowText(str);		bSnapEnable=TRUE;		int iImageSize = (m_pStatic[0]->m_rectVideo.Width()) * 			(m_pStatic[0]->m_rectVideo.Height()) * 4;	  			int iMode;		DWORD dwMemSize, dwPhysMem, dwHandle, dwLineAddr;		int nRet = StaticMemAlloc(&dwMemSize, &dwPhysMem, &dwHandle, &dwLineAddr);		if((nRet == 0) || (dwMemSize == 0))		{			MessageBox("Memory allocates error!", NULL, MB_OK | MB_ICONEXCLAMATION);			return;		}		dwMemSize *= 4 * 1024; // dwMemSize的单位为页数,一页是4K		if (CStaticEx::m_staticCounts <= 0)		{			return;		}		//启动各图像卡SnapToMem,数据存放格式由参数设置对话框控制		for ( int i = 0; i < CStaticEx::m_staticCounts; i++)		{			//设置回放参数			m_pStatic[i]->SetPlayBackParam(i *2* iImageSize, //偏移地址,帧数,图像大小				2, iImageSize,           //目标窗口的大小				CSize(m_pStatic[i]->m_rectVideo.Width(), m_pStatic[i]->m_rectVideo.Height()));			if (m_pStatic[i]->m_iFormMode == FRAME)//数据采集帧/场模式			{				iMode = m_pStatic[i]->m_iStoreFmt;//数据存储帧/场模式			}			else			{				iMode = FRAME;			}						int iRetVal1= CG300FillToMem(m_pStatic[i]->m_hCG300, 				(char *)dwLineAddr + m_pStatic[i]->m_dwLineAddrOffset,				(DWORD)iImageSize*2, 0);						int iRetVal3=CG300SnapOneToMem(m_pStatic[i]->m_hCG300,//启动各图像卡SnapToMem				dwPhysMem + m_pStatic[i]->m_dwLineAddrOffset, 				(DWORD)iImageSize*2, iMode);						if(iRetVal3)				SetTimer(1, 20, NULL);    					}	}		else	{		str="采 集";		pCapButton->SetWindowText(str);		KillTimer(1);				for (int j = 0; j < CStaticEx::m_staticCounts; j++)		{			CG300Capture(m_pStatic[j]->m_hCG300, FALSE);		}		Invalidate(TRUE);		SendMessage(WM_MOVE);			GetDlgItem(IDC_RECTVIDEO1)->GetClientRect(m_pStatic[0]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO1)->ClientToScreen(m_pStatic[0]->m_rectVideo);		GetDlgItem(IDC_RECTVIDEO2)->GetClientRect(m_pStatic[1]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO2)->ClientToScreen(m_pStatic[1]->m_rectVideo);		GetDlgItem(IDC_RECTVIDEO3)->GetClientRect(m_pStatic[2]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO3)->ClientToScreen(m_pStatic[2]->m_rectVideo);		GetDlgItem(IDC_RECTVIDEO4)->GetClientRect(m_pStatic[3]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO4)->ClientToScreen(m_pStatic[3]->m_rectVideo);		for(int k = 0; k < m_iCardNum; k++)		{			m_pStatic[k]->SetDispWindow(TRUE);		}				}	}int CConsoleDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) {	if (CDialog::OnCreate(lpCreateStruct) == -1)		return -1;	    for (int i = 0; i < m_iCardNum; i++)	{		//创建每个播放器窗口,初始时窗口为0,窗口大小在WM_SIZE消息响应中调整		int nResponse=m_pStatic[i]->Create(NULL, WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, 1000);        m_pStatic[i]->OnCreate();     			}		return 0;		}void CConsoleDlg::OnSize(UINT nType, int cx, int cy) {	CDialog::OnSize(nType, cx, cy);	   	::RedrawWindow(m_hDeskTop, NULL, NULL, RDW_ERASENOW | RDW_UPDATENOW |			     RDW_ERASE | RDW_NOINTERNALPAINT | RDW_INVALIDATE | RDW_ALLCHILDREN);	}void CConsoleDlg::OnShowWindow(BOOL bShow, UINT nStatus) {	CDialog::OnShowWindow(bShow, nStatus);		//	ShowWindow(SW_SHOWMAXIMIZED);	bShowMax=TRUE;	InitFlag=TRUE;//设立初始化标记	GetClientRect(RectMaxShow);	ClientToScreen(RectMaxShow);	CRect rectTemp;	GetDlgItem(IDC_RECTVIDEO1)->GetClientRect(m_pStatic[0]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO1)->ClientToScreen(m_pStatic[0]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO2)->GetClientRect(m_pStatic[1]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO2)->ClientToScreen(m_pStatic[1]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO3)->GetClientRect(m_pStatic[2]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO3)->ClientToScreen(m_pStatic[2]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO4)->GetClientRect(m_pStatic[3]->m_rectVideo);	GetDlgItem(IDC_RECTVIDEO4)->ClientToScreen(m_pStatic[3]->m_rectVideo);	for( int i = 0; i < m_iCardNum; i++)	{		rectTemp = RectMaxShow;		//移动播放器到相应位置		m_pStatic[i]->MoveWindow(rectTemp);		//重新设置播放器视频输入和输出窗口		m_pStatic[i]->SetDispWindow(TRUE);		bMoveFlag=TRUE;	}}void CConsoleDlg::OnMove(int x, int y) {	CDialog::OnMove(x, y);	bMoveFlag=TRUE;	if(InitFlag&&bMoveFlag)	{		GetDlgItem(IDC_RECTVIDEO1)->GetClientRect(m_pStatic[0]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO1)->ClientToScreen(m_pStatic[0]->m_rectVideo);		GetDlgItem(IDC_RECTVIDEO2)->GetClientRect(m_pStatic[1]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO2)->ClientToScreen(m_pStatic[1]->m_rectVideo);		GetDlgItem(IDC_RECTVIDEO3)->GetClientRect(m_pStatic[2]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO3)->ClientToScreen(m_pStatic[2]->m_rectVideo);		GetDlgItem(IDC_RECTVIDEO4)->GetClientRect(m_pStatic[3]->m_rectVideo);	    GetDlgItem(IDC_RECTVIDEO4)->ClientToScreen(m_pStatic[3]->m_rectVideo);		for(int k = 0; k < m_iCardNum; k++)		{			m_pStatic[k]->SetDispWindow(TRUE);		}			CRect rect;		GetClientRect(rect);		ClientToScreen(rect);		if(rect.top <=25||rect.left<=1) ReleaseCapture();//禁止左上角移出屏幕	}	bMoveFlag=FALSE;    //刷新整个桌面	::RedrawWindow(m_hDeskTop, NULL, NULL, RDW_ERASENOW | RDW_UPDATENOW |			     RDW_ERASE | RDW_NOINTERNALPAINT | RDW_INVALIDATE | RDW_ALLCHILDREN);		}void CConsoleDlg::OnTimer(UINT nIDEvent) {	int nStatus[4],i;	int m_iCurFrame[4] ;	bool bComplete1[4] ;	memset(m_iCurFrame,0,4*sizeof(int));	memset(bComplete1,0,4*sizeof(bool));	switch(nIDEvent)	{	case 1:				for ( i = 0; i < CStaticEx::m_staticCounts; i++)		{			if(!CG300GetSnappingStatus(m_pStatic[i]->m_hCG300, &nStatus[i]))				break;			if(nStatus[i] == 3 && bComplete1[i] == 0)//nStatus=0,3表示正在采集第二幅图像							{                                  				m_iCurFrame[i] = 1;               //第一幅图像已经采集完毕				bComplete1[i] = 1;			}						if(nStatus[i] == 1 && bComplete1[i] == 1)//nStatus=1,2表示正在采集第一幅图像			{				m_iCurFrame[i] = 2;               //第二幅图像已经采集完毕				bComplete1[i] = 0;			}						if( m_iCurFrame[i] )			{				m_pStatic[i]->m_iCurFrame=m_iCurFrame[i]-1;				m_pStatic[i]->Display();				m_iCurFrame[i] = 0;							}		}		break;	}		CDialog::OnTimer(nIDEvent);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -