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

📄 capturedlg.cpp

📁 社区视频监控系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// CaptureDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Capture.h"
#include "CaptureDlg.h"
#include "ControlForm.h"
#include "Autodlg.h"
#include "Playdlg.h"
#include "Login.h"
#include "Managedlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CCaptureDlg dialog


CCaptureDlg::CCaptureDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCaptureDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCaptureDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon        = AfxGetApp()->LoadIcon(IDI_ICON1);
	m_CapitonColor = RGB(0,0,255);
	m_Caption      = "社区视频监控系统";
	m_IsMax        = TRUE;
	m_Time         = FALSE;
	m_Kinescope    = FALSE;
	m_Cancel       = FALSE;
}

void CCaptureDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCaptureDlg)
	DDX_Control(pDX, IDC_REBRUSH, m_ReBrush);
	DDX_Control(pDX, IDC_INBRUSH, m_InBrush);
	DDX_Control(pDX, IDC_INAPERTURE, m_InAperture);
	DDX_Control(pDX, IDC_REAPERTURE, m_ReAperture);
	DDX_Control(pDX, IDC_RELEN, m_ReLen);
	DDX_Control(pDX, IDC_INLEN, m_InLen);
	DDX_Control(pDX, IDC_REFOCI, m_ReFoci);
	DDX_Control(pDX, IDC_INFOCI, m_InFoci);
	DDX_Control(pDX, IDC_BUTTONRIGHT, m_ButtonRight);
	DDX_Control(pDX, IDC_BUTTONLEFT, m_ButtonLeft);
	DDX_Control(pDX, IDC_BUTTONUP, m_ButtonUp);
	DDX_Control(pDX, IDC_BUTTONDOWN, m_ButtonDown);
	DDX_Control(pDX, IDC_MSCOMM1, m_Com);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCaptureDlg, CDialog)
	//{{AFX_MSG_MAP(CCaptureDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_SNAPSHOT, OnSnapshot)
	ON_WM_WINDOWPOSCHANGED()
	ON_BN_CLICKED(IDC_BMP, OnBmp)
	ON_BN_CLICKED(IDC_JPG, OnJpg)
	ON_BN_CLICKED(IDC_VGA, OnVga)
	ON_BN_CLICKED(IDC_PCI, OnPci)
	ON_BN_CLICKED(IDC_SETTING, OnSetting)
	ON_WM_CTLCOLOR()
	ON_WM_NCMOUSEMOVE()
	ON_WM_MOUSEMOVE()
	ON_WM_NCLBUTTONDOWN()
	ON_WM_NCACTIVATE()
	ON_BN_CLICKED(IDC_CONTROL, OnControl)
	ON_BN_CLICKED(IDC_AUTOMATISM, OnAutomatism)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_KINESCOPE, OnKinescope)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_MANAGE, OnManage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaptureDlg message handlers



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

	CButton* pBmpButton = (CButton*) GetDlgItem(IDC_BMP);
	pBmpButton->SetCheck(1);

	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);
		}
	}

	SetIcon(m_hIcon, TRUE);	
	SetIcon(m_hIcon, FALSE);
	CLogin dlg;
	if(dlg.DoModal() != IDOK)
	{
		m_Cancel = TRUE;
		CDialog::OnCancel();
	}
	char buf[256];
	::GetCurrentDirectory(256,buf);
	m_PathText.Format("%s",buf);
	m_UserName = dlg.m_Name;
	m_LogTime = CTime::GetCurrentTime();
	CString strText;
	strText.Format("%s\t%s\t登录\r\n",m_UserName,m_LogTime.Format("%y-%m-%d %H:%M:%S"));
	strcat(buf,"\\log.txt");
	m_LogPath.Format("%s",buf);
	CFile file;
	file.Open(m_LogPath,CFile::modeWrite);
	file.SeekToEnd();
	file.Write(strText,strText.GetLength());
	file.Close();
	
	//加载背景位图
	m_BKGround.LoadBitmap(IDB_BKGROUND);
	m_BorderHeight  = GetSystemMetrics(SM_CYBORDER);
	m_BorderWidth   = GetSystemMetrics(SM_CXBORDER);
	m_CaptionHeight = GetSystemMetrics(SM_CYCAPTION);	
	SetWindowText(m_Caption);
	m_CaptionFont.CreateFont(14,10,0,3,600,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_ROMAN,"宋体");
	CBitmap bitmap;
	bitmap.LoadBitmap(IDB_MINBT);
	BITMAPINFO bInfo;
	bitmap.GetObject(sizeof(bInfo),&bInfo);
	m_ButtonWidth = bInfo.bmiHeader.biWidth;
	m_ButtonHeight = bInfo.bmiHeader.biHeight;
	bitmap.DeleteObject();

	CString strTemp;
	m_Frame.Create(IDD_PANEL_DIALOG,NULL);
	CRect rc;
	GetWindowRect(rc);
	m_Frame.SetWindowPos(&wndTop,0,0,rc.Width()-180,rc.Height()-10,SWP_SHOWWINDOW);
	m_Frame.ShowWindow(SW_SHOW);
	CButton* pVGAButton = (CButton*) GetDlgItem(IDC_VGA);
	CButton* pPCIButton = (CButton*) GetDlgItem(IDC_PCI);
	CString str= "temp";
	GetPrivateProfileString("显卡设置","类型","VGA" ,str.GetBuffer(0), 10, "./syssetting.ini");	
	BOOL ret;
	if(str=="VGA")
	{
		pVGAButton->SetCheck(1);
		pPCIButton->SetCheck(0);
		//初始化SDK
		ret = VCAInitSdk(m_Frame.m_hWnd,PCI_VIEDOMEMORY);
	}
	else
	{
		ret = VCAInitSdk(m_Frame.m_hWnd,PCI_MEMORY_VIDEOMEMORY);
		pVGAButton->SetCheck(0);
		pPCIButton->SetCheck(1);
	}	
	if(ret)
	{
		//获得几路视频
		m_DevNum = VCAGetDevNum();
		m_Frame.CreatePreWnd((int)sqrt(m_DevNum));
		for (int i = 0; i<m_DevNum; i++)
		{
			VCAOpenDevice(i,m_Frame.m_pList[i].m_hWnd);
			BOOL ret = VCAStartVideoPreview(i);	
			m_Frame.UpdateAllPreView();
		}
		m_BStop = FALSE;
	}
	SetTimer(1,1000,NULL);

	m_ButtonUp.m_Type    = ctUp;
	m_ButtonDown.m_Type  = ctDown;
	m_ButtonLeft.m_Type  = ctLeft;
	m_ButtonRight.m_Type = ctRight;
	m_InFoci.m_Type      = ctInFoci;
	m_ReFoci.m_Type      = ctReFoci;
	m_InLen.m_Type       = ctInLen;
	m_ReLen.m_Type       = ctReLen;
	m_InAperture.m_Type  = ctInAperture;
	m_ReAperture.m_Type  = ctReAperture;
	m_InBrush.m_Type     = ctInBrush;
	m_ReBrush.m_Type     = ctReBrush;
	m_Len = GetPrivateProfileInt("使用字节数","字节数",8,"./stage.ini");
	m_ActoinCount = GetPrivateProfileInt("控制项","控制数",13,"./stage.ini");
	m_pData = new  unsigned char[m_ActoinCount][MAXNUM];
	m_Port = GetPrivateProfileInt("端口设置","端口号",1,"./stage.ini");
	GetPrivateProfileString("端口设置","环境设置","9600,n,8,1",
		m_Setting.GetBuffer(0),MAX_PATH,"./stage.ini");
	int data;
	char buff[20] = {0};
	char var[20]  = {0};
	for (int i = 0 ; i<m_ActoinCount ; i++)
	{
		for (int j = 0 ; j <m_Len; j++)
		{
			char section[20] = "字节";
			itoa(i+1,var,10);
			itoa(j+1,buff,10);
			strcat(section,buff);
			data = GetPrivateProfileInt(var,section,0,"./stage.ini");
			m_pData[i][j] = data;
		}
	}
	//设置端口信息,并打开端口
	m_Com.SetSettings(m_Setting);
	m_Com.SetOutBufferSize(512);
	m_Com.SetCommPort(m_Port);
	m_Com.SetSThreshold(0);
	m_Com.SetPortOpen(TRUE);
	return TRUE; 
}

