www.pudn.com > MediaPlayer.rar > MediaPlayerDLG.cpp
// MediaPlayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MediaPlayer.h"
#include "MediaPlayerDlg.h"
#include "MessageDlg.h"
#include "FrameInfoDlg.h"
#define UM_ONNEXTPRE WM_USER+10
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMediaPlayerDlg dialog
CMediaPlayerDlg::CMediaPlayerDlg(CWnd* pParent /*=NULL*/)
: CBitmapDialog(CMediaPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMediaPlayerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
filename = "";
mSliderTimer = 0;
mGrapTimer = 0;
mFilterGraph=NULL;
//CreateFilterGraph();
//******************** grap image
m_begin = 0;
m_end = 0;
m_rate = 0;
b_time = false;
b_frame = false;
num = 0;
//******************** grap image
}
CMediaPlayerDlg::~CMediaPlayerDlg()
{
DestroyFilterGraph();
CoUninitialize( );
}
void CMediaPlayerDlg::CreateFilterGraph(void)
{
DestroyFilterGraph();
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
mFilterGraph = new CDXGraph();
if (mFilterGraph->Create())
{
bool b = true;
b = b && mFilterGraph->RenderFile(filename);
b = b && mFilterGraph->SetDisplayWindow(m_VideoWindow.GetSafeHwnd());
b = b && mFilterGraph->SetNotifyWindow(this->GetSafeHwnd());
b = b && mFilterGraph->Pause();
mFilterGraph->GetDuration(&length);
int vol = 0;
vol = (-100) *(100-m_SliderAudio.GetPos());
mFilterGraph->SetAudioVolume(vol);
if(!b)
MessageBox("not support file type!", "Sorry", MB_OK|MB_ICONEXCLAMATION);
}
}
void CMediaPlayerDlg::DestroyFilterGraph(void)
{
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
if(mFilterGraph)
{
//mGraph->Release();
mFilterGraph->Stop();
mFilterGraph->SetNotifyWindow(NULL);
delete mFilterGraph;
mFilterGraph = NULL;
}
}
void CMediaPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CBitmapDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMediaPlayerDlg)
DDX_Control(pDX, IDC_PROGRESS, m_Progress);
DDX_Control(pDX, IDC_SLIDER_AUDIO, m_SliderAudio);
DDX_Control(pDX, IDC_SLIDER_GRAPH, mSlider);
DDX_Control(pDX, IDC_VIDEO_WINDOW, m_VideoWindow);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMediaPlayerDlg, CBitmapDialog)
//{{AFX_MSG_MAP(CMediaPlayerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause)
ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
ON_WM_TIMER()
ON_WM_HSCROLL()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDBLCLK()
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_BN_CLICKED(IDC_BUTTON_GRAP, OnButtonGrap)
ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
ON_BN_CLICKED(IDC_BUTTON_GRADUAL, OnButtonShotDetection)
ON_BN_CLICKED(IDC_BUTTON_ABRUPT, OnButtonKeyFrameExtraction)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BUTTON_SHOW, OnButtonShow)
ON_MESSAGE(UM_ONNEXTPRE, OnNextPre)
ON_MESSAGE(UM_ONSHOWSOURCEBITMAP,OnShowSourceBitmap)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_GRAPHNOTIFY, OnGraphNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMediaPlayerDlg message handlers
BOOL CMediaPlayerDlg::OnInitDialog()
{
CBitmapDialog::OnInitDialog();
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
LoadBitmap(PLAYBK);
SetTransColor (RGB(255,255,0));
SetTransparent (TRUE);
SetStaticTransparent (TRUE);
SetClickAnywhereMove (TRUE);
m_BtnOPEN.AutoLoad(IDC_BUTTON_OPEN,this);
m_BtnPAUSE.AutoLoad(IDC_BUTTON_PAUSE,this);
m_BtnSTOP.AutoLoad(IDC_BUTTON_STOP,this);
m_BtnPLAY.AutoLoad(IDC_BUTTON_PLAY,this);
m_BtnGRAP.AutoLoad(IDC_BUTTON_GRAP,this);
m_BtnCLOSE.AutoLoad(IDC_BUTTON_CLOSE,this);
m_BtnABRUPT.AutoLoad(IDC_BUTTON_ABRUPT,this);
m_BtnGRADUAL.AutoLoad(IDC_BUTTON_GRADUAL,this);
m_BtnSHOW.AutoLoad(IDC_BUTTON_SHOW,this);
m_ToolTip.Create(this);
m_ToolTip.Activate(TRUE);
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_OPEN),"Open file");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_PAUSE),"Pause");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_STOP),"Stop");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_PLAY),"Play");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_GRAP),"Grap Data");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_SHOW),"Show Result");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_ABRUPT),"KeyFrame Exatraction");
m_ToolTip.AddTool(GetDlgItem(IDC_BUTTON_GRADUAL),"Shot Detection");
m_VideoWindow.ModifyStyle(0, WS_CLIPCHILDREN);
mSlider.SetRange(0, 1000);
mSlider.SetPos(0);
m_SliderAudio.SetLineSize(100);
m_SliderAudio.SetPos(80);
m_SliderAudio.SetScrollRange(0,100,TRUE);
GetWindowRect(&DlgRect);
Open=FALSE;
app->Grap=FALSE;
Show=FALSE;
app->ShowR =new ResultDlg;
app->ShowR->Create(IDD_DIALOG_RESULT);
app->ShowR->ShowWindow(SW_SHOW);
MoveWindow(10,150,DlgRect.Width(),DlgRect.Height(),true);
app->hWnd=this->m_hWnd;
return TRUE; // return TRUE unless you set the focus to a control
}
void CMediaPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
{
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 CMediaPlayerDlg::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
{
CBitmapDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMediaPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMediaPlayerDlg::OnButtonOpen()
{
// TODO: Add your control notification handler code here
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
PlaySound("start.wav", AfxGetResourceHandle(),
SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
Open=TRUE;
CString strFilter = "All Files (*.*)|*.*|";
strFilter += "MPEG File (*.mpg;*.mpeg)|*.mpg;*.mpeg|";
strFilter += "Mp3 File (*.mp3)|*.mp3|";
strFilter += "Wave File (*.wav)|*.wav|";
strFilter += "wmv File (*.wmv)|*.wmv|";
CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
strFilter, this);
if (IDOK == dlgOpen.DoModal())
{
filename = dlgOpen.GetPathName();
// Rebuild the file playback filter graph
CreateFilterGraph();
if(!mFilterGraph)
{
MessageDlg m;
m.SendMessage("can't open file!");
m.DoModal();
return;
}
num_frame=1;
time=0.0;
mFilterGraph->GetBitmapSize(&bitmapSize);
mFilterGraph->GetFrameInfo(&Width,&Height);
N=(int)(length*10)+1;
loop=0;
ImgData = new unsigned char[Width * Height * 3];
memset(ImgData, 0 , 3*Width*Height*sizeof(unsigned char));
TepImg = new float[3 * N * Width * Height];
memset(TepImg , 0 , 3 * N * Width * Height * sizeof(float));
//ImgData = new unsigned char[Width * Height * 3 / 4];优化的算法
//memset(ImgData, 0 , 3*Width*Height/4*sizeof(unsigned char));
//TepImg = new float[3 * Width * Height / 4];
Hist_hsv = new int[N*72] ; //突变直方图
memset(Hist_hsv , 0 , N * 72 * sizeof(int));
/* Hist_hsv1 = new int[N*200];
memset(Hist_hsv1, 0, N*200*sizeof(int));*/
result = new int[N] ;
memset(result, 0, N * sizeof(int));
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
app->KeyFrame_num = 0 ;
app->KeyFrame_time=new double[N];
memset(app->KeyFrame_time, 0, N * sizeof(double));
app->ShotFrame_num = 0 ;
app->ShotFrame_time=new double[N];
memset(app->ShotFrame_time, 0, N * sizeof(double));
m_Progress.SetRange(0,N-1);
m_Progress.SetPos(0);
m_Progress.SetStep(1);
m_Progress.RoolBack(TRUE);
}
}
// Deal with the graph events
LRESULT CMediaPlayerDlg::OnGraphNotify(WPARAM inWParam, LPARAM inLParam)
{
IMediaEventEx * pEvent = NULL;
if (mFilterGraph && (pEvent = mFilterGraph->GetEventHandle()))
{
LONG eventCode = 0, eventParam1 = 0, eventParam2 = 0;
while (SUCCEEDED(pEvent->GetEvent(&eventCode, &eventParam1, &eventParam2, 0)))
{
// Spin through the events
pEvent->FreeEventParams(eventCode, eventParam1, eventParam2);
switch (eventCode)
{
case EC_COMPLETE:
OnButtonPause();
mFilterGraph->SetCurrentPosition(0);
mSliderTimer=0;
break;
case EC_USERABORT:
case EC_ERRORABORT:
//OnButtonStop();
break;
default:
break;
}
}
}
return 0;
}
void CMediaPlayerDlg::RestoreFromFullScreen(void)
{
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
if (mFilterGraph)
{
if (mFilterGraph->GetFullScreen())
{
mFilterGraph->SetFullScreen(FALSE);
}
}
}
void CMediaPlayerDlg::OnButtonPause()
{
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
// TODO: Add your control notification handler code here
PlaySound("start.wav", AfxGetResourceHandle(),
SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
if(mFilterGraph)
{
if(!mFilterGraph->IsPaused())
{
mFilterGraph->Pause();
}
else
{
mFilterGraph->Run();
}
}
}
void CMediaPlayerDlg::OnButtonPlay()
{
// TODO: Add your control notification handler code here
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
PlaySound("start.wav", AfxGetResourceHandle(),
SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
if(mFilterGraph)
{
CRect rect;
CWnd *hStatic = this-> GetDlgItem(IDC_VIDEO_WINDOW);
hStatic->GetClientRect(rect);
mFilterGraph->SetVideoSize(rect.Width(),rect.Height());
if(mSliderTimer == 0)
{
mSliderTimer = SetTimer(0, 500, NULL);
mFilterGraph->Run();
}
}
}
void CMediaPlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
double currentPos = 0.0;
double duration = 1.0;
int curPos = 0;
//char buf[10];
if(nIDEvent==0)
{
mFilterGraph->GetCurrentPosition(¤tPos);
mFilterGraph->GetDuration(&duration);
curPos = (int)(currentPos*1000/duration);
if(curPos != mSlider.GetPos())
{
mSlider.SetPos(curPos);
// CString str ="进度:";
// _itoa((int)(curPos*100/1000), buf, 10);
// str += buf;
// str += "%,";
// double length = 0;
// CString strTemp = "";
// mFilterGraph->GetCurrentPosition(&length);
// mFilterGraph->IndicateTime((int)length, &strTemp);
// str += strTemp;
// str += "/";
// mFilterGraph->GetDuration(&length);
// mFilterGraph->IndicateTime((int)length, &strTemp);
// str += strTemp;
// m_Progress.SetWindowText(str);
}
}
///////////////////////////////////////////////////
else if(nIDEvent==2)
{
if(loopSetCurrentPosition(time);
////////////////////////////////////////////////
/*char FilePath[20]={""};
char Temp[10];
_itoa(num_frame,Temp,10);
strcat(FilePath,"C:\\liudehua/out");
strcat(FilePath,Temp);
strcat(FilePath,".bmp");
mFilterGraph->SnapshotBitmap(FilePath);
num_frame++;*/
///////////////////////////////////////////////////
// start=clock();
mFilterGraph->GetCurrentImageData(ImgData);
// end=clock();
// double k=mFilterGraph->GetCurrentImageInfo(ImgData);
bmpInstance.Rgb2Hsv(ImgData, Width , Height , TepImg , loop);
bmpInstance.Hist_hsv(TepImg , Hist_hsv , loop , Width , Height);
//////////////////////////////////////////////////////////////////////////
// double k= (double)(end-start)/CLOCKS_PER_SEC;
// char t[20];
// char Mes[100]={"Grap Finish!GrapTime is "};
// _gcvt(k,4,t);
// strcat(Mes,t);
// strcat(Mes," s");
// MessageDlg m;
// m.SendMessage(Mes);
// KillTimer(2);
// m.DoModal();
//////////////////////////////////////////////////////////////////////////
//优化算法
//bmpInstance.Rgb2Hsv(ImgData, Width , Height , TepImg);
//bmpInstance.Hist_hsv(TepImg , Hist_hsv , loop , Width , Height);
char str[10] ={""};
double percent=1.0*loop/N*100;
_gcvt(percent,2,str);
strcat(str,"%");
// CRect rect;
// GetDlgItem(IDC_PROGRESS)->GetWindowRect(&rect);
// ScreenToClient(&rect);
// InvalidateRect(&rect);
time=time+DELTA;//add
loop++;
m_Progress.StepIt();
m_Progress.SetWindowText(str);
}
else
{
mFilterGraph->SetCurrentPosition(0);
m_Progress.RoolBack(FALSE);
KillTimer(2);
end = clock();
Grap_Time = (double)(end-start)/CLOCKS_PER_SEC;
char t[20];
char Mes[100]={"Grap Finish!GrapTime is "};
_gcvt(Grap_Time,4,t);
strcat(Mes,t);
strcat(Mes," s");
// delete [] TepImg ;
// TepImg = NULL ;
delete []ImgData ;
ImgData = NULL ;
bmpInstance.FrameExaction(TepImg , Hist_hsv , result , 0 , N - 1 , Width , Height) ;
for( int i = 0 ; i < N ; i++ )
{
if((result[i] == 1)&&(result[i + 1] != 1))
{
/* char FilePath[20]={""};
char Temp[10];
_itoa(i,Temp,10);
strcat(FilePath,"C:\\bmp/out");
strcat(FilePath,Temp);
strcat(FilePath,".bmp");
mFilterGraph->SnapshotBitmap(FilePath);*/
///////////////////////////////
app->ShotFrame_time[app->ShotFrame_num] = 1.0 * (i + 1) * DELTA ;
// mFilterGraph->SetCurrentPosition(app->KeyFrame_time[app->KeyFrame_num]);
app->ShotFrame_num++;
}
else if ((result[i] == 1)&&(result[i + 1] == 1))
{
do
{
i ++ ;
} while(result[i] == 1);
app->ShotFrame_time[app->ShotFrame_num] = 1.0 * (i + 1) * DELTA ;
// mFilterGraph->SetCurrentPosition(app->KeyFrame_time[app->KeyFrame_num]);
app->ShotFrame_num++;
}
}
for( i = 0 ; i < N ; i++ )
{
if(result[i] == 10)
{
app->KeyFrame_time[app->KeyFrame_num] = 1.0 * (i + 1) * DELTA ;
app->KeyFrame_num++;
}
}
delete []result;
result = NULL;
delete []TepImg;
TepImg = NULL;
delete []Hist_hsv;
Hist_hsv = NULL;
app->ShotFrame_num--;
app->KeyFrame_num--;
app->Grap=TRUE;
MessageDlg m;
m.SendMessage(Mes);
m.DoModal();
}
}
/*
else if (mFilterGraph && nIDEvent==mGrapTimer)
{
if(b_time)
{
int currentTime = 0;
mFilterGraph->GetCurrentPosition(¤tPos);
//ms as the unit
currentTime = (int)currentPos * 1000;
if((currentTime<=m_end) && (currentTime>=m_begin))
{
char filename[30];
sprintf(filename, "d:\\time%d.bmp", currentTime/m_rate);
//save image data need too much 'io' operation, or it will be effective
mFilterGraph->SnapshotBitmap(filename);
}
}
else if(b_frame)
{
int currentFrame = 0;
mFilterGraph->GetCurrentFrame(¤tFrame);
if((currentFrame<=m_end) && (currentFrame>=m_begin))
{
char filename[30];
sprintf(filename, "F:\\vc_programm\\DirectShow\\MediaPlayer\\image\\time%d.bmp", (currentFrame-m_begin)/m_rate);
//save image data need too much 'io' operation, or it will be effective
mFilterGraph->SnapshotBitmap(filename);
}
}
}*/
CDialog::OnTimer(nIDEvent);
}
BOOL CMediaPlayerDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if (mSliderTimer)
{
KillTimer(0);
mSliderTimer = 0;
}
if(mGrapTimer)
{
KillTimer(mGrapTimer);
mGrapTimer = 0;
}
KillTimer(2);
return CDialog::DestroyWindow();
}
BOOL CMediaPlayerDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
m_VideoWindow.GetWindowRect(&rc);
ScreenToClient(&rc);
pDC->ExcludeClipRect(&rc);
return CBitmapDialog::OnEraseBkgnd(pDC);
}
void CMediaPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
if (mSlider.GetSafeHwnd() == pScrollBar->GetSafeHwnd())
{
if(mFilterGraph)
{
double duration = 1.0;
mFilterGraph->GetDuration(&duration);
double pos = duration * mSlider.GetPos() / 1000.;
mFilterGraph->SetCurrentPosition(pos);
}
}
else if (m_SliderAudio.GetSafeHwnd() == pScrollBar->GetSafeHwnd())
{
if(mFilterGraph)
{
int vol = 0;
vol = (-100) *(100-m_SliderAudio.GetPos());
mFilterGraph->SetAudioVolume(vol);
}
}
else
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
BOOL CMediaPlayerDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
{
// Restore form fullscreen mode
RestoreFromFullScreen();
return 1;
}
}
m_ToolTip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void CMediaPlayerDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
mFilterGraph->SetFullScreen(TRUE);
CDialog::OnLButtonDblClk(nFlags, point);
}
void CMediaPlayerDlg::OnButtonStop()
{
// TODO: Add your control notification handler code here
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
PlaySound("start.wav", AfxGetResourceHandle(),
SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
if(mFilterGraph)
{
mFilterGraph->SetCurrentPosition(0);
mFilterGraph->Stop();
mSliderTimer =0;
}
// mFilterGraph->SetCurrentPosition(0.7);
// mFilterGraph->SnapshotBitmap("C:\\7.bmp");
// mFilterGraph->SetCurrentPosition(28.7);
// mFilterGraph->SnapshotBitmap("C:\\28.bmp");
}
void CMediaPlayerDlg::OnButtonGrap()
{
// TODO: Add your control notification handler code here
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
PlaySound("start.wav", AfxGetResourceHandle(),
SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
if(Open)
{
Open=FALSE;
if(!mFilterGraph->IsRunning())
{
KillTimer(0);
time=0;
mFilterGraph->SetVideoSize(0,0);
//loop=N-10;//////////////////////////////////////////////////////////////////////////
SetTimer (2,100,NULL);
start = clock();
}
else
{
MessageDlg m;
m.SendMessage("Sorry! The Video is Running! Please Stop it!");
m.DoModal();
}
}
else
{
MessageDlg m;
m.SendMessage("Error! Please Open file First!");
m.DoModal();
}
}
void CMediaPlayerDlg::OnButtonClose()
{
// TODO: Add your control notification handler code here
OnCancel();
}
void CMediaPlayerDlg::OnButtonShotDetection()
{
// TODO: Add your control notification handler code here
PlaySound("start.wav", AfxGetResourceHandle(),SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
if(app->Grap)
{
app->ShowKeyFrame=FALSE;
if(app->ShotFrame_num>=0)
{
app->Page=app->ShotFrame_num/9+1;
app->rest=app->ShotFrame_num%9;
app->curPage=0;
if(app->Page>1)
{
for (app->curFrame=0;app->curFrame<9;app->curFrame++)
{
ShowResult(app->ShotFrame_time[app->curFrame+app->curPage*9]);
}
}
else if(app->Page==1)
{
for (app->curFrame=0;app->curFrame<=app->rest;app->curFrame++)
{
ShowResult(app->ShotFrame_time[app->curFrame+app->curPage*9]);
FillResult(app->rest+1,8);
}
}
}
}
else
{
MessageDlg m;
m.SendMessage("Error! Grap Data First! ");
m.DoModal();
}
}
void CMediaPlayerDlg::OnButtonKeyFrameExtraction()
{
// TODO: Add your control notification handler code here
PlaySound("start.wav", AfxGetResourceHandle(),SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
///////////////////////////////////ShowResult Page0 call ShowResult();
if (app->Grap)
{
app->ShowKeyFrame=TRUE;
if(app->KeyFrame_num>=0)
{
app->Page=app->KeyFrame_num/9+1;
app->rest=app->KeyFrame_num%9;
app->curPage=0;
if(app->Page>1)
{
for (app->curFrame=0;app->curFrame<9;app->curFrame++)
{
ShowResult(app->KeyFrame_time[app->curFrame+app->curPage*9]);
}
}
else if(app->Page==1)
{
for (app->curFrame=0;app->curFrame<=app->rest;app->curFrame++)
{
ShowResult(app->KeyFrame_time[app->curFrame+app->curPage*9]);
FillResult(app->rest+1,8);
}
}
}
}
else
{
MessageDlg m;
m.SendMessage("Error! Grap Data First! ");
m.DoModal();
}
}
HBRUSH CMediaPlayerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(GetDlgItem(IDC_PROGRESS) == pWnd)
{ switch (nCtlColor)
{
case CTLCOLOR_STATIC: //静态文本
{
pDC->SetBkMode(TRANSPARENT);
HBRUSH B = CreateSolidBrush(RGB(69,69,69)); //控件背景颜色
pDC->SetTextColor(RGB(255,255,255)); //控件中的文字的颜色
return (HBRUSH) B;
}
return hbr;
}
}
return hbr;
}
void CMediaPlayerDlg::OnButtonShow()
{
// TODO: Add your control notification handler code here
PlaySound("hide.wav", AfxGetResourceHandle(),
SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
GetWindowRect(&DlgRect);
if(!Show)
{
app->ShowR->MoveWindow(DlgRect.right-70,10,app->ShowR->DlgRect.Width(),app->ShowR->DlgRect.Height(),true);
Show=TRUE;
if(!app->Grap)
{
FillResult(0,8);
}
else
{
SendMessage(UM_ONNEXTPRE,NULL,NULL);
}
}
else
{
app->ShowR->MoveWindow(DlgRect.right,DlgRect.top,0,app->ShowR->DlgRect.Height(),true);
Show=FALSE;
}
}
void CMediaPlayerDlg::ShowResult(double curTime)
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
mFilterGraph->SetCurrentPosition(curTime);
CRect rect;
// CDC *pDC=new CDC;
// CClientDC dc(&app->ShowR->m_Result0);
switch(app->curFrame)
{
case 0:
{
cs=&app->ShowR->m_Result0;
break;
}
case 1:
{
cs=&app->ShowR->m_Result1;
break;
}
case 2:
{
cs=&app->ShowR->m_Result2;
break;
}
case 3:
{
cs=&app->ShowR->m_Result3;
break;
}
case 4:
{
cs=&app->ShowR->m_Result4;
break;
}
case 5:
{
cs=&app->ShowR->m_Result5;
break;
}
case 6:
{
cs=&app->ShowR->m_Result6;
break;
}
case 7:
{
cs=&app->ShowR->m_Result7;
break;
}
case 8:
{
cs=&app->ShowR->m_Result8;
break;
}
}
HWND hPicture = cs->GetSafeHwnd();
cs->GetClientRect(&rect);
CClientDC dc(cs);
HDC hdcDest = ::GetDC(hPicture);
unsigned char *buffer=new unsigned char[bitmapSize];
memset(buffer, 0 , bitmapSize*sizeof(unsigned char));
mFilterGraph->GetBitmapBuffer(bitmapSize,buffer);
BITMAPINFOHEADER *bmih= (BITMAPINFOHEADER*)buffer;
unsigned char *Data=new unsigned char[Width * Height * 3];
memset(Data, 0 , 3*Width*Height*sizeof(unsigned char));
mFilterGraph->GetBitmapInfo(buffer,bmih,Data);
bmih->biBitCount=24;
bmih->biSizeImage=bmih->biHeight*bmih->biWidth*3;
BITMAPINFO bmi;
ZeroMemory(&bmi, sizeof(BITMAPINFO));
CopyMemory(&(bmi.bmiHeader), bmih, sizeof(BITMAPINFOHEADER));
// HBITMAP hBitmap = CreateDIBitmap(hdcDest, bmih, CBM_INIT, Data, &bmi, DIB_RGB_COLORS);
//
// BITMAP bm;
// CBitmap bitmap;
// ::GetObject(hBitmap,sizeof(BITMAP),&bm);
// bitmap.Attach(hBitmap);
// bitmap.GetObject(sizeof(BITMAP),&bm);
//
//
// pDC->CreateCompatibleDC(&dc);
// pDC->SelectObject(bitmap);
SetStretchBltMode(hdcDest,COLORONCOLOR);
StretchDIBits(hdcDest,0,0,rect.Width(),rect.Height(), 0,0,Width,Height,Data,(LPBITMAPINFO)&bmi,DIB_RGB_COLORS,SRCCOPY);
//dc.StretchBlt(0,0,rect.Width(),rect.Height(),pDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
///////////////////////////////////////////////////////
// DeleteObject(hBitmap);
::ReleaseDC(hPicture, hdcDest);
// pDC->DeleteDC();
delete []buffer;
buffer=NULL;
delete []Data;
Data=NULL;
}
void CMediaPlayerDlg::GetFilter(CDXGraph *Filter)
{
Filter=mFilterGraph;
}
void CMediaPlayerDlg::OnNextPre()
{
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
if(app->Grap)
{
if (app->ShowKeyFrame)
{
if(app->curPagePage-1)
{
for (app->curFrame=0;app->curFrame<9;app->curFrame++)
{
ShowResult(app->KeyFrame_time[app->curFrame+app->curPage*9]);
}
}
else if(app->curPage==app->Page-1)
{
for (app->curFrame=0;app->curFrame<=app->rest;app->curFrame++)
{
ShowResult(app->KeyFrame_time[app->curFrame+app->curPage*9]);
FillResult(app->rest+1,8);
}
}
}
else if (!app->ShowKeyFrame)
{
if(app->curPagePage-1)
{
for (app->curFrame=0;app->curFrame<9;app->curFrame++)
{
ShowResult(app->ShotFrame_time[app->curFrame+app->curPage*9]);
}
}
else if(app->curPage==app->Page-1)
{
for (app->curFrame=0;app->curFrame<=app->rest;app->curFrame++)
{
ShowResult(app->ShotFrame_time[app->curFrame+app->curPage*9]);
FillResult(app->rest+1,8);
}
}
}
}
else
{
FillResult(0,8);
}
}
void CMediaPlayerDlg::FillResult(int start, int end)
{
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
CRect rect;
for(int i=start;i<=end;i++)
{
if(i==0)
{
cs=&app->ShowR->m_Result0;
}
if(i==1)
{
cs=&app->ShowR->m_Result1;
}
if(i==2)
{
cs=&app->ShowR->m_Result2;
}
if(i==3)
{
cs=&app->ShowR->m_Result3;
}
if(i==4)
{
cs=&app->ShowR->m_Result4;
}
if(i==5)
{
cs=&app->ShowR->m_Result5;
}
if(i==6)
{
cs=&app->ShowR->m_Result6;
}
if(i==7)
{
cs=&app->ShowR->m_Result7;
}
if(i==8)
{
cs=&app->ShowR->m_Result8;
}
cs->GetClientRect(&rect);
CClientDC dc(cs);
CBitmap bitmap;
bitmap.LoadBitmap(BACKBG);
BITMAP bm;
// ::GetObject(hBitmap,sizeof(BITMAP),&bm);
//bitmap.Attach(hBitmap);
//bitmap.GetObject(sizeof(BITMAP),&bm);
CDC *pDC=new CDC;
::GetObject((HBITMAP)bitmap,sizeof(BITMAP),&bm);
pDC->CreateCompatibleDC(&dc);
pDC->SelectObject(bitmap);
dc.SetStretchBltMode(COLORONCOLOR);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),pDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
bitmap.DeleteObject();
pDC->DeleteDC();
}
}
//////////////////////////////////////////////////////////////////////
void CMediaPlayerDlg::OnShowSourceBitmap()
{
CMediaPlayerApp *app = (CMediaPlayerApp *)AfxGetApp();
mFilterGraph->SetCurrentPosition(app->curTime);
HWND hPicture =app->cs->GetSafeHwnd();
HDC hdcDest = ::GetDC(hPicture);
long bitmapSize;
mFilterGraph->GetBitmapSize(&bitmapSize);
unsigned char *buffer=new unsigned char[bitmapSize];
memset(buffer, 0 , bitmapSize*sizeof(unsigned char));
mFilterGraph->GetBitmapBuffer(bitmapSize,buffer);
BITMAPINFOHEADER *bmih= (BITMAPINFOHEADER*)buffer;
unsigned char *Data=new unsigned char[Width * Height * 3];
memset(Data, 0 , 3*Width*Height*sizeof(unsigned char));
mFilterGraph->GetBitmapInfo(buffer,bmih,Data);
bmih->biBitCount=24;
bmih->biSizeImage=bmih->biHeight*bmih->biWidth*3;
BITMAPINFO bmi;
ZeroMemory(&bmi, sizeof(BITMAPINFO));
CopyMemory(&(bmi.bmiHeader), bmih, sizeof(BITMAPINFOHEADER));
HBITMAP hBitmap = CreateDIBitmap(hdcDest, bmih, CBM_INIT, Data, &bmi, DIB_RGB_COLORS);
app->cs->SetBitmap(hBitmap);
// BITMAP bm;
// CBitmap bitmap;
// ::GetObject(hBitmap,sizeof(BITMAP),&bm);
// bitmap.Attach(hBitmap);
// bitmap.GetObject(sizeof(BITMAP),&bm);
// pDC->CreateCompatibleDC(&dc);
// pDC->SelectObject(bitmap);
// dc.StretchBlt(0,0,rect.Width(),rect.Height(),pDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
///////////////////////////////////////////////////////
// bitmap.DeleteObject();
DeleteObject(hBitmap);
::ReleaseDC(hPicture, hdcDest);
// pDC->DeleteDC();
delete []buffer;
buffer=NULL;
delete []Data;
Data=NULL;
}