📄 vidcapview.cpp
字号:
CWaitCursor wait;
m_wndCap.SavePalette(dlg.GetPathName());
}
}
void CVidCapView::OnUpdateFileSavepalette(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::OnFileSavesingleframe()
{
CString sFilter;
sFilter.LoadString(IDS_BITMAP_EXTENSIONS);
CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, sFilter);
dlg.m_ofn.lpstrTitle = _T("Save Single Frame");
if (dlg.DoModal() == IDOK)
{
CWaitCursor wait;
m_wndCap.SaveDib(dlg.GetPathName());
}
}
void CVidCapView::OnUpdateFileSavesingleframe(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::OnFilePlaycapturedvideo()
{
CString sFilename;
m_wndCap.GetCaptureFile(sFilename);
ShellExecute(AfxGetMainWnd()->m_hWnd, _T("open"), sFilename, NULL, NULL, SW_SHOW);
}
void CVidCapView::OnUpdateFilePlaycapturedvideo(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::OnEditPastepalette()
{
m_wndCap.PastePalette();
}
void CVidCapView::OnUpdateEditPastepalette(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::OnOptionsOverlay()
{
m_wndCap.SetOverlay(TRUE);
}
void CVidCapView::OnUpdateOptionsOverlay(CCmdUI* pCmdUI)
{
if (m_wndCap.GetSafeHwnd() && m_wndCap.HasOverlay())
pCmdUI->SetCheck(m_wndCap.IsOverlay());
else
pCmdUI->Enable(FALSE);
}
void CVidCapView::OnOptionsPreview()
{
m_wndCap.SetPreview(TRUE);
}
void CVidCapView::OnUpdateOptionsPreview(CCmdUI* pCmdUI)
{
if (m_wndCap.GetSafeHwnd())
pCmdUI->SetCheck(m_wndCap.IsPreview());
else
pCmdUI->Enable(FALSE);
}
void CVidCapView::OnOptionsVideodisplay()
{
if (m_wndCap.ShowVideoOutputDlg())
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
CRect rect(0, 0, status.uiImageWidth, status.uiImageHeight);
m_wndCap.MoveWindow(rect);
}
}
void CVidCapView::OnOptionsVideoformat()
{
if (m_wndCap.ShowVideoFormatDlg())
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
CRect rect(0, 0, status.uiImageWidth, status.uiImageHeight);
m_wndCap.MoveWindow(rect);
}
}
void CVidCapView::OnOptionsVideosource()
{
if (m_wndCap.ShowVideoSourceDlg())
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
CRect rect(0, 0, status.uiImageWidth, status.uiImageHeight);
m_wndCap.MoveWindow(rect);
}
}
void CVidCapView::OnUpdateOptionsVideodisplay(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() && m_wndCap.HasVideoOutputDlg());
}
void CVidCapView::OnUpdateOptionsVideoformat(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() && m_wndCap.HasVideoFormatDlg());
}
void CVidCapView::OnUpdateOptionsVideosource(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() && m_wndCap.HasVideoSourceDlg());
}
void CVidCapView::OnOptionsCompression()
{
m_wndCap.ShowCompressionDlg();
}
void CVidCapView::OnUpdateOptionsCompression(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::OnOptionsAudioformat()
{
if (m_pWaveFormat)
{
delete [] m_pWaveFormat;
m_pWaveFormat = NULL;
}
// Get the current audio format
DWORD dwSize;
m_wndCap.GetAudioFormat(m_pWaveFormat, dwSize);
m_nWaveFormatSize = dwSize;
//Ask the user which format they want to use
ACMFORMATCHOOSE cfmt;
memset(&cfmt, 0, sizeof(ACMFORMATCHOOSE));
cfmt.cbStruct = sizeof(ACMFORMATCHOOSE);
cfmt.fdwStyle = ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT;
cfmt.fdwEnum = ACM_FORMATENUMF_HARDWARE | ACM_FORMATENUMF_INPUT;
cfmt.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
cfmt.pwfx = m_pWaveFormat;
cfmt.cbwfx = m_nWaveFormatSize;
if (acmFormatChoose(&cfmt) == MMSYSERR_NOERROR)
m_wndCap.SetAudioFormat(m_pWaveFormat);
}
void CVidCapView::OnUpdateOptionsAudioformat(CCmdUI* pCmdUI)
{
if (m_wndCap.GetSafeHwnd())
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
pCmdUI->Enable(status.fAudioHardware);
}
else
pCmdUI->Enable(FALSE);
}
void CVidCapView::OnCaptureVideo()
{
//Display the dialog which allows the capture settings to be configured
CCaptureVideoDlg dlg;
m_wndCap.GetSetup(dlg.m_CapParms);
if (dlg.DoModal() == IDOK)
{
//Do the capture
m_wndCap.SetSetup(dlg.m_CapParms);
m_wndCap.CaptureSequence();
}
}
void CVidCapView::OnUpdateCaptureVideo(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::OnCaptureFrames()
{
CCaptureFramesDlg dlg;
dlg.m_pCapWnd = &m_wndCap;
m_wndCap.GetCaptureFile(dlg.m_sFilename);
dlg.DoModal();
}
void CVidCapView::OnUpdateCaptureFrames(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_wndCap.GetSafeHwnd() != NULL);
}
void CVidCapView::LoadSettings()
{
CWinApp* pApp = AfxGetApp();
CString sSection(_T("General"));
m_sCaptureFile = pApp->GetProfileString(sSection, _T("CaptureFile"));
m_dwCaptureRate = static_cast<DWORD>(pApp->GetProfileInt(sSection, _T("CaptureRate"), m_dwCaptureRate));
m_dwPreviewRate = static_cast<DWORD>(pApp->GetProfileInt(sSection, _T("PreviewRate"), m_dwPreviewRate));
m_bPreview = static_cast<BOOL>(pApp->GetProfileInt(sSection, _T("Preview"), m_bPreview));
m_bOverlay = pApp->GetProfileInt(sSection, _T("Overlay"), FALSE);
m_bCaptureAudio = static_cast<BOOL>(pApp->GetProfileInt(sSection, _T("CaptureAudio"), m_bCaptureAudio));
m_bLimitEnabled = static_cast<BOOL>(pApp->GetProfileInt(sSection, _T("LimitEnabled"), m_bLimitEnabled));
m_wTimeLimit = pApp->GetProfileInt(sSection, _T("TimeLimit"), m_wTimeLimit);
m_nDefaultDevice = pApp->GetProfileInt(sSection, _T("Device"), m_nDefaultDevice);
m_bStretch = pApp->GetProfileInt(sSection, _T("Stretch"), m_bStretch);
m_nWidth = pApp->GetProfileInt(sSection, _T("Width"), m_nWidth);
m_nHeight = pApp->GetProfileInt(sSection, _T("Height"), m_nHeight);
m_wBitCount = static_cast<WORD>(pApp->GetProfileInt(sSection, _T("BitCount"), -1));
m_pWaveFormat = NULL;
m_nWaveFormatSize = 0;
pApp->GetProfileBinary(sSection, _T("WaveFormat"), reinterpret_cast<LPBYTE*>(&m_pWaveFormat), &m_nWaveFormatSize);
}
void CVidCapView::SaveSettings()
{
if (m_wndCap.GetSafeHwnd())
OnFileDisconnect();
CWinApp* pApp = AfxGetApp();
CString sSection(_T("General"));
pApp->WriteProfileString(sSection, _T("CaptureFile"), m_sCaptureFile);
pApp->WriteProfileInt(sSection, _T("CaptureRate"), m_dwCaptureRate);
pApp->WriteProfileInt(sSection, _T("PreviewRate"), m_dwPreviewRate);
pApp->WriteProfileInt(sSection, _T("Preview"), m_bPreview);
pApp->WriteProfileInt(sSection, _T("Overlay"), m_bOverlay);
pApp->WriteProfileInt(sSection, _T("CaptureAudio"), m_bCaptureAudio);
pApp->WriteProfileInt(sSection, _T("LimitEnabled"), m_bLimitEnabled);
pApp->WriteProfileInt(sSection, _T("TimeLimit"), m_wTimeLimit);
pApp->WriteProfileInt(sSection, _T("Device"), m_nDefaultDevice);
pApp->WriteProfileInt(sSection, _T("Stretch"), m_bStretch);
pApp->WriteProfileInt(sSection, _T("Width"), m_nWidth);
pApp->WriteProfileInt(sSection, _T("Height"), m_nHeight);
pApp->WriteProfileInt(sSection, _T("BitCount"), m_wBitCount);
pApp->WriteProfileBinary(sSection, _T("WaveFormat"), reinterpret_cast<LPBYTE>(m_pWaveFormat), m_nWaveFormatSize);
}
void CVidCapView::OnDestroy()
{
//Save the default settings
SaveSettings();
if (m_pWaveFormat)
{
delete [] m_pWaveFormat;
m_pWaveFormat = NULL;
}
//Let the parent class do its thing
CView::OnDestroy();
}
void CVidCapView::OnInitialUpdate()
{
//Let the parent class do its thing
CView::OnInitialUpdate();
//Load the default settings
LoadSettings();
//Auto connect to the device if we can
if (m_nDefaultDevice != -1)
Connect(m_nDefaultDevice);
else
{
//No device has been configured. See how many devices there are installed!
int nDevices = 0;
int nDeviceID = -1;
for (WORD i=0; i<10; i++)
{
CString sName;
CString sVersion;
if (CAVICapWnd::GetDescription(i, sName, sVersion))
{
nDeviceID = i;
++nDevices;
}
}
//If there is one device, then connect directly
if (nDevices == 1)
Connect(nDeviceID);
else
{
// Prompt the user to pick the device
PostMessage(WM_COMMAND, ID_FILE_CONNECT);
}
}
}
void CVidCapView::OnOptionsStretch()
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
m_wndCap.SetScale(!status.fScale);
}
void CVidCapView::OnUpdateOptionsStretch(CCmdUI* pCmdUI)
{
if (m_wndCap.GetSafeHwnd())
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
if (status.fLiveWindow)
pCmdUI->SetCheck(status.fScale);
else
pCmdUI->Enable(FALSE);
}
else
pCmdUI->Enable(FALSE);
}
void CVidCapView::OnSize(UINT nType, int cx, int cy)
{
//Scale the capture window if needed
if (m_wndCap.GetSafeHwnd())
{
CAPSTATUS status;
m_wndCap.GetStatus(status);
if (status.fScale)
{
CRect rect(0, 0, status.uiImageWidth, status.uiImageHeight);
m_wndCap.MoveWindow(rect);
}
}
//Let the parent class do its thing
CView::OnSize(nType, cx, cy);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -