00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "DlgVidSeek.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CDlgVidSeek::CDlgVidSeek(CWnd* pParent )
00017 : CDialog(CDlgVidSeek::IDD, pParent)
00018 {
00019 m_hWndDuration = NULL;
00020 m_seek = NULL;
00021 }
00022
00023 void CDlgVidSeek::DoDataExchange(CDataExchange* pDX)
00024 {
00025 CDialog::DoDataExchange(pDX);
00026
00027 DDX_Control(pDX, IDC_SEEK, m_wndSeek);
00028
00029 }
00030
00031 BEGIN_MESSAGE_MAP(CDlgVidSeek, CDialog)
00032
00033 ON_WM_CTLCOLOR()
00034 ON_WM_SIZE()
00035 ON_WM_TIMER()
00036 ON_WM_HSCROLL()
00037
00038 END_MESSAGE_MAP()
00039
00040 HBRUSH CDlgVidSeek::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00041 {
00042 HBRUSH hbr = m_brClrWindow;
00043 pDC->SetBkMode (TRANSPARENT);
00044 return hbr;
00045 }
00046
00047 void CDlgVidSeek::OnSize(UINT nType, int cx, int cy)
00048 {
00049 CDialog::OnSize(nType, cx, cy);
00050 if (cx && cy && IsWindow (m_wndSeek))
00051 m_wndSeek.MoveWindow (0, 0, cx, cy);
00052 }
00053
00054 BOOL CDlgVidSeek::OnInitDialog()
00055 {
00056 CDialog::OnInitDialog();
00057
00058 m_brClrWindow.CreateSolidBrush (GetSysColor (COLOR_WINDOW));
00059
00060 m_seek = NULL;
00061 m_wndSeek.EnableWindow (FALSE);
00062
00063 return TRUE;
00064 }
00065
00066 void CDlgVidSeek::OnTimer(UINT nIDEvent)
00067 {
00068 LONGLONG cur, stop;
00069
00070 if (m_seek == NULL)
00071 return;
00072
00073 if (m_hWndDuration)
00074 ::SetWindowText (m_hWndDuration, GetDuration ());
00075
00076 m_seek->GetPositions (&cur, &stop);
00077
00078 double pos = (double) cur / m_llDuration;
00079 if (m_llDuration > 1000)
00080 pos *= 1000.0;
00081 else
00082 pos *= m_llDuration;
00083
00084 m_wndSeek.SetPos (int (pos));
00085
00086 CDialog::OnTimer(nIDEvent);
00087 }
00088
00089 void CDlgVidSeek::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00090 {
00091 static BOOL bStartScroll = TRUE;
00092
00093 if (bStartScroll)
00094 {
00095 bStartScroll = FALSE;
00096 KillTimer (1);
00097 }
00098
00099 if (nSBCode == SB_ENDSCROLL)
00100 {
00101 double pos = m_wndSeek.GetPos ();
00102 if (m_llDuration < 1000)
00103 pos /= m_llDuration;
00104 else
00105 pos /= 1000.0;
00106
00107 LONGLONG cur, stop;
00108 m_seek->GetPositions (&cur, &stop);
00109
00110 cur = (LONGLONG) (m_llDuration * pos);
00111
00112 m_seek->SetPositions (&cur, AM_SEEKING_AbsolutePositioning,
00113 &stop, AM_SEEKING_AbsolutePositioning);
00114
00115 SetTimer (1, 1000, NULL);
00116 bStartScroll = TRUE;
00117 }
00118
00119 CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
00120 }
00121
00122 void CDlgVidSeek::Set_MediaSeeking(IMediaSeeking *seek)
00123 {
00124 if (m_seek)
00125 {
00126 KillTimer (1);
00127 m_wndSeek.SetPos (0);
00128 m_seek->Release ();
00129 }
00130
00131 m_seek = seek;
00132
00133 if (m_seek)
00134 {
00135 if (FAILED (seek->GetDuration (&m_llDuration)))
00136 m_seek = NULL;
00137 else
00138 {
00139 m_wndSeek.SetRange (0, m_llDuration > 1000 ? 1000 : (int)m_llDuration);
00140 SetTimer (1, 1000, NULL);
00141 m_seek->AddRef ();
00142 }
00143 }
00144
00145 m_wndSeek.EnableWindow (m_seek != NULL);
00146 }
00147
00148 CString CDlgVidSeek::GetDuration()
00149 {
00150 if (m_seek == NULL)
00151 return "00:00/00:00";
00152
00153 LONGLONG cur, stop;
00154
00155 m_seek->GetPositions (&cur, &stop);
00156
00157
00158 ULONG nTotalMS = (ULONG) (cur / 10000);
00159 int nSeconds = nTotalMS / 1000;
00160
00161 nSeconds %= 60;
00162
00163 CString str1, str2;
00164 BOOL bH = FALSE;
00165
00166 str2 = DurationToString (m_llDuration, &bH);
00167 str1 = DurationToString (cur, &bH);
00168
00169 CString strDuration;
00170 strDuration.Format ("%s/%s", str1, str2);
00171
00172 return strDuration;
00173 }
00174
00175 CString CDlgVidSeek::DurationToString(LONGLONG llDur, BOOL* pbNeedHours)
00176 {
00177
00178 ULONG nTotalMS = (ULONG) (llDur / 10000);
00179 int nSeconds = nTotalMS / 1000;
00180 int nMinutes = nSeconds / 60;
00181 int nHours = nMinutes / 60;
00182 nSeconds %= 60;
00183 nMinutes %= 60;
00184
00185 CString strDur;
00186
00187 BOOL bH = pbNeedHours ? *pbNeedHours : FALSE;
00188
00189 if (nHours == 0 && bH == FALSE)
00190 strDur.Format ("%02d:%02d", nMinutes, nSeconds);
00191 else
00192 {
00193 strDur.Format ("%02d:%02d:%02d", nHours, nMinutes, nSeconds);
00194 bH = TRUE;
00195 }
00196
00197 if (pbNeedHours)
00198 *pbNeedHours = bH;
00199
00200 return strDur;
00201 }
00202