home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / Mmdlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-15  |  28.3 KB  |  1,095 lines

  1. // MMDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MMApp.h"
  6. #include "MMDlg.h"
  7. #include "MMSave.h"
  8.  
  9. #define TIMER_ID          1
  10.  
  11. #define BALANCE_MIN    -100
  12. #define BALANCE_MED       0
  13. #define BALANCE_MAX     100
  14. #define BALANCE_POS       0
  15.  
  16. #define VOLUME_MIN        0
  17. #define VOLUME_MED       50
  18. #define VOLUME_MAX      100
  19. #define VOLUME_POS       50
  20.  
  21. #define SPEED_MIN         0
  22. #define SPEED_MED       100
  23. #define SPEED_MAX       200
  24. #define SPEED_POS       100
  25.  
  26. char szGraphOpenFilter[] = 
  27. {
  28.    "All Files (*.*)|"           "*.*|"
  29.    "LEAD (*.cmp)|"              "*.cmp|"
  30.    "CALS (*.cal)|"              "*.cal|"
  31.    "GEM Image (*.img)|"         "*.img|"
  32.    "CServe PNG (*.png)|"        "*.png|"
  33.    "DICOM DIC (*.dic)|"         "*.dic|"
  34.    "Exif (*.jpj)|"              "*.tif;*.jpg|"
  35. #ifdef WIN32
  36.    "FlashPix (*.fpx)|"          "*.fpx|"
  37. #endif
  38.    "GIF (*.gif)|"               "*.gif|"
  39.    "IOCA (*.ica)|"              "*.ica|"
  40.    "JPEG (*.jpg;*.jff;*.jtf)|"  "*.jpg;*.jff;*.jtf|"
  41.    "Mac PICTURE (*.pct)|"       "*.pct|"
  42.    "MacPaint (*.mac)|"          "*.mac|"
  43.    "MS Paint (*.msp)|"          "*.msp|"
  44. #ifdef WIN32
  45.    "MS Fax (*.awd)|"            "*.awd|"
  46. #endif
  47.    "Photo CD (*.pcd)|"          "*.pcd|"
  48.    "PCX (*.pcx)|"               "*.pcx|"
  49.    "PhotoShop PSD (*.psd)|"     "*.psd|"
  50.    "PostScript Raster (*.eps)|" "*.eps|"
  51.    "SUN Raster (*.ras)|"        "*.ras|"
  52.    "TGA (*.tga)|"               "*.tga|"
  53.    "TIF (*.tif)|"               "*.tif|"
  54.    "Win Metafile (*.wmf)|"      "*.wmf|"
  55.    "Win & OS/2 (*.bmp)|"        "*.bmp|"
  56.    "Winfax (*.fxs)|"            "*.fxs|"
  57.    "WordPerfect (*.wpg)|"       "*.wpg|"
  58.    "Win Icon (*.ico)|"          "*.ico|"
  59.    "Win Cursor (*.cur)|"        "*.cur|"
  60. };
  61.  
  62. char szVideoOpenFilter[] = 
  63. {
  64.    "AVI Files (*.avi)|" "*.avi|"
  65.    "WAV Files (*.wav)|" "*.wav|"
  66.    "All Files (*.*)|"   "*.*||" 
  67. };
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CAboutDlg dialog used for App About
  71.  
  72. class CAboutDlg : public CDialog
  73. {
  74. public:
  75.     CAboutDlg();
  76.  
  77. // Dialog Data
  78.     //{{AFX_DATA(CAboutDlg)
  79.     enum { IDD = IDD_ABOUTBOX };
  80.     //}}AFX_DATA
  81.  
  82.     // ClassWizard generated virtual function overrides
  83.     //{{AFX_VIRTUAL(CAboutDlg)
  84.     protected:
  85.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  86.     //}}AFX_VIRTUAL
  87.  
  88. // Implementation
  89. protected:
  90.     //{{AFX_MSG(CAboutDlg)
  91.     //}}AFX_MSG
  92.     DECLARE_MESSAGE_MAP()
  93. };
  94.  
  95. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  96. {
  97.     //{{AFX_DATA_INIT(CAboutDlg)
  98.     //}}AFX_DATA_INIT
  99. }
  100.  
  101. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  102. {
  103.     CDialog::DoDataExchange(pDX);
  104.     //{{AFX_DATA_MAP(CAboutDlg)
  105.     //}}AFX_DATA_MAP
  106. }
  107.  
  108. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  109.     //{{AFX_MSG_MAP(CAboutDlg)
  110.         // No message handlers
  111.     //}}AFX_MSG_MAP
  112. END_MESSAGE_MAP()
  113.  
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CMMDlg dialog
  116.  
  117. CMMDlg::CMMDlg(CWnd* pParent /*=NULL*/)
  118.     : CDialog(CMMDlg::IDD, pParent)
  119. {
  120.     //{{AFX_DATA_INIT(CMMDlg)
  121.     m_FrameMin = _T("");
  122.     m_FrameMax = _T("");
  123.     m_TimeMin  = _T("");
  124.     m_TimeMax  = _T("");
  125.     //}}AFX_DATA_INIT
  126.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  127.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  128.  
  129.    m_szVideoCompressor[0] = 0;
  130.    m_szAudioCompressor[0] = 0;
  131.    m_nAudioFormat         = -1;
  132. }
  133.  
  134. void CMMDlg::DoDataExchange(CDataExchange* pDX)
  135. {
  136.     CDialog::DoDataExchange(pDX);
  137.     //{{AFX_DATA_MAP(CMMDlg)
  138.     DDX_Control(pDX, IDC_FRAMEPOS, m_FramePos);
  139.     DDX_Control(pDX, IDC_TIMEPOS, m_TimePos);
  140.     DDX_Control(pDX, IDC_VIDEOFRAME, m_VideoFrame);
  141.     DDX_Control(pDX, IDC_ONOFF, m_OnOff);
  142.     DDX_Control(pDX, IDC_VOLUME, m_Volume);
  143.     DDX_Control(pDX, IDC_SPEED, m_Speed);
  144.     DDX_Control(pDX, IDC_BALANCE, m_Balance);
  145.     DDX_Control(pDX, IDC_PROGRESS, m_Progress);
  146.     DDX_Control(pDX, IDC_PLAY, m_Play);
  147.     DDX_Control(pDX, IDC_STOP, m_Stop);
  148.     DDX_Control(pDX, IDC_REWIND, m_Rewind);
  149.     DDX_Control(pDX, IDC_FORWARD, m_Forward);
  150.     DDX_Control(pDX, IDC_PREVMARK, m_PrevMark);
  151.     DDX_Control(pDX, IDC_NEXTMARK, m_NextMark);
  152.     DDX_Control(pDX, IDC_PREVFRAME, m_PrevFrame);
  153.     DDX_Control(pDX, IDC_NEXTFRAME, m_NextFrame);
  154.     DDX_Control(pDX, IDC_STARTSEL, m_StartSel);
  155.     DDX_Control(pDX, IDC_ENDSEL, m_EndSel);
  156.     DDX_Text(pDX, IDC_FRAMEMIN, m_FrameMin);
  157.     DDX_Text(pDX, IDC_FRAMEMAX, m_FrameMax);
  158.     DDX_Text(pDX, IDC_TIMEMIN, m_TimeMin);
  159.     DDX_Text(pDX, IDC_TIMEMAX, m_TimeMax);
  160.     DDX_Control(pDX, IDC_LEADDLG, m_LeadDlg);
  161.     DDX_Control(pDX, IDC_LEAD, m_Lead);
  162.     DDX_Control(pDX, IDC_LEADVIDEO, m_LeadVideo);
  163.     //}}AFX_DATA_MAP
  164. }
  165.  
  166. BEGIN_MESSAGE_MAP(CMMDlg, CDialog)
  167.     //{{AFX_MSG_MAP(CMMDlg)
  168.     ON_WM_SYSCOMMAND()
  169.     ON_COMMAND(ID_FILE_OPENREAD, OnFileOpenRead)
  170.     ON_COMMAND(ID_FILE_OPENEDIT, OnFileOpenEdit)
  171.     ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
  172.     ON_COMMAND(ID_FILE_SAVEAS, OnFileSaveAs)
  173.     ON_COMMAND(ID_EDIT_COPYFRAME, OnEditCopyFrame)
  174.     ON_COMMAND(ID_EDIT_PASTEFRAME, OnEditPasteFrame)
  175.     ON_COMMAND(ID_EDIT_INSERTFRAME, OnEditInsertFrame)
  176.     ON_COMMAND(ID_EDIT_REPLACEFRAME, OnEditReplaceFrame)
  177.     ON_COMMAND(ID_EDIT_DELETEFRAME, OnEditDeleteFrame)
  178.     ON_COMMAND(ID_EDIT_SAVEFRAME, OnEditSaveFrame)
  179.     ON_COMMAND(ID_HELP_ABOUTBOX, OnHelpAboutbox)
  180.     ON_BN_CLICKED(IDC_PLAY, OnPlay)
  181.     ON_BN_CLICKED(IDC_STOP, OnStop)
  182.     ON_BN_CLICKED(IDC_REWIND, OnRewind)
  183.     ON_BN_CLICKED(IDC_FORWARD, OnForward)
  184.     ON_BN_CLICKED(IDC_PREVMARK, OnPrevMark)
  185.     ON_BN_CLICKED(IDC_NEXTMARK, OnNextMark)
  186.     ON_BN_CLICKED(IDC_PREVFRAME, OnPrevFrame)
  187.     ON_BN_CLICKED(IDC_NEXTFRAME, OnNextFrame)
  188.     ON_BN_CLICKED(IDC_STARTSEL, OnStartSel)
  189.     ON_BN_CLICKED(IDC_ENDSEL, OnEndSel)
  190.     ON_WM_HSCROLL()
  191.     ON_WM_VSCROLL()
  192.     ON_WM_TIMER()
  193.     ON_WM_CLOSE()
  194.     //}}AFX_MSG_MAP
  195. END_MESSAGE_MAP()
  196.  
  197. /////////////////////////////////////////////////////////////////////////////
  198. // CMMDlg message handlers
  199.  
  200. BOOL CMMDlg::OnInitDialog()
  201. {
  202.    CRect rcVideo;
  203.    
  204.     CDialog::OnInitDialog();
  205.  
  206.     SetIcon(m_hIcon, TRUE);    
  207.     SetIcon(m_hIcon, FALSE);
  208.  
  209.    UNLOCKSUPPORT(m_Lead);
  210.    UNLOCKSUPPORT(m_LeadVideo);
  211.    
  212.    m_Lead.SetEnableMethodErrors(FALSE);
  213.    m_LeadVideo.SetEnableMethodErrors(FALSE);
  214.    m_LeadVideo.SetAutoResizeControl(FALSE);
  215.    m_LeadVideo.SetEnableProgressEvent(FALSE);
  216.  
  217.    m_OnOff.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
  218.    m_Play.SetIcon(AfxGetApp()->LoadIcon(IDI_PLAY));
  219.    m_Stop.SetIcon(AfxGetApp()->LoadIcon(IDI_STOP));
  220.    m_Rewind.SetIcon(AfxGetApp()->LoadIcon(IDI_REWIND));
  221.    m_Forward.SetIcon(AfxGetApp()->LoadIcon(IDI_FORWARD));
  222.    m_PrevFrame.SetIcon(AfxGetApp()->LoadIcon(IDI_PREVFRAME));
  223.    m_NextFrame.SetIcon(AfxGetApp()->LoadIcon(IDI_NEXTFRAME));
  224.    m_PrevMark.SetIcon(AfxGetApp()->LoadIcon(IDI_PREVMARK));
  225.    m_NextMark.SetIcon(AfxGetApp()->LoadIcon(IDI_NEXTMARK));
  226.    m_StartSel.SetIcon(AfxGetApp()->LoadIcon(IDI_STARTSEL));
  227.    m_EndSel.SetIcon(AfxGetApp()->LoadIcon(IDI_ENDSEL));
  228.  
  229.    m_Balance.SetRange(BALANCE_MIN, BALANCE_MAX, TRUE);
  230.    m_Balance.SetTic(BALANCE_MIN);
  231.    m_Balance.SetTic(BALANCE_MED);
  232.    m_Balance.SetTic(BALANCE_MAX);
  233.    m_Balance.SetPos(BALANCE_POS);
  234.  
  235.    m_Volume.SetRange(VOLUME_MIN, VOLUME_MAX, TRUE);
  236.    m_Volume.SetTic(VOLUME_MIN);
  237.    m_Volume.SetTic(VOLUME_MED);
  238.    m_Volume.SetTic(VOLUME_MAX);
  239.    m_Volume.SetPos(VOLUME_POS);
  240.  
  241.    m_Speed.SetRange(SPEED_MIN, SPEED_MAX, TRUE);
  242.    m_Speed.SetTic(SPEED_MIN);
  243.    m_Speed.SetTic(SPEED_MED);
  244.    m_Speed.SetTic(SPEED_MAX);
  245.    m_Speed.SetPos(SPEED_POS);
  246.  
  247.    m_ToolTip.Create(this);
  248.    m_ToolTip.Activate(TRUE);
  249.    m_ToolTip.AddTool(GetDlgItem(IDC_PLAY), "Play");
  250.    m_ToolTip.AddTool(GetDlgItem(IDC_STOP), "Stop");
  251.    m_ToolTip.AddTool(GetDlgItem(IDC_PREVFRAME), "Previous Frame");
  252.    m_ToolTip.AddTool(GetDlgItem(IDC_NEXTFRAME), "Next Frame");
  253.    m_ToolTip.AddTool(GetDlgItem(IDC_PREVMARK), "Previous Mark");
  254.    m_ToolTip.AddTool(GetDlgItem(IDC_NEXTMARK), "Next Mark");
  255.    m_ToolTip.AddTool(GetDlgItem(IDC_REWIND), "Rewind");
  256.    m_ToolTip.AddTool(GetDlgItem(IDC_FORWARD), "Forward");
  257.    m_ToolTip.AddTool(GetDlgItem(IDC_STARTSEL), "Start Selection");
  258.    m_ToolTip.AddTool(GetDlgItem(IDC_ENDSEL), "End Selection");
  259.  
  260.    m_fLeadVideo = FALSE;
  261.  
  262.    m_VideoFrame.GetWindowRect(m_rcVideoFrame);
  263.    ScreenToClient(m_rcVideoFrame);
  264.    m_VideoFrame.GetClientRect(rcVideo);
  265.    m_LeadVideo.MoveWindow(m_rcVideoFrame.TopLeft().x + (m_rcVideoFrame.Width() - rcVideo.Width()) / 2, m_rcVideoFrame.TopLeft().y + (m_rcVideoFrame.Height() - rcVideo.Height()) / 2, rcVideo.Width(), rcVideo.Height(), TRUE);
  266.  
  267.    SetButtons();
  268.    InitProgress(0, 0);
  269.    SetProgress(0);
  270.  
  271.    SetTimer(TIMER_ID, 100, NULL);
  272.  
  273.    return TRUE;  // return TRUE  unless you set the focus to a control
  274. }
  275.  
  276. void CMMDlg::OnSysCommand(UINT nID, LPARAM lParam)
  277. {
  278.    SetMenu();
  279.  
  280.    CDialog::OnSysCommand(nID, lParam);
  281. }
  282.  
  283. BOOL CMMDlg::PreTranslateMessage(MSG* pMsg)
  284. {
  285.     m_ToolTip.RelayEvent(pMsg);
  286.  
  287.     return CDialog::PreTranslateMessage(pMsg);
  288. }
  289.  
  290. BEGIN_EVENTSINK_MAP(CMMDlg, CDialog)
  291.     //{{AFX_EVENTSINK_MAP(CMMDlg)
  292.     ON_EVENT(CMMDlg, IDC_LEADVIDEO, 1 /* MMCompressor */, OnMMCompressor, VTS_BSTR)
  293.     ON_EVENT(CMMDlg, IDC_LEADVIDEO, 3 /* MMModeChange */, OnMMModeChange, VTS_I2)
  294.     //}}AFX_EVENTSINK_MAP
  295. END_EVENTSINK_MAP()
  296.  
  297. void CMMDlg::OnClose() 
  298. {
  299.    KillTimer(TIMER_ID);
  300.    OnFileClose();
  301.     
  302.     CDialog::OnClose();
  303. }
  304.  
  305. void CMMDlg::OnFileOpenRead() 
  306. {
  307.    int nResult;
  308.  
  309.    OnFileClose();
  310.  
  311.    nResult = OpenFile(MODE_PLAYBACK);
  312.    if (nResult != S_OK)
  313.    {
  314.       if (nResult != ERROR_DLG_CANCELED)
  315.       {
  316.          DisplayError(nResult);
  317.       }
  318.       return;
  319.    }
  320.  
  321.    m_fLeadVideo = TRUE;
  322.  
  323.    SetButtons();
  324.    InitProgress(0, m_LeadVideo.GetMMTotalFrames());
  325.    SetProgress(0);
  326. }
  327.  
  328. void CMMDlg::OnFileOpenEdit() 
  329. {
  330.    int nResult;
  331.  
  332.    OnFileClose();
  333.  
  334.    nResult = OpenFile(MODE_EDIT);
  335.    if (nResult != S_OK)
  336.    {
  337.       if (nResult != ERROR_DLG_CANCELED)
  338.       {
  339.          DisplayError(nResult);
  340.       }
  341.       return;
  342.    }
  343.  
  344.    m_fLeadVideo = TRUE;
  345.  
  346.    SetButtons();
  347.    InitProgress(0, m_LeadVideo.GetMMTotalFrames());
  348.    SetProgress(0);
  349. }
  350.  
  351. void CMMDlg::OnFileClose() 
  352. {
  353.    if (m_fLeadVideo)
  354.    {
  355.       if (m_LeadVideo.GetMMIsPlaying())
  356.       {
  357.          m_LeadVideo.MMStop();
  358.       }
  359.  
  360.       m_LeadVideo.MMClose();
  361.       m_fLeadVideo = FALSE;
  362.  
  363.       SetButtons();
  364.       InitProgress(0, 0);
  365.       SetProgress(0);
  366.    }
  367. }
  368.  
  369. void CMMDlg::OnFileSaveAs() 
  370. {
  371.    int nResult;
  372.  
  373.    nResult = SaveFile(MODE_EDIT);
  374.    if (nResult != S_OK)
  375.    {
  376.       if (nResult != ERROR_DLG_CANCELED)
  377.       {
  378.          DisplayError(nResult);
  379.       }
  380.    }
  381. }
  382.  
  383. void CMMDlg::OnEditCopyFrame() 
  384. {
  385.    int nResult;
  386.  
  387.    nResult = m_LeadVideo.MMCopyFramesToClipboard(m_Progress.GetPos(), 1);
  388.    if (nResult != S_OK)
  389.    {
  390.       DisplayError(nResult);
  391.    }
  392. }
  393.  
  394. void CMMDlg::OnEditPasteFrame() 
  395. {
  396.    int nResult, nMin, nMax;
  397.  
  398.    nResult = m_LeadVideo.MMPasteFrames(m_Progress.GetPos(), -1);
  399.    if (nResult != S_OK)
  400.    {
  401.       DisplayError(nResult);
  402.    }
  403.  
  404.    m_Progress.GetSelection(nMin, nMax);
  405.    InitProgress(nMin, nMax);
  406.    SetProgress(m_Progress.GetPos());
  407. }
  408.  
  409. void CMMDlg::OnEditInsertFrame() 
  410. {
  411.    int nResult, nMin, nMax;
  412.    
  413.    nResult = OpenFile(-1);
  414.    if (nResult != S_OK)
  415.    {
  416.       if (nResult != ERROR_DLG_CANCELED)
  417.       {
  418.          DisplayError(nResult);
  419.       }
  420.       return;
  421.    }
  422.  
  423.    m_Progress.GetSelection(nMin, nMax);
  424.    InitProgress(nMin, nMax);
  425.    SetProgress(m_Progress.GetPos());
  426. }
  427.  
  428. void CMMDlg::OnEditReplaceFrame() 
  429. {
  430.    int nResult;
  431.    
  432.    nResult = m_LeadVideo.MMDeleteFrames(m_Progress.GetPos(), 1);
  433.    if (nResult != S_OK)
  434.    {
  435.       DisplayError(nResult);
  436.       return;
  437.    }
  438.  
  439.    nResult = OpenFile(-1);
  440.    if (nResult != S_OK)
  441.    {
  442.       if (nResult != ERROR_DLG_CANCELED)
  443.       {
  444.          DisplayError(nResult);
  445.       }
  446.       return;
  447.    }
  448.  
  449.    SetProgress(m_Progress.GetPos());
  450. }
  451.  
  452. void CMMDlg::OnEditDeleteFrame() 
  453. {
  454.    int nPos, nResult, nMin, nMax;
  455.  
  456.    nPos = m_Progress.GetPos();
  457.  
  458.    nResult = m_LeadVideo.MMDeleteFrames(nPos, 1);
  459.    if (nResult != S_OK)
  460.    {
  461.       DisplayError(nResult);
  462.       return;
  463.    }
  464.  
  465.    if (nPos >= m_LeadVideo.GetMMTotalFrames())
  466.    {
  467.       m_Progress.SetPos(m_LeadVideo.GetMMTotalFrames());
  468.    }
  469.  
  470.    m_Progress.GetSelection(nMin, nMax);
  471.    InitProgress(nMin, nMax);
  472.    SetProgress(m_Progress.GetPos());
  473. }
  474.  
  475. void CMMDlg::OnEditSaveFrame() 
  476. {
  477.    int nResult;
  478.  
  479.    nResult = SaveFile(-1);
  480.    if (nResult != S_OK)
  481.    {
  482.       if (nResult != ERROR_DLG_CANCELED)
  483.       {
  484.          DisplayError(nResult);
  485.       }
  486.    }
  487. }
  488.  
  489. void CMMDlg::OnHelpAboutbox() 
  490. {
  491.    CAboutDlg dlg;
  492.    dlg.DoModal();
  493. }
  494.  
  495. void CMMDlg::OnPlay() 
  496. {
  497.    int nMin, nMax, nPos;
  498.  
  499.    if (m_LeadVideo.GetMMIsPlaying())
  500.    {
  501.       m_LeadVideo.MMPause();
  502.    }
  503.    else
  504.    {
  505.       m_Progress.GetSelection(nMin, nMax);
  506.       nPos = m_Progress.GetPos();
  507.       if(nMin <= nPos  && nPos < nMax)
  508.          nMin = nPos;
  509.       m_LeadVideo.SetMMClipStart(nMin);
  510.       m_LeadVideo.SetMMClipEnd(nMax);
  511.       m_LeadVideo.MMPlay();
  512.    }
  513. }
  514.  
  515. void CMMDlg::OnStop() 
  516. {
  517.    int nMin, nMax;
  518.  
  519.    m_LeadVideo.MMStop();
  520.    m_Progress.GetSelection(nMin, nMax);
  521.    SetProgress(nMin);
  522. }
  523.  
  524. void CMMDlg::OnRewind() 
  525. {
  526.    SetProgress(0);
  527. }
  528.  
  529. void CMMDlg::OnForward() 
  530. {
  531.    SetProgress(m_LeadVideo.GetMMTotalFrames());
  532. }
  533.  
  534. void CMMDlg::OnPrevMark() 
  535. {
  536.    int nMin, nMax;
  537.    
  538.    m_Progress.GetSelection(nMin, nMax);
  539.    SetProgress(nMin);
  540. }
  541.  
  542. void CMMDlg::OnNextMark() 
  543. {
  544.    int nMin, nMax;
  545.    
  546.    m_Progress.GetSelection(nMin, nMax);
  547.    SetProgress(nMax);
  548. }
  549.  
  550. void CMMDlg::OnPrevFrame() 
  551. {
  552.    SetProgress(m_Progress.GetPos() - 1);
  553. }
  554.  
  555. void CMMDlg::OnNextFrame() 
  556. {
  557.    SetProgress(m_Progress.GetPos() + 1);
  558. }
  559.  
  560. void CMMDlg::OnStartSel() 
  561. {
  562.    int nMin, nMax;
  563.    
  564.    m_Progress.GetSelection(nMin, nMax);
  565.    nMin = m_Progress.GetPos();
  566.    InitProgress(nMin, nMax);
  567. }
  568.  
  569. void CMMDlg::OnEndSel() 
  570. {
  571.    int nMin, nMax;
  572.    
  573.    m_Progress.GetSelection(nMin, nMax);
  574.    nMax = m_Progress.GetPos();
  575.    InitProgress(nMin, nMax);
  576. }
  577.  
  578. void CMMDlg::OnTimer(UINT nIDEvent) 
  579. {
  580.    long nPos;
  581.  
  582.    if (m_fLeadVideo)
  583.    {
  584.       nPos = m_LeadVideo.GetMMCurrentPos();
  585.  
  586.       if (m_LeadVideo.GetMMIsPlaying())
  587.       {
  588.          nPos = m_LeadVideo.GetMMCurrentPos();
  589.          DisplayPosition(nPos, IDC_TIMEPOS, IDC_FRAMEPOS);
  590.          m_Progress.SetPos(nPos);
  591.  
  592.          if (m_nOnOff)
  593.          {
  594.             m_OnOff.SetIcon(AfxGetApp()->LoadIcon(IDI_ONLOW));
  595.             m_nOnOff = 0;
  596.          }
  597.          else
  598.          {
  599.             m_OnOff.SetIcon(AfxGetApp()->LoadIcon(IDI_ONHIGH));
  600.             m_nOnOff = 1;
  601.          }
  602.       }
  603.    }
  604.     
  605.     CDialog::OnTimer(nIDEvent);
  606. }
  607.  
  608. void CMMDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  609. {
  610.    if (m_fLeadVideo == FALSE)
  611.    {
  612.       return;
  613.    }
  614.    
  615.    if ((CSliderCtrl *)pScrollBar == &m_Balance)
  616.    {
  617.       m_LeadVideo.SetMMBalance(-m_Balance.GetPos());
  618.    }
  619.    else
  620.    if ((CSliderCtrl *)pScrollBar == &m_Progress)
  621.    {
  622.       int nPos;
  623.       
  624.       nPos = m_Progress.GetPos();
  625.  
  626.       if (nPos != m_LeadVideo.GetMMCurrentPos())
  627.       {
  628.          SetProgress(nPos);
  629.       }
  630.    }
  631.     
  632.     CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  633. }
  634.  
  635. void CMMDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  636. {
  637.    if (m_fLeadVideo == FALSE)
  638.    {
  639.       return;
  640.    }
  641.  
  642.    if ((CSliderCtrl *)pScrollBar == &m_Volume)
  643.    {
  644.       m_LeadVideo.SetMMVolume(m_Volume.GetPos());
  645.    }
  646.    else
  647.    if ((CSliderCtrl *)pScrollBar == &m_Speed)
  648.    {
  649.       m_LeadVideo.SetMMPlayRate((float)m_Speed.GetPos() / 100);
  650.    }
  651.     
  652.     CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  653. }
  654.  
  655. int CMMDlg::DisplayError (int nCode)
  656. {
  657.    char str[128];
  658.  
  659.    if (nCode != S_OK)
  660.    {
  661.       wsprintf(str, "A LEADTOOLS error has occured.\nCODE = %d", nCode);
  662.       MessageBox(str, NULL, MB_ICONERROR);
  663.    }
  664.    
  665.    return nCode;
  666. }
  667.  
  668. int CMMDlg::OpenFile(int nMode)
  669. {
  670.    int   nResult, nZoom, nWidth, nHeight, nLeft, nTop;
  671.    CRect rcVideo;
  672.  
  673.    m_LeadDlg.SetEnableMethodErrors(FALSE);
  674.    m_LeadDlg.SetPreviewEnabled(TRUE);
  675.    m_LeadDlg.SetFileDlgFlags(0);
  676.    m_LeadDlg.SetUIFlags(DLG_FO_95STYLE | DLG_FO_MULTIPAGE | DLG_FO_FILEINFO | DLG_FO_SHOWPREVIEW | DLG_FO_SHOWSTAMP);
  677.    m_LeadDlg.SetDialogTitle("Open File");
  678.  
  679.    if ((nMode != MODE_PLAYBACK) && (nMode != MODE_EDIT))
  680.    {
  681.       m_LeadDlg.SetFilter(szGraphOpenFilter);
  682.    }
  683.    else
  684.    {
  685.       m_LeadDlg.SetFilter(szVideoOpenFilter);
  686.    }
  687.  
  688.    //You must move the Video Control off the screen or else it
  689.    //traps input and never sets focus back correctly when
  690.    //user selects a file by double clicking on the filename
  691.    //in the FileOpen dialog.  This is due to the Playback
  692.    //window which is created by Microsoft ActiveMovie.
  693.    CRect rcWin;
  694.    m_LeadVideo.GetWindowRect(&rcWin);
  695.    m_LeadVideo.SetWindowPos(NULL, -400, 0, 0, 0, SWP_NOSIZE);
  696.    nResult = m_LeadDlg.FileOpen((long)this->m_hWnd);
  697.    m_LeadVideo.SetWindowPos(NULL, rcWin.left, rcWin.top, 0, 0, SWP_NOSIZE);
  698.    if (nResult != S_OK)
  699.    {
  700.       return nResult;
  701.    }
  702.  
  703.    if ((nMode != MODE_PLAYBACK) && (nMode != MODE_EDIT))
  704.    {
  705.       BeginWaitCursor();
  706.       nResult = m_LeadVideo.MMInsertFrame(m_Progress.GetPos(), (char far *)((LPCTSTR)m_LeadDlg.GetFileName()));
  707.       EndWaitCursor();
  708.    }
  709.    else
  710.    {
  711.       BeginWaitCursor();
  712.       m_LeadVideo.SetControlMode(nMode);
  713.       nResult = m_LeadVideo.MMLoad((char far *)((LPCTSTR)m_LeadDlg.GetFileName()));
  714.       if (nResult != S_OK)
  715.       {
  716.          EndWaitCursor();
  717.          return nResult;
  718.       }
  719.       nResult = S_OK;
  720.  
  721.       m_LeadVideo.SetMMBalance(-m_Balance.GetPos());
  722.       m_LeadVideo.SetMMVolume(m_Volume.GetPos());
  723.       m_LeadVideo.SetMMPlayRate((float)m_Speed.GetPos() / 100);
  724.  
  725.       if ((m_LeadVideo.GetVideoWidth() <= 0) || (m_LeadVideo.GetVideoHeight() <= 0))
  726.       {
  727.          EndWaitCursor();
  728.          return S_OK;
  729.       }
  730.  
  731.       nZoom = max(min(((long)m_rcVideoFrame.Width() * 1000L / (long)m_LeadVideo.GetVideoWidth()), ((long)m_rcVideoFrame.Height() * 1000L / (long)m_LeadVideo.GetVideoHeight())), 1L);
  732.       nWidth  = MulDiv(m_LeadVideo.GetVideoWidth(), nZoom, 1000);
  733.       nHeight = MulDiv(m_LeadVideo.GetVideoHeight(), nZoom, 1000);
  734.  
  735.       nLeft   = (m_rcVideoFrame.Width() - nWidth) / 2 + m_rcVideoFrame.TopLeft().x;
  736.       nTop    = (m_rcVideoFrame.Height() - nHeight) / 2 + m_rcVideoFrame.TopLeft().y;
  737.  
  738.       m_VideoFrame.MoveWindow(nLeft, nTop, nWidth, nHeight, TRUE);
  739.       m_VideoFrame.GetClientRect(rcVideo);
  740.       m_LeadVideo.MoveWindow(nLeft + (nWidth - rcVideo.Width()) / 2, nTop + (nHeight - rcVideo.Height()) / 2, rcVideo.Width(), rcVideo.Height(), TRUE);
  741.       EndWaitCursor();
  742.    }
  743.  
  744.    return nResult;
  745. }
  746.  
  747. void CMMDlg::OnMMCompressor(LPCTSTR szName) 
  748. {
  749.    if (m_nCompressor == COMPRESSOR_VIDEO)
  750.    {
  751.       if (m_strVideoCompressor == NULL)
  752.       {
  753.          m_nVideoIndex++;
  754.       }
  755.       else
  756.       {
  757.          m_strVideoCompressor[m_nVideoIndex++] = szName;
  758.       }
  759.    }
  760.    else
  761.    {
  762.       if (m_strAudioCompressor == NULL)
  763.       {
  764.          m_nAudioIndex++;
  765.       }
  766.       else
  767.       {
  768.          m_strAudioCompressor[m_nAudioIndex++] = szName;
  769.       }
  770.    }
  771. }
  772.  
  773. int CMMDlg::SaveFile(int nMode)
  774. {
  775.    int     nResult;
  776.    CMMSave dlgSave;
  777.  
  778.    if ((nMode != MODE_PLAYBACK) && (nMode != MODE_EDIT))
  779.    {
  780.       m_LeadDlg.SetEnableMethodErrors(FALSE);
  781.       m_LeadDlg.SetFileDlgFlags(0);
  782.       m_LeadDlg.SetUIFlags(DLG_FS_95STYLE | DLG_FS_MULTIPAGE | DLG_FS_QFACTOR);
  783.       m_LeadDlg.SetSaveFormatFlags(DLG_FS_ALL);
  784.       m_LeadDlg.SetDialogTitle("Save File");
  785.  
  786.       nResult = m_LeadDlg.FileSave((long)(this->m_hWnd));
  787.       if (nResult != S_OK)
  788.       {
  789.          return nResult;
  790.       }
  791.  
  792.       BeginWaitCursor();
  793.        nResult = m_LeadVideo.MMSaveFrame((char far *)((LPCTSTR)m_LeadDlg.GetFileName()), m_LeadDlg.GetSaveFormat(), m_LeadDlg.GetSaveBitsPerPixel(), m_LeadDlg.GetSaveQFactor(), m_LeadDlg.GetSaveMulti());
  794.       EndWaitCursor();
  795.    }
  796.    else
  797.    {
  798.       m_nCompressor        = COMPRESSOR_VIDEO;
  799.       m_nVideoIndex        = 0;
  800.       m_strVideoCompressor = NULL;
  801.       m_LeadVideo.MMEnumCompressors(m_nCompressor);
  802.       
  803.       m_strVideoCompressor = new CString[m_nVideoIndex];
  804.       m_nVideoIndex        = 0;
  805.       m_LeadVideo.MMEnumCompressors(m_nCompressor);
  806.  
  807.       m_nCompressor        = COMPRESSOR_AUDIO;
  808.       m_nAudioIndex        = 0;
  809.       m_strAudioCompressor = NULL;
  810.       m_LeadVideo.MMEnumCompressors(m_nCompressor);
  811.       
  812.       m_strAudioCompressor = new CString[m_nAudioIndex];
  813.       m_nAudioIndex        = 0;
  814.       m_LeadVideo.MMEnumCompressors(m_nCompressor);
  815.  
  816.       strcpy(dlgSave.m_szVideoCompressor, m_szVideoCompressor);
  817.       strcpy(dlgSave.m_szAudioCompressor, m_szAudioCompressor);
  818.  
  819.       dlgSave.m_strVideoCompressor = m_strVideoCompressor;
  820.       dlgSave.m_nVideoIndex        = m_nVideoIndex;
  821.       dlgSave.m_strAudioCompressor = m_strAudioCompressor;
  822.       dlgSave.m_nAudioIndex        = m_nAudioIndex;
  823.       dlgSave.m_nAudioFormat       = m_nAudioFormat;
  824.  
  825.       if (dlgSave.DoModal() != IDOK)
  826.       {
  827.          return ERROR_DLG_CANCELED;
  828.       }
  829.  
  830.       strcpy(m_szVideoCompressor, dlgSave.m_szVideoCompressor);
  831.       strcpy(m_szAudioCompressor, dlgSave.m_szAudioCompressor);
  832.       m_nAudioFormat = dlgSave.m_nAudioFormat;
  833.  
  834.  
  835.       BeginWaitCursor();
  836.       if (m_LeadVideo.GetControlMode() == MODE_PLAYBACK)
  837.       {
  838.          nResult = m_LeadVideo.MMSaveFile((char far *)((LPCTSTR)dlgSave.GetFileName()), FILE_AVI, m_szVideoCompressor, m_szAudioCompressor);
  839.       }
  840.       else
  841.       {
  842.          nResult = m_LeadVideo.MMSaveFile((char far *)((LPCTSTR)dlgSave.GetFileName()), FILE_AVI, m_szVideoCompressor, m_szAudioCompressor);
  843.       }
  844.       EndWaitCursor();
  845.  
  846.       delete []m_strVideoCompressor;
  847.       delete []m_strAudioCompressor;
  848.    }
  849.  
  850.    return nResult;
  851. }
  852.  
  853. void CMMDlg::SetMenu()
  854. {
  855.    CMenu *pMenu=GetMenu();
  856.  
  857.    if (pMenu == NULL)
  858.    {
  859.       return;
  860.    }
  861.  
  862.    if (m_fLeadVideo != FALSE)
  863.    {
  864.       pMenu->EnableMenuItem(ID_FILE_CLOSE, MF_ENABLED);
  865.       pMenu->EnableMenuItem(ID_FILE_SAVE, MF_ENABLED);
  866.       pMenu->EnableMenuItem(ID_FILE_SAVEAS, MF_ENABLED);
  867.  
  868.       if (m_LeadVideo.GetControlMode() == MODE_PLAYBACK)
  869.       {
  870.          pMenu->EnableMenuItem(ID_EDIT_COPYFRAME, MF_DISABLED | MF_GRAYED);
  871.          pMenu->EnableMenuItem(ID_EDIT_PASTEFRAME, MF_DISABLED | MF_GRAYED);
  872.          pMenu->EnableMenuItem(ID_EDIT_INSERTFRAME, MF_DISABLED | MF_GRAYED);
  873.          pMenu->EnableMenuItem(ID_EDIT_REPLACEFRAME, MF_DISABLED | MF_GRAYED);
  874.          pMenu->EnableMenuItem(ID_EDIT_DELETEFRAME, MF_DISABLED | MF_GRAYED);
  875.          pMenu->EnableMenuItem(ID_EDIT_SAVEFRAME, MF_DISABLED | MF_GRAYED);
  876.       }
  877.       else
  878.       {
  879.          pMenu->EnableMenuItem(ID_EDIT_COPYFRAME, MF_ENABLED);
  880.  
  881.          if (m_LeadVideo.GetMMIsClipboardReady() != 0)
  882.          {
  883.             pMenu->EnableMenuItem(ID_EDIT_PASTEFRAME, MF_ENABLED);
  884.          }
  885.          else
  886.          {
  887.             pMenu->EnableMenuItem(ID_EDIT_PASTEFRAME, MF_DISABLED | MF_GRAYED);
  888.          }
  889.          
  890.          pMenu->EnableMenuItem(ID_EDIT_INSERTFRAME, MF_ENABLED);
  891.          pMenu->EnableMenuItem(ID_EDIT_REPLACEFRAME, MF_ENABLED);
  892.          pMenu->EnableMenuItem(ID_EDIT_DELETEFRAME, MF_ENABLED);
  893.          pMenu->EnableMenuItem(ID_EDIT_SAVEFRAME, MF_ENABLED);
  894.       }
  895.    }
  896.    else
  897.    {
  898.       pMenu->EnableMenuItem(ID_FILE_SAVE, MF_DISABLED | MF_GRAYED);
  899.       pMenu->EnableMenuItem(ID_FILE_SAVEAS, MF_DISABLED | MF_GRAYED);
  900.       pMenu->EnableMenuItem(ID_FILE_CLOSE, MF_DISABLED | MF_GRAYED);
  901.       pMenu->EnableMenuItem(ID_EDIT_COPYFRAME, MF_DISABLED | MF_GRAYED);
  902.       pMenu->EnableMenuItem(ID_EDIT_PASTEFRAME, MF_DISABLED | MF_GRAYED);
  903.       pMenu->EnableMenuItem(ID_EDIT_INSERTFRAME, MF_DISABLED | MF_GRAYED);
  904.       pMenu->EnableMenuItem(ID_EDIT_REPLACEFRAME, MF_DISABLED | MF_GRAYED);
  905.       pMenu->EnableMenuItem(ID_EDIT_DELETEFRAME, MF_DISABLED | MF_GRAYED);
  906.       pMenu->EnableMenuItem(ID_EDIT_SAVEFRAME, MF_DISABLED | MF_GRAYED);
  907.    }
  908. }
  909.  
  910. void CMMDlg::SetButtons()
  911. {
  912.    m_OnOff.SetIcon(AfxGetApp()->LoadIcon(IDI_OFF));
  913.  
  914.    if (m_fLeadVideo != FALSE)
  915.    {
  916.       if (m_LeadVideo.GetMMIsPlaying())
  917.       {
  918.          m_Play.EnableWindow(TRUE);
  919.          m_Stop.EnableWindow(TRUE);
  920.          m_Rewind.EnableWindow(FALSE);
  921.          m_Forward.EnableWindow(FALSE);
  922.          m_PrevFrame.EnableWindow(FALSE);
  923.          m_NextFrame.EnableWindow(FALSE);
  924.          m_PrevMark.EnableWindow(FALSE);
  925.          m_NextMark.EnableWindow(FALSE);
  926.          m_StartSel.EnableWindow(FALSE);
  927.          m_EndSel.EnableWindow(FALSE);
  928.  
  929.          m_Play.SetIcon(AfxGetApp()->LoadIcon(IDI_PAUSE));
  930.  
  931.          m_ToolTip.DelTool(GetDlgItem(IDC_PLAY));
  932.          m_ToolTip.AddTool(GetDlgItem(IDC_PLAY), "Pause");
  933.       }
  934.       else
  935.       {
  936.          m_Play.EnableWindow(TRUE);
  937.          m_Stop.EnableWindow(FALSE);
  938.          m_Rewind.EnableWindow(TRUE);
  939.          m_Forward.EnableWindow(TRUE);
  940.          m_PrevFrame.EnableWindow(TRUE);
  941.          m_NextFrame.EnableWindow(TRUE);
  942.          m_PrevMark.EnableWindow(TRUE);
  943.          m_NextMark.EnableWindow(TRUE);
  944.          m_StartSel.EnableWindow(TRUE);
  945.          m_EndSel.EnableWindow(TRUE);
  946.  
  947.          m_Play.SetIcon(AfxGetApp()->LoadIcon(IDI_PLAY));
  948.  
  949.          m_ToolTip.DelTool(GetDlgItem(IDC_PLAY));
  950.          m_ToolTip.AddTool(GetDlgItem(IDC_PLAY), "Play");
  951.       }
  952.    }
  953.    else
  954.    {
  955.       m_Play.EnableWindow(FALSE);
  956.       m_Stop.EnableWindow(FALSE);
  957.       m_Rewind.EnableWindow(FALSE);
  958.       m_Forward.EnableWindow(FALSE);
  959.       m_PrevFrame.EnableWindow(FALSE);
  960.       m_NextFrame.EnableWindow(FALSE);
  961.       m_PrevMark.EnableWindow(FALSE);
  962.       m_NextMark.EnableWindow(FALSE);
  963.       m_StartSel.EnableWindow(FALSE);
  964.       m_EndSel.EnableWindow(FALSE);
  965.  
  966.       m_Play.SetIcon(AfxGetApp()->LoadIcon(IDI_PLAY));
  967.  
  968.       m_ToolTip.DelTool(GetDlgItem(IDC_PLAY));
  969.       m_ToolTip.AddTool(GetDlgItem(IDC_PLAY), "Play");
  970.    }
  971. }
  972.  
  973. void CMMDlg::DisplayPosition(long nPosition, int nTimeID, int nFrameID)
  974. {
  975.    int   nFormat, nResult;
  976.    long nTime=-1, nFrame=-1;
  977.    CString strText;
  978.  
  979.    if (m_fLeadVideo != FALSE)
  980.    {
  981.       nFormat = m_LeadVideo.GetMMTimeFormat();
  982.  
  983.       if (nFormat == TIME_MILLISEC)
  984.       {
  985.          nTime = nPosition;
  986.          nResult = m_LeadVideo.MMConvertTime(&nFrame, TIME_FRAME, nTime, TIME_MILLISEC);
  987.          if (nResult != S_OK)
  988.          {
  989.             nFrame = -1;
  990.          }
  991.       }
  992.       else
  993.       {
  994.          nFrame = nPosition;
  995.          nResult = m_LeadVideo.MMConvertTime(&nTime, TIME_MILLISEC, nFrame, TIME_FRAME);
  996.          if (nResult != S_OK)
  997.          {
  998.             nTime = -1;
  999.          }
  1000.       }
  1001.    }
  1002.  
  1003.    if (nFrame >= 0)
  1004.    {
  1005.       strText.Format("%ld", nFrame);
  1006.    }
  1007.    else
  1008.    {
  1009.       strText = "";
  1010.    }
  1011.  
  1012.    SetDlgItemText(nFrameID, strText);
  1013.    m_FramePos.RedrawWindow();
  1014.  
  1015.    if (nTime >= 0)
  1016.    {
  1017.       strText.Format("%02ld:%02ld", (nTime / 1000) / 60, (nTime / 1000) % 60);
  1018.    }
  1019.    else
  1020.    {
  1021.       strText = "";
  1022.    }
  1023.  
  1024.    SetDlgItemText(nTimeID, strText);
  1025.    m_TimePos.RedrawWindow();
  1026. }
  1027.  
  1028. void CMMDlg::InitProgress(int nMin, int nMax)
  1029. {
  1030.    m_Progress.ClearSel(TRUE);
  1031.    m_Progress.ClearTics();
  1032.  
  1033.    if ((m_fLeadVideo != FALSE) && (m_LeadVideo.GetMMTotalFrames() > 0))
  1034.    {
  1035.       nMin = max(0, nMin);
  1036.       nMax = min(m_LeadVideo.GetMMTotalFrames(), nMax);
  1037.  
  1038.       m_Progress.SetRange(0, m_LeadVideo.GetMMTotalFrames(), TRUE);
  1039.       m_Progress.SetSelection(nMin, nMax);
  1040.       m_Progress.SetTic(nMin);
  1041.       m_Progress.SetTic(nMax);
  1042.  
  1043.       if (m_Progress.GetPos() < 0)
  1044.       {
  1045.          m_Progress.SetPos(0);
  1046.       }
  1047.       else
  1048.       if (m_Progress.GetPos() > m_LeadVideo.GetMMTotalFrames())
  1049.       {
  1050.          m_Progress.SetPos(m_LeadVideo.GetMMTotalFrames());
  1051.       }
  1052.  
  1053.       DisplayPosition(0, IDC_TIMEMIN, IDC_FRAMEMIN);
  1054.       DisplayPosition(m_LeadVideo.GetMMTotalFrames(), IDC_TIMEMAX, IDC_FRAMEMAX);
  1055.    }
  1056.    else
  1057.    {
  1058.       m_Progress.SetRange(0, 0, TRUE);
  1059.       m_Progress.SetPos(0);
  1060.       DisplayPosition(0, IDC_TIMEMIN, IDC_FRAMEMIN);
  1061.       DisplayPosition(0, IDC_TIMEMAX, IDC_FRAMEMAX);
  1062.    }
  1063. }
  1064.  
  1065. void CMMDlg::SetProgress(int nPos)
  1066. {
  1067.    if (m_fLeadVideo == FALSE)
  1068.    {
  1069.       nPos = 0;
  1070.       m_Progress.SetPos(nPos);
  1071.    }
  1072.    else
  1073.    {
  1074.       nPos = max(nPos, 0);
  1075.       nPos = min(nPos, m_LeadVideo.GetMMTotalFrames());
  1076.       m_Progress.SetPos(nPos);
  1077.       m_LeadVideo.SetMMCurrentPos(nPos);
  1078.    }
  1079.  
  1080.    DisplayPosition(nPos, IDC_TIMEPOS, IDC_FRAMEPOS);
  1081. }
  1082.  
  1083. void CMMDlg::OnMMModeChange(short iMode) 
  1084. {
  1085.    switch (iMode)
  1086.    {
  1087.    case MODE_PLAY:
  1088.    case MODE_STOP:
  1089.    case MODE_PAUSE:
  1090.    case MODE_RESUME:
  1091.       SetButtons();
  1092.       break;
  1093.    }
  1094. }
  1095.