void CCaptureDlg::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 CCaptureDlg::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();
	}
	DrawDialog(FALL);
	m_IsDrawForm = TRUE;
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCaptureDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCaptureDlg::OnCancel()
{
	for(int i=0;i<m_DevNum;i++)
		VCACloseDevice(i);
	VCAUnInitSdk();
	CDialog::OnCancel();
}

void CCaptureDlg::OnTimer(UINT nIDEvent) 
{
	//判断某一路是否有信号
	eFieldFrequency frequency;
	for (int i=0;i<m_DevNum;i++)
	{
		VCAGetVidFieldFrq(i,frequency);
		if(frequency == FIELD_FREQ_0HZ)  //无信号
		{
			if (m_Frame.m_pList[i].m_ShowImage == TRUE)
			{
				m_Frame.m_pList[i].m_ShowImage = FALSE;
				m_Frame.m_pList[i].Invalidate();
			}
		}
		else
		{
			if(m_Frame.m_pList[i].m_ShowImage == FALSE)
			{
				m_Frame.m_pList[i].m_ShowImage = TRUE;
				m_Frame.m_pList[i].Invalidate();
				if(m_Frame.m_pList[i].m_Stop == psPreview)
				{
					VCAUpdateOverlayWnd(m_Frame.m_hWnd);
					VCAUpdateVideoPreview(i,m_Frame.m_pList[i].m_hWnd);	
				}
			}
		}
	}
	if(m_Time)
	{
		CTime time= CTime::GetCurrentTime();
		if(time == m_StopTime)
		{
			OnStop();
			m_Time = FALSE;
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void CCaptureDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);	
	CPoint pos(30,1);
	m_MinRect.CopyRect(CRect(m_RTitleRc.left+pos.x,(m_TitleDrawHeight 
		+2*m_BorderHeight -m_ButtonHeight)/2+pos.y,m_ButtonWidth,m_ButtonHeight));
	pos.x = 55;
	m_MaxRect.CopyRect(CRect(m_RTitleRc.left+pos.x,(m_TitleDrawHeight
		+2*m_BorderHeight -m_ButtonHeight)/2+pos.y,m_ButtonWidth,m_ButtonHeight));
	pos.x = 80;
	m_CloseRect.CopyRect(CRect(m_RTitleRc.left+pos.x,(m_TitleDrawHeight
		+2*m_BorderHeight -m_ButtonHeight)/2+pos.y,m_ButtonWidth,m_ButtonHeight));
	Invalidate();

	CRect rc,frc;
	GetClientRect(rc);
	CRect rcconctrl;
	GetDlgItem(IDC_STATIC1)->GetClientRect(rcconctrl);
	GetDlgItem(IDC_STATIC1)->MoveWindow(rc.Width()-170,rc.top+55,
		rcconctrl.Width(),rcconctrl.Height());
	GetDlgItem(IDC_STATIC2)->GetClientRect(rcconctrl);
	GetDlgItem(IDC_STATIC2)->MoveWindow(rc.Width()-170,rc.top+255,
		rcconctrl.Width(),rcconctrl.Height());
	GetDlgItem(IDC_REFOCI)->GetClientRect(rcconctrl);
	GetDlgItem(IDC_REFOCI)->MoveWindow(rc.Width()-150,rc.top+80,
		rcconctrl.Width(),rcconctrl.Height());
	GetDlgItem(IDC_RELEN)->GetClientRect(rcconctrl);
	GetDlgItem(IDC_RELEN)->MoveWindow(rc.Width()-150,rc.top+120,
		rcconctrl.Width(),rcconctrl.Height());
	GetDlgItem(IDC_REAPERTURE)->GetClientRect(rcconctrl);
	GetDlgItem(IDC_REAPERTURE)->MoveWindow(rc.Width()-150,rc.top+160,
		rcconctrl.Width(),rcconctrl.Height());
	GetDlgItem(IDC_REBRUSH)->GetClientRect(rcconctrl);
	GetDlgItem(IDC_REBRUSH)->MoveWindow(rc.Width()-150,rc.top+200,

⌨️ 快捷键说明

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