XvidQuantsParserDlg.cpp
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:14k
源码类别:
VC书籍
开发平台:
Visual C++
- // XvidQuantsParserDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "XvidQuantsParser.h"
- #include "XvidQuantsParserDlg.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 };
- CString m_notes;
- //}}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)
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- m_notes = _T("");
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- DDX_Text(pDX, IDC_EDIT_NOTES, m_notes);
- //}}AFX_DATA_MAP
- }
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Notes Begin -------------------------------------------------------------
- m_notes +="Supported builds:rn";
- m_notes +="--------------------------------------------------------------------------------rn";
- m_notes +="Koepi'st04/10/2002;rn";
- m_notes +="Nic'st09/09/2002;rn";
- // Notes End ---------------------------------------------------------------
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXvidQuantsParserDlg dialog
- CXvidQuantsParserDlg::CXvidQuantsParserDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CXvidQuantsParserDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CXvidQuantsParserDlg)
- m_rate = 0.0f;
- m_height = 0;
- m_width = 0;
- m_nframes = 0;
- m_qmax = 0;
- m_qmin = 0;
- m_qavg = 0.0f;
- m_logging = false;
- m_len = 0;
- m_start = 0;
- m_stop = 0;
- m_maxfs = 0;
- m_minfs = 0;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CXvidQuantsParserDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CXvidQuantsParserDlg)
- DDX_Control(pDX, IDC_EDIT_STATUS, m_status);
- DDX_Control(pDX, IDC_PROGRESS_ANALYZE, m_progress);
- DDX_Text(pDX, IDC_EDIT_RATE, m_rate);
- DDX_Text(pDX, IDC_EDIT_HEIGHT, m_height);
- DDX_Text(pDX, IDC_EDIT_WIDTH, m_width);
- DDX_Text(pDX, IDC_EDIT_FRAMES, m_nframes);
- DDX_Text(pDX, IDC_EDIT_QMAX, m_qmax);
- DDX_Text(pDX, IDC_EDIT_QMIN, m_qmin);
- DDX_Text(pDX, IDC_EDIT_QAVG, m_qavg);
- DDX_Text(pDX, IDC_EDIT_LEN, m_len);
- DDX_Text(pDX, IDC_EDIT_START, m_start);
- DDX_Text(pDX, IDC_EDIT_STOP, m_stop);
- DDX_Text(pDX, IDC_EDIT_MAXFS, m_maxfs);
- DDX_Text(pDX, IDC_EDIT_MINFS, m_minfs);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CXvidQuantsParserDlg, CDialog)
- //{{AFX_MSG_MAP(CXvidQuantsParserDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_COMMAND(MNU_FILE_OPEN, OnFileOpen)
- ON_COMMAND(MNU_FILE_CLOSE, OnFileClose)
- ON_COMMAND(MNU_FILE_QUIT, OnFileQuit)
- ON_COMMAND(MNU_FILE_ANALYZE, OnFileAnalyze)
- ON_COMMAND(MNU_HELP_ABOUT, OnHelpAbout)
- ON_COMMAND(MNU_FILE_SAVE, OnFileSave)
- ON_COMMAND(MNU_FILE_LOAD, OnFileLoad)
- ON_COMMAND(MNU_EDIT_OPTIONS, OnEditOptions)
- ON_COMMAND(MNU_VIEW_HISTOGRAM, OnViewHistogram)
- ON_COMMAND(MNU_VIEW_TIMELINE, OnViewTimeline)
- ON_COMMAND(MNU_EDIT_RANGE, OnEditRange)
- ON_COMMAND(MNU_VIEW_CRITICAL, OnViewCritical)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXvidQuantsParserDlg message handlers
- BOOL CXvidQuantsParserDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Set the icon for this dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- hAccel = LoadAccelerators(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR_MAIN));
- m_status.ReplaceSel("Ready!");
- //Init menu items
- SetMenuInit();
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CXvidQuantsParserDlg::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 CXvidQuantsParserDlg::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 CXvidQuantsParserDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- //---------------------------------------------------------------------------------------------
- BOOL CXvidQuantsParserDlg::PreTranslateMessage(MSG* pMsg)
- {
- if (!TranslateAccelerator(this->m_hWnd ,hAccel,pMsg))
- return CDialog::PreTranslateMessage(pMsg);
- else
- return TRUE;
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnFileOpen()
- {
- CFileDialog* filedialog;
- CString filetypes;
- filetypes = "Xvid AVI (*.avi)|*.avi||";
- filedialog = new CFileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY , (LPCTSTR)filetypes, this);
- filedialog->m_ofn.lpstrTitle = "Xvid AVI File";
- if (IDOK == filedialog->DoModal())
- {
- OnFileClose();
- if (!m_xvid.Open(filedialog->GetPathName()))
- {
- m_rate = m_xvid.GetRate();
- m_width = m_xvid.GetWidth();
- m_height = m_xvid.GetHeight();
- m_nframes = m_xvid.GetFrameCount();
- m_start = 0;
- m_stop = m_nframes;
- m_len = m_nframes;
- SetMenuOpened();
- UpdateData(FALSE);
- }
- else
- {
- AfxMessageBox("Error loading Xvid AVI");
- }
- }
- delete filedialog;
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnFileClose()
- {
- if (m_xvid.IsOpened())
- {
- m_xvid.Close();
- m_width = 0;
- m_height = 0;
- m_nframes = 0;
- m_rate = 0;
- m_qmin = 0;
- m_qmax = 0;
- m_qavg = 0;
- m_start = 0;
- m_stop = 0;
- m_len = 0;
- m_maxfs = 0;
- m_minfs = 0;
- m_progress.SetPos(0);
- m_status.SetSel(0, m_status.LineLength());
- m_status.ReplaceSel("Ready!");
- SetMenuInit();
- UpdateData(FALSE);
- }
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnFileAnalyze()
- {
- if (m_xvid.IsOpened())
- {
- m_xvid.Analyze(m_progress, m_status, m_logging, m_start, m_stop);
- m_qmax = m_xvid.GetMaxQuant();
- m_qmin = m_xvid.GetMinQuant();
- m_qavg = m_xvid.GetAvgQuants();
- m_maxfs = m_xvid.GetMaxFrameSize();
- m_minfs = m_xvid.GetMinFrameSize();
- SetMenuAnalysed();
- UpdateData(FALSE);
- }
- else
- {
- AfxMessageBox("No XviD File Opened!");
- }
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnFileSave()
- {
- CReportFile report;
- CFileDialog* filedialog;
- CString filetypes;
- CString ext;
- filetypes = "XviD Quants Parser Report (*.xqr)|*.xqr||";
- filedialog = new CFileDialog(FALSE, NULL, NULL, OFN_HIDEREADONLY , (LPCTSTR)filetypes, this);
- filedialog->m_ofn.lpstrTitle = "XviD Quants Parser Report";
- if (m_xvid.IsAnalysed())
- {
- if (IDOK == filedialog->DoModal())
- {
- ext = filedialog->GetFileExt();
- if (ext != "") //Wrote extension
- {
- if (!report.Save(filedialog->GetPathName(), m_xvid, m_start, m_stop))
- {
- AfxMessageBox("Error saving report!");
- }
- }
- else //No extension (add it)
- {
- if (!report.Save(filedialog->GetPathName() + ".xqr", m_xvid, m_start, m_stop))
- {
- AfxMessageBox("Error saving report!");
- }
- }
- }
- }
- else
- {
- AfxMessageBox("Xvid AVI not analysed yet!");
- }
- delete filedialog;
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnFileLoad()
- {
- CReportFile report;
- CFileDialog* filedialog;
- CString filetypes;
- filetypes = "XviD Quants Parser Report (*.xqr)|*.xqr||";
- filedialog = new CFileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY , (LPCTSTR)filetypes, this);
- filedialog->m_ofn.lpstrTitle = "XviD Quants Parser Report";
- if (IDOK == filedialog->DoModal())
- {
- if (!report.Load(filedialog->GetPathName(), m_xvid))
- {
- AfxMessageBox("Error loading report!");
- }
- else
- {
- m_rate = m_xvid.GetRate();
- m_width = m_xvid.GetWidth();
- m_height = m_xvid.GetHeight();
- m_nframes = m_xvid.GetFrameCount();
- m_qmax = m_xvid.GetMaxQuant();
- m_qmin = m_xvid.GetMinQuant();
- m_qavg = m_xvid.GetAvgQuants();
- m_start = 0;
- m_stop = m_nframes;
- m_len = m_nframes;
- m_maxfs = m_xvid.GetMaxFrameSize();
- m_minfs = m_xvid.GetMinFrameSize();
- SetMenuAnalysed();
- //Options/Views not available when loading from report
- EnableMenuItem(*GetMenu(), MNU_FILE_ANALYZE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_EDIT_RANGE, MF_GRAYED);
- UpdateData(FALSE);
- }
- }
- delete filedialog;
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnFileQuit()
- {
- OnOK();
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnEditOptions()
- {
- if (GetMenuState(*GetMenu(), MNU_EDIT_OPTIONS, MF_BYCOMMAND) == MF_CHECKED)
- {
- CheckMenuItem(*GetMenu(), MNU_EDIT_OPTIONS, MF_UNCHECKED);
- m_logging=false;
- }
- else
- {
- CheckMenuItem(*GetMenu(), MNU_EDIT_OPTIONS, MF_CHECKED);
- m_logging=true;
- }
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnEditRange()
- {
- CRangeDlg m_range;
- m_range.SetStart(m_start);
- m_range.SetEnd(m_stop);
- m_range.SetFrameCount(m_nframes);
- if (IDOK == m_range.DoModal())
- {
- m_start = m_range.GetStart();
- m_stop = m_range.GetEnd();
- m_len = m_stop - m_start;
- UpdateData(FALSE);
- }
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnViewHistogram()
- {
- CDistributionDlg distdlg;
- if (m_xvid.IsAnalysed())
- {
- distdlg.Init(m_xvid, m_xvid.GetQuantsArray(), m_len);
- distdlg.DoModal();
- }
- else
- {
- AfxMessageBox("Xvid AVI not analysed yet!");
- }
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnViewTimeline()
- {
- CTimelineDlg timedlg;
- if (m_xvid.IsAnalysed())
- {
- timedlg.Init(m_xvid.GetQuantsArray(), m_len, m_xvid.GetMaxQuant(), m_xvid.GetMaxFrameSize());
- timedlg.DoModal();
- }
- else
- {
- AfxMessageBox("Xvid AVI not analysed yet!");
- }
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnViewCritical()
- {
- CCriticalDlg criticDlg;
- criticDlg.Init(m_xvid.GetQuantsArray(), m_len);
- criticDlg.DoModal();
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::OnHelpAbout()
- {
- CAboutDlg about;
- about.DoModal();
- }
- // Utils --------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::SetMenuInit(void)
- {
- //Enabled
- EnableMenuItem(*GetMenu(), MNU_FILE_OPEN, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_LOAD, MF_ENABLED);
- //Disabled
- EnableMenuItem(*GetMenu(), MNU_FILE_CLOSE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_FILE_ANALYZE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_FILE_SAVE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_EDIT_RANGE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_HISTOGRAM, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_TIMELINE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_CRITICAL, MF_GRAYED);
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::SetMenuOpened(void)
- {
- //Enabled
- EnableMenuItem(*GetMenu(), MNU_FILE_OPEN, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_CLOSE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_ANALYZE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_LOAD, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_EDIT_RANGE, MF_ENABLED);
- //Disabled
- EnableMenuItem(*GetMenu(), MNU_FILE_SAVE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_HISTOGRAM, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_TIMELINE, MF_GRAYED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_CRITICAL, MF_GRAYED);
- }
- //---------------------------------------------------------------------------------------------
- void CXvidQuantsParserDlg::SetMenuAnalysed(void)
- {
- //All Enabled
- EnableMenuItem(*GetMenu(), MNU_FILE_OPEN, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_CLOSE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_ANALYZE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_SAVE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_FILE_LOAD, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_EDIT_RANGE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_HISTOGRAM, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_TIMELINE, MF_ENABLED);
- EnableMenuItem(*GetMenu(), MNU_VIEW_CRITICAL, MF_ENABLED);
- }