Browse Source

【软件版本】V
【模块名称】
【问题原因】初步完成摄像头集成功能,但是清晰度不如系统自带的。还有其他小问题未解决。
【修改描述】
【测试结果】

sat23 3 years ago
parent
commit
798624b0af

+ 16 - 5
FieldTestTool/FieldTestTool/CaptureVideo.cpp

@@ -13,6 +13,8 @@ CCaptureVideo::CCaptureVideo()
 	m_pVW = NULL;
 	m_pMC = NULL;
 	m_pGB = NULL;
+    m_pBF = NULL;
+    m_pGrabber = NULL;
 	m_pCapture = NULL;
 }
 
@@ -107,10 +109,12 @@ HRESULT CCaptureVideo::Init(int iDeviceID, HWND hWnd)
 	//hr = m_pGrabber.CoCreateInstance( CLSID_SampleGrabber );
 	hr = CoCreateInstance( CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_ISampleGrabber, (void**)&m_pGrabber );
 
-	if( !m_pGrabber ){
+	if( !m_pGrabber )
+    {
 		AfxMessageBox("Fail to create SampleGrabber, maybe qedit.dll is not registered?");
 		return hr;
 	}
+
 	CComQIPtr< IBaseFilter, &IID_IBaseFilter > pGrabBase( m_pGrabber );
 	//ÉèÖÃÊÓÆµ¸ñʽ
 	AM_MEDIA_TYPE mt;
@@ -118,26 +122,33 @@ HRESULT CCaptureVideo::Init(int iDeviceID, HWND hWnd)
 	mt.majortype = MEDIATYPE_Video;
 	mt.subtype = MEDIASUBTYPE_RGB24;
 	hr = m_pGrabber->SetMediaType(&mt);
-	if( FAILED( hr ) ){
+	if( FAILED( hr ) )
+    {
 		AfxMessageBox("Fail to set media type!");
 		return hr;
 	}
+
 	hr = m_pGB->AddFilter( pGrabBase, L"Grabber" );
-	if( FAILED( hr ) ){
+	if( FAILED( hr ) )
+    {
 		AfxMessageBox("Fail to put sample grabber in graph");
 		return hr;
 	}
+
 	// try to render preview/capture pin
 	hr = m_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL);
 	if( FAILED( hr ) )
 		hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,m_pBF,pGrabBase,NULL);
-	if( FAILED( hr ) ){
+
+	if( FAILED( hr ) )
+    {
 		AfxMessageBox("Can¡¯t build the graph");
 		return hr;
 	}
 
 	hr = m_pGrabber->GetConnectedMediaType( &mt );
-	if ( FAILED( hr) ){
+	if ( FAILED( hr) )
+    {
 		AfxMessageBox("Failt to read the connected media type");
 		return hr;
 	}

+ 2 - 1
FieldTestTool/FieldTestTool/CaptureVideo.h

@@ -24,6 +24,8 @@ public:
 	HRESULT Init(int iDeviceID,HWND hWnd);
 	// ö¾ÙÉ豸;
 	int EnumDevices(CMFCRibbonComboBox *pCombobox);
+    // ¸üд°¿Ú;
+    void ResizeVideoWindow();
 	CCaptureVideo();
 	virtual ~CCaptureVideo();
 private:
@@ -37,7 +39,6 @@ private:
 protected:
 	void FreeMediaType(AM_MEDIA_TYPE& mt);
 	bool BindFilter(int deviceId, IBaseFilter **pFilter);
-	void ResizeVideoWindow();
 	HRESULT SetupVideoWindow();
 	HRESULT InitCaptureGraphBuilder();
 };

+ 1 - 0
FieldTestTool/FieldTestTool/ChildFrm.cpp

@@ -50,6 +50,7 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
 	if( !CMDIChildWndEx::PreCreateWindow(cs) )
 		return FALSE;
 
+    cs.style &=~WS_CAPTION;
     // 只去掉最大化最小化按钮;
     //cs.style &= ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX |WS_THICKFRAME);
 

+ 2 - 0
FieldTestTool/FieldTestTool/ChildFrm.h

@@ -43,4 +43,6 @@ protected:
 	afx_msg void OnFilePrintPreview();
 	afx_msg void OnUpdateFilePrintPreview(CCmdUI* pCmdUI);
 	DECLARE_MESSAGE_MAP()
+public:
+
 };

+ 2 - 0
FieldTestTool/FieldTestTool/FieldTestTool.cpp

@@ -126,6 +126,8 @@ BOOL CFieldTestToolApp::InitInstance()
 
 	// ´´˝¨Ö÷ MDI żňźÜ´°żÚ
 	CMainFrame* pMainFrame = new CMainFrame;
+    pMainFrame->m_pDocTemplate = pDocTemplate;
+    pMainFrame->m_pDoc = (CFieldTestToolDoc *)pDocTemplate->CreateNewDocument();
 	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
 	{
 		delete pMainFrame;

+ 7 - 23
FieldTestTool/FieldTestTool/FieldTestToolView.cpp

@@ -29,9 +29,7 @@ IMPLEMENT_DYNCREATE(CFieldTestToolView, CView)
 
 BEGIN_MESSAGE_MAP(CFieldTestToolView, CView)
 	// 标准打印命令
-	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
-	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
-	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CFieldTestToolView::OnFilePrintPreview)
+
 END_MESSAGE_MAP()
 
 // CFieldTestToolView 构造/析构
@@ -39,7 +37,7 @@ END_MESSAGE_MAP()
 CFieldTestToolView::CFieldTestToolView()
 {
 	// TODO: 在此处添加构造代码
-
+    m_pCamera = NULL;
 }
 
 CFieldTestToolView::~CFieldTestToolView()
@@ -49,7 +47,8 @@ CFieldTestToolView::~CFieldTestToolView()
 BOOL CFieldTestToolView::PreCreateWindow(CREATESTRUCT& cs)
 {
 	// TODO: 在此处通过修改
-	//  CREATESTRUCT cs 来修改窗口类或样式
+
+    cs.style &= ~WS_CAPTION;
 
 	return CView::PreCreateWindow(cs);
 }
@@ -62,8 +61,9 @@ void CFieldTestToolView::OnDraw(CDC* /*pDC*/)
 	ASSERT_VALID(pDoc);
 	if (!pDoc)
 		return;
-
 	// TODO: 在此处为本机数据添加绘制代码
+    if ( m_pCamera )
+        m_pCamera->ResizeVideoWindow();
 }
 
 
