// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "DICOMVid.h" #include "Document.h" #include "MainFrm.h" #include "LeftView.h" #include "View.h" #include #include "CompressionSettingsDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_DESTROY() ON_COMMAND(ID_OPTIONS_CAPTUREPROPERTIES, OnOptionsCaptureproperties) ON_UPDATE_COMMAND_UI(ID_OPTIONS_CAPTUREPROPERTIES, OnUpdateOptionsCaptureproperties) ON_COMMAND(ID_CAPTURE_STARTCAPTUREINTODICOMFILE, OnCaptureStartcaptureintodicomfile) ON_UPDATE_COMMAND_UI(ID_CAPTURE_STARTCAPTUREINTODICOMFILE, OnUpdateCaptureStartcaptureintodicomfile) ON_COMMAND(ID_CAPTURE_STOPCAPTURE, OnCaptureStopcapture) ON_UPDATE_COMMAND_UI(ID_CAPTURE_STOPCAPTURE, OnUpdateCaptureStopcapture) ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit) ON_COMMAND(ID_COMPRESSION_SETTINGS, OnCompressionSettings) ON_UPDATE_COMMAND_UI(ID_COMPRESSION_SETTINGS, OnUpdateCompressionSettings) //}}AFX_MSG_MAP ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles) ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle) ON_COMMAND_RANGE( ID_VIDEODEVICE, ID_VIDEODEVICELAST, OnVideoDevice) ON_UPDATE_COMMAND_UI_RANGE( ID_VIDEODEVICE, ID_VIDEODEVICELAST, OnUpdateVideoDevice) ON_COMMAND_RANGE( ID_AUDIODEVICE, ID_AUDIODEVICELAST, OnAudioDevice) ON_UPDATE_COMMAND_UI_RANGE( ID_AUDIODEVICE, ID_AUDIODEVICELAST, OnUpdateAudioDevice) END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() :m_wndToolBar(40, IDR_ANIMATION) { m_bMMCapabilitiesInitialized = FALSE; m_pDICOMFilter = NULL; m_capture = NULL; m_DicomWriter = NULL; m_bNowPlaying = FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } m_wndToolBar.m_wndAnim.Open(IDR_ANIMATION); if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } ///////////////////////////////////////////////////////////////////////////// // Instantiate capture library and DICOM Writer filter BOOL CMainFrame::InitMMCapabilities() { m_capture = NULL; m_DicomWriter = NULL; m_bMMCapabilitiesInitialized = FALSE; HRESULT hr = CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**) &m_capture); if(FAILED(hr)) { AfxMessageBox(CANT_INSTANTIATE_CAPTURE_LIBRARY_ERROR); return TRUE; } hr = CreateTargetFormats(); if(FAILED(hr)) { AfxMessageBox(CANT_FIND_LEAD_DICOM_FILE_WRITER_ERROR); return TRUE; } hr = m_pDICOMFilter->QueryInterface(IID_ILTDicWrtDisp, (void**)&m_DicomWriter); if(FAILED(hr)) { AfxMessageBox(_T("Can't get a DICOM Writer interface")); return TRUE; } #ifdef LICENSE_WINDOWSMEDIA IUnknown* punkCert; hr = WMCreateCertificate(&punkCert); if(SUCCEEDED(hr)) { m_capture->put_WMCertificate(punkCert); punkCert->Release(); } #endif m_bMMCapabilitiesInitialized = TRUE; m_capture->put_VideoWindowFrame((long) m_wndSplitter.GetPane(0, 1)->m_hWnd); m_capture->put_Preview(VARIANT_TRUE); SetCompression(DICOMVID_IMAGE_COMPRESSION_NONE); SetQFactor(Q_FACTOR_MIN); BuildDeviceMenu(); //BuildCompressionTypeMenu(); m_capture->put_VideoWindowSizeMode(ltmmNormal); return TRUE; } ///////////////////////////////////////////////////////////////////////////// //We are interested in two target formats: //1-DICOM (which includes uncompressed, JPEG lossy and lossless compression) //2-DICOM-MPEG2 which represents DICOM with MPEG2 compression ///////////////////////////////////////////////////////////////////////////// HRESULT CMainFrame::CreateTargetFormats() { HRESULT hr; IltmmTargetFormats* pformats = NULL; IltmmTargetFormat* pformat = NULL; hr = m_capture->get_TargetFormats(&pformats); if(FAILED(hr)) { return hr; } hr = pformats->Item(ltmmCapture_TargetFormat_DICOM, &pformat); if(FAILED(hr)) { pformats->Release(); return hr; } hr = pformat->put_UseFilterCache(VARIANT_TRUE); if(FAILED(hr)) { pformat->Release(); pformats->Release(); return hr; } /// get the DICOM filter for private use hr = pformat->GetCacheObject(ltmmTargetFormat_Object_Mux, &m_pDICOMFilter); if(FAILED(hr)) { pformat->Release(); pformats->Release(); return hr; } pformat->Release(); pformat = NULL; hr = pformats->Item(ltmmCapture_TargetFormat_MPEG2_DICOM, &pformat); if(FAILED(hr)) { pformats->Release(); return hr; } hr = pformat->put_UseFilterCache(VARIANT_TRUE); if(FAILED(hr)) { pformat->Release(); pformats->Release(); return hr; } pformat->Release(); pformats->Release(); return S_OK; } HRESULT CMainFrame::SelectMPEG2Compressor(BOOL bSelect) { IltmmCompressors *pVideoCompressors = NULL; IltmmCompressors *pAudioCompressors = NULL; HRESULT hr; hr = m_capture->get_VideoCompressors(&pVideoCompressors); if(FAILED(hr) && bSelect) { AfxMessageBox("Can't find any Video compressors!"); return hr; } hr = m_capture->get_AudioCompressors(&pAudioCompressors); if(FAILED(hr) && bSelect) { AfxMessageBox("Can't find any Audio compressors, You won't be able to capture Audio!"); pAudioCompressors = NULL; } if(!bSelect) { if(pVideoCompressors) pVideoCompressors->put_Selection(-1); if(pAudioCompressors) pAudioCompressors->put_Selection(-1); } else { long lIndex; // look for the LEAD MPEG-2 Professional Encoder first if((hr = pVideoCompressors->Find(LEAD_MPEG2_PROFESSIONAL, &lIndex)) != S_OK) hr = pVideoCompressors->Find(LEAD_MPEG2_STANDARD, &lIndex); if(FAILED(hr)) { AfxMessageBox("Cannot find the MPEG-2 encoder. You will not be able to capture MPEG-2 DICOM files!"); pVideoCompressors->Release(); if(pAudioCompressors) { pAudioCompressors->Release(); } return hr; } else { hr = pVideoCompressors->put_Selection(lIndex); if(SUCCEEDED(hr)) { // set the compatibility mode to DICOM IUnknown *pUnk; // get a pointer to the MPEG-2 object hr = m_capture->GetSubObject(ltmmCapture_Object_VideoCompressor, &pUnk); if(SUCCEEDED(hr)) { ILMMPEG2Encoder *pMPEG2Encoder; hr = pUnk->QueryInterface(IID_ILMMPEG2Encoder, (void**)&pMPEG2Encoder); if(SUCCEEDED(hr)) { pMPEG2Encoder->put_DefaultMpegMode(MPEG2MODE_DICOM); pMPEG2Encoder->put_RateControlMethod(MPEG2_CONSTANT_QUALITY); pMPEG2Encoder->put_QuantizerValue(8); pMPEG2Encoder->Release(); } pUnk->Release(); } } } lIndex = -1; if(pAudioCompressors) { hr = pAudioCompressors->Find(LEAD_MPEG_AUDIO_ENCODER, &lIndex); if(FAILED(hr) || (lIndex == -1)) { AfxMessageBox("Cannot find the LEAD MPEG Audio Encoder. You will not be able to capture Audio."); } else { hr = pAudioCompressors->put_Selection(lIndex); if(FAILED(hr)) { AfxMessageBox("Can't select the LEAD MPEG Audio Encoder, You will not be able to capture Audio."); } } } } if(pVideoCompressors) { pVideoCompressors->Release(); } if(pAudioCompressors) { pAudioCompressors->Release(); } return hr; } //Set the target format HRESULT CMainFrame::SetTargetFormat(DICOM_WRITER_FILTER_TARGET_FORMAT TargetFormat) { m_capture->EnterEdit(); HRESULT hr = S_FALSE; switch(TargetFormat) { case DICOM_WRITER_FILTER_TARGET_FORMAT_CUSTOM: hr = m_capture->put_TargetFormat(ltmmCapture_TargetFormat_DICOM); // clear any compressor (might have been set when we selected MPEG-2 DICOM) if(SUCCEEDED(hr)) hr = SelectMPEG2Compressor(FALSE); break; case DICOM_WRITER_FILTER_TARGET_FORMAT_MPEG2: hr = m_capture->put_TargetFormat(ltmmCapture_TargetFormat_MPEG2_DICOM); // select a MPEG-2 compressor if(SUCCEEDED(hr)) hr = SelectMPEG2Compressor(TRUE); break; default: hr = S_FALSE; } m_capture->LeaveEdit(); return hr; } DICOMVID_IMAGE_COMPRESSION CMainFrame::GetCompression() { return m_CompressionType; } HRESULT CMainFrame::SetCompression(DICOMVID_IMAGE_COMPRESSION ImageCompression) { m_CompressionType = ImageCompression; DICOM_WRITER_FILTER_TARGET_FORMAT TargetFormat = DICOM_WRITER_FILTER_TARGET_FORMAT_CUSTOM; if(m_CompressionType == DICOMVID_IMAGE_COMPRESSION_MPEG2) { TargetFormat = DICOM_WRITER_FILTER_TARGET_FORMAT_MPEG2; } else { int nDICOMCompression = COMP_UNCOMPRESSED; TargetFormat = DICOM_WRITER_FILTER_TARGET_FORMAT_CUSTOM; switch(m_CompressionType) { case DICOMVID_IMAGE_COMPRESSION_NONE: nDICOMCompression = COMP_UNCOMPRESSED; break; case DICOMVID_IMAGE_COMPRESSION_JPEGLOSSLESS: nDICOMCompression = COMP_LOSSLESSJPEG; break; case DICOMVID_IMAGE_COMPRESSION_JPEGLOSSY: nDICOMCompression = COMP_JPEG422; break; case DICOMVID_IMAGE_COMPRESSION_J2KLOSSLESS: nDICOMCompression = COMP_LOSSLESSJPEG2000; break; case DICOMVID_IMAGE_COMPRESSION_J2KLOSSY: nDICOMCompression = COMP_JPEG2000; break; default: return S_FALSE; } m_DicomWriter->put_CompressionFormat(nDICOMCompression); } return SetTargetFormat(TargetFormat); } long CMainFrame::GetTargetFormatStreams(long tf) { IltmmTargetFormats* targetformats; m_capture->get_TargetFormats(&targetformats); IltmmTargetFormat* targetformat; HRESULT hr = targetformats->Item(tf, &targetformat); targetformats->Release(); if(FAILED(hr) || !targetformat) return 0; long streams; targetformat->get_Streams(&streams); targetformat->Release(); return streams; } void CMainFrame::OnVideoDevice( UINT nID ) { if(m_bMMCapabilitiesInitialized) { BeginWaitCursor(); IltmmDevices* devices; m_capture->get_VideoDevices(&devices); devices->put_Selection(nID - ID_VIDEODEVICE - 1); devices->Release(); EndWaitCursor(); } } void CMainFrame::OnUpdateVideoDevice(CCmdUI* pCmdUI) { if(m_bMMCapabilitiesInitialized) { long state; m_capture->get_State(&state); pCmdUI->Enable(state != ltmmCapture_State_Running); IltmmDevices* devices; long index; m_capture->get_VideoDevices(&devices); devices->get_Selection(&index); devices->Release(); pCmdUI->SetCheck((long) (pCmdUI->m_nID - ID_VIDEODEVICE - 1) == index ? 1 : 0); } else { pCmdUI->Enable(FALSE); } } void CMainFrame::OnUpdateAudioDevice(CCmdUI* pCmdUI) { long state; m_capture->get_State(&state); pCmdUI->Enable(state != ltmmCapture_State_Running); IltmmDevices* devices; long index; m_capture->get_AudioDevices(&devices); devices->get_Selection(&index); devices->Release(); pCmdUI->SetCheck((long) (pCmdUI->m_nID - ID_AUDIODEVICE - 1) == index ? 1 : 0); } void CMainFrame::OnAudioDevice( UINT nID ) { BeginWaitCursor(); IltmmDevices* devices; m_capture->get_AudioDevices(&devices); HRESULT hr = devices->put_Selection(nID - ID_AUDIODEVICE - 1); if(FAILED(hr)) AfxMessageBox("This audio capture device is not available.\n" "Make sure no other program is using the device.\n" "If you have a player running, you can try setting \n" "the player so it plays to the MIDI device"); devices->Release(); EndWaitCursor(); } void CMainFrame::BuildDeviceMenu() { IltmmDevices* devices; long count, i; if(FALSE == m_bMMCapabilitiesInitialized) return; CMenu* menu = GetMenu()->GetSubMenu(2)->GetSubMenu(0); while(menu->RemoveMenu(0, MF_BYPOSITION)) ; m_capture->get_VideoDevices(&devices); devices->get_Count(&count); menu->AppendMenu(MF_STRING, ID_VIDEODEVICE, _T("None")); if(count) { devices->put_Selection(-1); for(i = 0; i < count; i++) { USES_CONVERSION; IltmmDevice* device; BSTR name; devices->Item(i, &device); device->get_FriendlyName(&name); menu->AppendMenu(MF_STRING, ID_VIDEODEVICE + i + 1, OLE2T(name)); SysFreeString(name); device->Release(); } } devices->Release(); menu = GetMenu()->GetSubMenu(2)->GetSubMenu(1); while(menu->RemoveMenu(0, MF_BYPOSITION)) ; m_capture->get_AudioDevices(&devices); devices->get_Count(&count); menu->AppendMenu(MF_STRING, ID_AUDIODEVICE, _T("None")); if(count) { devices->put_Selection(-1); for(i = 0; i < count; i++) { USES_CONVERSION; IltmmDevice* device; BSTR name; devices->Item(i, &device); device->get_FriendlyName(&name); menu->AppendMenu(MF_STRING, ID_AUDIODEVICE + i + 1, OLE2T(name)); SysFreeString(name); device->Release(); } } } void CMainFrame::BuildCompressionTypeMenu() { /* CMenu* menu = GetMenu()->GetSubMenu(2)->GetSubMenu(2); while(menu->RemoveMenu(0, MF_BYPOSITION)) ; menu->AppendMenu(MF_STRING, DICOMVID_IMAGE_COMPRESSION_NONE, "&Uncompressed"); menu->AppendMenu(MF_STRING, DICOMVID_IMAGE_COMPRESSION_JPEGLOSSLESS, "&Lossless JPEG"); menu->AppendMenu(MF_STRING, DICOMVID_IMAGE_COMPRESSION_JPEGLOSSY, "&JPEG 4:2:2"); menu->AppendMenu(MF_STRING, DICOMVID_IMAGE_COMPRESSION_J2KLOSSLESS, "L&ossless JPEG 2000"); menu->AppendMenu(MF_STRING, DICOMVID_IMAGE_COMPRESSION_J2KLOSSY, "JPEG &2000"); menu->AppendMenu(MF_STRING, DICOMVID_IMAGE_COMPRESSION_MPEG2, "&MPEG2"); */ } void CMainFrame::OnOptionsCaptureproperties() { if(FALSE == m_bMMCapabilitiesInitialized) return; m_capture->put_Preview(VARIANT_FALSE); m_capture->ShowDialog(ltmmCapture_Dlg_Capture, (long) m_hWnd); m_capture->put_Preview(VARIANT_TRUE); } void CMainFrame::OnUpdateOptionsCaptureproperties(CCmdUI* pCmdUI) { if(m_bMMCapabilitiesInitialized) { long state; m_capture->get_State(&state); VARIANT_BOOL f; m_capture->HasDialog(ltmmCapture_Dlg_Capture, &f); pCmdUI->Enable(f && state != ltmmCapture_State_Running); } else { pCmdUI->Enable(FALSE); } } BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) { // create splitter window if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE; if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(350, 100), pContext) || !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CDicomVidView), CSize(100, 100), pContext)) { m_wndSplitter.DestroyWindow(); return FALSE; } if(!InitMMCapabilities()) { return FALSE; } return TRUE; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers CDicomVidView* CMainFrame::GetRightPane() { CWnd* pWnd = m_wndSplitter.GetPane(0, 1); CDicomVidView* pView = DYNAMIC_DOWNCAST(CDicomVidView, pWnd); return pView; } void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI) { // TODO: customize or extend this code to handle choices on the // View menu. CDicomVidView* pView = GetRightPane(); // if the right-hand pane hasn't been created or isn't a view, // disable commands in our range if (pView == NULL) pCmdUI->Enable(FALSE); else { DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK; // if the command is ID_VIEW_LINEUP, only enable command // when we're in LVS_ICON or LVS_SMALLICON mode if (pCmdUI->m_nID == ID_VIEW_LINEUP) { if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON) pCmdUI->Enable(); else pCmdUI->Enable(FALSE); } else { // otherwise, use dots to reflect the style of the view pCmdUI->Enable(); BOOL bChecked = FALSE; switch (pCmdUI->m_nID) { case ID_VIEW_DETAILS: bChecked = (dwStyle == LVS_REPORT); break; case ID_VIEW_SMALLICON: bChecked = (dwStyle == LVS_SMALLICON); break; case ID_VIEW_LARGEICON: bChecked = (dwStyle == LVS_ICON); break; case ID_VIEW_LIST: bChecked = (dwStyle == LVS_LIST); break; default: bChecked = FALSE; break; } pCmdUI->SetRadio(bChecked ? 1 : 0); } } } void CMainFrame::OnViewStyle(UINT nCommandID) { // TODO: customize or extend this code to handle choices on the // View menu. CDicomVidView* pView = GetRightPane(); // if the right-hand pane has been created and is a CDicomVidView, // process the menu commands... if (pView != NULL) { DWORD dwStyle = -1; switch (nCommandID) { case ID_VIEW_LINEUP: { // ask the list control to snap to grid CListCtrl& refListCtrl = pView->GetListCtrl(); refListCtrl.Arrange(LVA_SNAPTOGRID); } break; // other commands change the style on the list control case ID_VIEW_DETAILS: dwStyle = LVS_REPORT; break; case ID_VIEW_SMALLICON: dwStyle = LVS_SMALLICON; break; case ID_VIEW_LARGEICON: dwStyle = LVS_ICON; break; case ID_VIEW_LIST: dwStyle = LVS_LIST; break; } // change the style; window will repaint automatically if (dwStyle != -1) pView->ModifyStyle(LVS_TYPEMASK, dwStyle); } } // Cleanup void CMainFrame::OnDestroy() { if(m_DicomWriter) { m_DicomWriter->Release(); m_DicomWriter = NULL; } if(m_pDICOMFilter) { m_pDICOMFilter->Release(); } if(m_capture) { m_capture->Release(); m_capture = NULL; } CFrameWnd::OnDestroy(); } void CMainFrame::SetDicomDS(LDicomDS *pDS) { if(m_DicomWriter) { m_DicomWriter->SetDicomDS( (long)pDS, NULL, FALSE, FALSE); } } // Start capturing void CMainFrame::OnCaptureStartcaptureintodicomfile() { if(FALSE == m_bMMCapabilitiesInitialized) return; CDicomVidDoc * pDicomVidDoc = NULL; pDicomVidDoc = (CDicomVidDoc *)GetActiveDocument(); if(pDicomVidDoc) { //Before you can start capturing we need a valid dataset ! if(pDicomVidDoc->IsDataSetInitialized()==FALSE) { AfxMessageBox("Before you start capturing please either load a DICOM file or create a new one."); return ; } } else { AfxMessageBox("Can't start capturing"); return ; } m_capture->put_Preview(VARIANT_FALSE); if(GetCompression() == DICOMVID_IMAGE_COMPRESSION_MPEG2) { AfxMessageBox( "Warning: Compressing MPEG2 data requires high computation power. We recommend using a high-end machine capable of handling this type of load." "\n\nPlease note that the size (width and height) of the video you capture heavily affects the speed of the compression process. For example compressing a (640X480) video is approximately four times slower than compressing a (320X240) video. You can change the size of the video by adjusting the \"Capture Properties\" from the \"Options\" menu."); } m_capture->put_Preview(TRUE); CWaitCursor Wait ; // Tell the DIOCM writer to capture into our dataset long lDS = 0; HRESULT hr = m_DicomWriter->get_DicomDS(&lDS); if(FAILED(hr)) { AfxMessageBox("Can't start capturing"); return; } if(0==lDS) { m_DicomWriter->SetDicomDS((long)(& (pDicomVidDoc->GetActiveDS())),NULL,FALSE,FALSE); } // Ok start capturing now if(GetCompression() == DICOMVID_IMAGE_COMPRESSION_MPEG2) { IltmmDevices* devices; long index = -1; m_capture->get_AudioDevices(&devices); devices->get_Selection(&index); devices->Release(); if(index ==-1) { hr = m_capture->StartCapture(ltmmCapture_Mode_Video); } else { hr = m_capture->StartCapture(ltmmCapture_Mode_VideoAndAudio); } } else { hr = m_capture->StartCapture(ltmmCapture_Mode_Video); } if(FAILED(hr)) { AfxMessageBox("Can't start capturing"); return; } //Show the user that capturing is in progress StartToolbarPlay(); pDicomVidDoc->SetModifiedFlag(TRUE); } void CMainFrame::OnUpdateCaptureStartcaptureintodicomfile(CCmdUI* pCmdUI) { if(m_bMMCapabilitiesInitialized) { long state; m_capture->get_State(&state); VARIANT_BOOL f; m_capture->IsModeAvailable(ltmmCapture_Mode_Video, &f); pCmdUI->Enable(f && state != ltmmCapture_State_Running); } else { pCmdUI->Enable(FALSE); } } //Stop capturing void CMainFrame::OnCaptureStopcapture() { CWaitCursor Wait ; if(FALSE == m_bMMCapabilitiesInitialized) return; HRESULT hr = m_capture->StopCapture(); if(FAILED(hr)) { AfxMessageBox("error stopping capturing"); } StopToolbarPlay(); } L_BOOL CMainFrame::IsCapturing() { if(m_capture) { long state; m_capture->get_State(&state); return ((ltmmCapture_State_Running == state) ? TRUE : FALSE); } return FALSE; } void CMainFrame::OnUpdateCaptureStopcapture(CCmdUI* pCmdUI) { if(m_bMMCapabilitiesInitialized) { long state; m_capture->get_State(&state); pCmdUI->Enable(IsCapturing()); } else { pCmdUI->Enable(FALSE); } } void CMainFrame::StartToolbarPlay() { if (FALSE == m_bNowPlaying) { m_wndToolBar.m_wndAnim.Play(0, -1, -1); m_bNowPlaying = TRUE; } } void CMainFrame::StopToolbarPlay() { if (m_bNowPlaying) { m_wndToolBar.m_wndAnim.Stop(); m_bNowPlaying = FALSE; } } void CMainFrame::OnUpdateAppExit(CCmdUI* pCmdUI) { pCmdUI->Enable(!IsCapturing()); } void CMainFrame::ShowMPEG2OptionsDlg() { HRESULT hr; if(GetCompression() == DICOMVID_IMAGE_COMPRESSION_MPEG2) { hr = m_capture->ShowDialog(ltmmCapture_Dlg_VideoCompressor, (long)m_hWnd); } else { hr = m_capture->ShowDialog(ltmmCapture_Dlg_TargetFormat, (long)m_hWnd); } m_capture->StopCapture(); if(FAILED(hr)) { AfxMessageBox(_T("Couln't bring up compression options dialog")); return; } } void CMainFrame::ShowMPEG2AudioOptionsDlg() { HRESULT hr; if(GetCompression() == DICOMVID_IMAGE_COMPRESSION_MPEG2) { hr = m_capture->ShowDialog(ltmmCapture_Dlg_AudioCompressor, (long)m_hWnd); } m_capture->StopCapture(); if(FAILED(hr)) { AfxMessageBox(_T("Couln't bring up audio compression options dialog")); return; } } void CMainFrame::OnCompressionSettings() { m_capture->put_Preview(VARIANT_FALSE); CCompressionSettingsDlg CompressionSettingsDlg; CompressionSettingsDlg.DoModal (); m_capture->put_Preview(VARIANT_TRUE); } void CMainFrame::SetQFactor(int nQFactor) { if(nQFactor < Q_FACTOR_MIN) { nQFactor = Q_FACTOR_MIN; } if(nQFactor > Q_FACTOR_MAX) { nQFactor = Q_FACTOR_MAX; } m_nQFactor = nQFactor; m_DicomWriter->put_CompressionQuality(m_nQFactor); } int CMainFrame::GetQFactor() { return m_nQFactor; } void CMainFrame::OnUpdateCompressionSettings(CCmdUI* pCmdUI) { if(m_bMMCapabilitiesInitialized) { CDicomVidDoc * pDicomVidDoc = NULL; pDicomVidDoc = (CDicomVidDoc *)GetActiveDocument(); if(pDicomVidDoc) { pCmdUI->Enable(pDicomVidDoc->IsDataSetInitialized() && (!IsCapturing())); pCmdUI->SetCheck( (pCmdUI->m_nID == (ULONG)GetCompression()) ? 1 : 0); } else { pCmdUI->Enable(FALSE); } } else { pCmdUI->Enable(FALSE); } }