@@ -75,22 +75,6 @@ void CFieldTestToolView::OnFilePrintPreview()
 	AFXPrintPreview(this);
 }
 
-BOOL CFieldTestToolView::OnPreparePrinting(CPrintInfo* pInfo)
-{
-	// 默认准备
-	return DoPreparePrinting(pInfo);
-}
-
-void CFieldTestToolView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
-{
-	// TODO: 添加额外的打印前进行的初始化过程
-}
-
-void CFieldTestToolView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
-{
-	// TODO: 添加打印后进行的清理过程
-}
-
 void CFieldTestToolView::OnRButtonUp(UINT nFlags, CPoint point)
 {
 	ClientToScreen(&point);
@@ -99,7 +83,7 @@ void CFieldTestToolView::OnRButtonUp(UINT nFlags, CPoint point)
 
 void CFieldTestToolView::OnContextMenu(CWnd* pWnd, CPoint point)
 {
-	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
+	//theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
 }
 
 

+ 3 - 3
FieldTestTool/FieldTestTool/FieldTestToolView.h

@@ -15,6 +15,8 @@
 
 #pragma once
 
+#include "CaptureVideo.h"
+#include "FieldTestToolDoc.h"
 
 class CFieldTestToolView : public CView
 {
@@ -24,6 +26,7 @@ protected: // 
 
 // 属性
 public:
+    CCaptureVideo *m_pCamera;
 	CFieldTestToolDoc* GetDocument() const;
 
 // 操作
@@ -34,9 +37,6 @@ public:
 	virtual void OnDraw(CDC* pDC);  // 重写以绘制该视图
 	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
 protected:
-	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
-	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
-	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
 
 // 实现
 public:

+ 32 - 0
FieldTestTool/FieldTestTool/MainFrm.cpp

@@ -16,6 +16,8 @@
 #include "FieldTestTool.h"
 
 #include "MainFrm.h"
+#include "ChildFrm.h"
+#include "FieldTestToolView.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -69,6 +71,8 @@ END_MESSAGE_MAP()
 CMainFrame::CMainFrame()
 {
 	// TODO: 在此添加成员初始化代码
+    m_pDoc = NULL;
+    m_pDocTemplate = NULL;
     m_bFindTestWizardPort = false;
     m_bFindSwitcherPort = false;
     m_bSwitcherCheckA = false;
@@ -605,6 +609,34 @@ void CMainFrame::OnCameraCombobox()
     CMFCRibbonBar* pRibbon = GetRibbonBar();
     ASSERT_VALID(pRibbon);
     CMFCRibbonComboBox* pCameraCombo = DYNAMIC_DOWNCAST(CMFCRibbonComboBox, pRibbon->FindByID(ID_RIBBON_CAMERA_COMBOBOX));
+    if ( pCameraCombo )
+    {
+        int nCurSel = pCameraCombo->GetCurSel();
+        if ( nCurSel != -1 )
+        {
+            CString strCamera = pCameraCombo->GetItem(nCurSel);
+            OutputDebugString(strCamera + _T("\r\n"));
+
+            CCreateContext context;
+            CChildFrame *pChildView = new CChildFrame();
+            context.m_pLastView = NULL;
+            context.m_pCurrentFrame = this;
+            context.m_pCurrentDoc = m_pDoc;
+            context.m_pNewViewClass = RUNTIME_CLASS(CFieldTestToolView);
+            context.m_pNewDocTemplate = m_pDocTemplate;
+
+            if (pChildView->LoadFrame(IDR_MAINFRAME, WS_MAXIMIZE | WS_CHILDWINDOW, this, &context))
+            {
+                pChildView->MDIActivate();
+                pChildView->InitialUpdateFrame(m_pDoc, TRUE);
+                pChildView->ShowWindow(SW_SHOWMAXIMIZED);
+                CFieldTestToolView *pView = (CFieldTestToolView*)pChildView->GetActiveView();
+                if ( pView )
+                    pView->m_pCamera = &m_cap;
+                m_cap.Init(1, pChildView->GetSafeHwnd());
+            }
+        }
+    }
 }
 
 void CMainFrame::OnUpdateCameraCombobox(CCmdUI* pCmdUI)

+ 3 - 1
FieldTestTool/FieldTestTool/MainFrm.h

@@ -17,6 +17,7 @@
 #include "Resource.h"
 #include "PropertiesWnd.h"
 #include "CaptureVideo.h"
+#include "FieldTestToolDoc.h"
 
 class COutlookBar : public CMFCOutlookBar
 {
@@ -32,7 +33,8 @@ public:
 
 // ÊôÐÔ
 public:
-
+    CFieldTestToolDoc* m_pDoc;
+    CMultiDocTemplate* m_pDocTemplate;
 // ²Ù×÷
 public: