📄 dlgtest.cpp
字号:
// DlgTest.cpp : implementation file
//
#include "stdafx.h"
#include "pgm.h"
#include "DlgTest.h"
#include "WMPControls.h"
#include "WMPSettings.h"
#include "WMPMedia.h"
#include "engine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgTest dialog
DlgTest::DlgTest(CWnd* pParent /*=NULL*/)
: CDialog(DlgTest::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgTest)
m_playtime1 = _T("");
m_timelong = _T("");
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void DlgTest::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgTest)
DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
DDX_Control(pDX, IDC_WMPlayer, m_Player);
DDX_Text(pDX, IDC_EDIT1, m_playtime1);
DDX_Text(pDX, IDC_EDIT4, m_timelong);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgTest, CDialog)
//{{AFX_MSG_MAP(DlgTest)
ON_BN_CLICKED(IDC_BUTTON7_PLAY, OnButton7Play)
ON_BN_CLICKED(IDC_BUTTON8_PAUSE, OnButton8Pause)
ON_BN_CLICKED(IDC_BUTTON9_STOP, OnButton9Stop)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1_OPEN, OnButton1Open)
ON_BN_CLICKED(IDC_BUTTON11_DELEATE, OnButton11Deleate)
ON_BN_CLICKED(IDC_BUTTON12_DELALL, OnButton12Delall)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgTest message handlers
/*
void DlgTest::OnButton1Open()
{
}
*/
void DlgTest::OnButton7Play()
{
// TODO: Add your control notification handler code here
if(pos==0)
{
m_Player.SetUrl(fileName);
}
else
{
(m_Player.GetControls()).SetCurrentPosition(pos);
(m_Player.GetControls()).play();
}
KillTimer(1);
SetTimer(0,200,NULL);
}
void DlgTest::OnButton8Pause()
{
// TODO: Add your control notification handler code here
}
void DlgTest::OnButton9Stop()
{
// TODO: Add your control notification handler code here
}
void DlgTest::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
nItem=m_ListCtrl.GetNextSelectedItem(pos);
fileName=m_ListCtrl.GetItemText(nItem,2);
pos=0;
*pResult = 0;
}
void DlgTest::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
nItem=m_ListCtrl.GetNextSelectedItem(pos);
fileName=m_ListCtrl.GetItemText(nItem,2);
m_Player.SetUrl(fileName);
SetTimer(0,70,NULL);
*pResult = 0;
}
BOOL DlgTest::OnInitDialog()
{
//m_bmp.AutoLoad(IDC_BUTTON2_PLAY,this);
CDialog::OnInitDialog();
/*
CString sPath;
sPath=_T("D:\\CUC.gif");
CDC* pDC = GetDlgItem(IDC_showPC1)->GetDC();
ShowJpgGif(pDC,sPath,0,0);
*/
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
m_ListCtrl.InsertColumn(0,"曲目");
m_ListCtrl.SetColumnWidth(0,70);
m_ListCtrl.InsertColumn(1,"类型");
m_ListCtrl.SetColumnWidth(1,70);
m_ListCtrl.InsertColumn(2,"地址");
m_ListCtrl.SetColumnWidth(2,700);
pos=0;Count=0;
//m_Slider.SetRange(0,100,FALSE);
// m_Slider.SetPos(50);
// m_cSliderPro.SetRange(0,10000);
// m_cSliderPro.SetPos(0);
m_ShowFont=new CFont;
CreateDisplayFont(m_ShowFont,18,_T("楷体_GB2321"),0);
// m_edit.SetFont(m_ShowFont,true);
check1=true;check2=true;check3=true;flag=false;
Str=0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void DlgTest::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
DlgTest dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
BEGIN_EVENTSINK_MAP(DlgTest, CDialog)
//{{AFX_EVENTSINK_MAP(DlgTest)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void DlgTest::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 0:
m_timelong=m_Player.GetCurrentMedia().GetDurationString();
m_playtime1=m_Player.GetControls().GetCurrentPositionString();
SetTimer(1,50,NULL);
UpdateData(FALSE);
break;
case 1:
//KillTimer(0);
m_playtime1=m_Player.GetControls().GetCurrentPositionString();
double pro=m_Player.GetCurrentMedia().GetDuration();
double cur_pro=m_Player.GetControls().GetCurrentPosition();
m_curTime=m_Player.GetControls().GetCurrentPositionString();
//m_cSliderPro.SetPos((int)(10000*cur_pro/pro));
UpdateData(FALSE);
/*
if(pro-cur_pro<=0.3 && pro-cur_pro>0)
{
if(flag==1)
{
OnButton2Play();
}
else
{
OnButton11Down();
}
}
if(lrc_flag==1)
{
file.Seek(Str,0);
file.ReadString(m_time);//读取一行歌词
m_min = m_time.Left(6);
m_sec = m_min.Right(5);
if (m_sec.Compare(m_curTime)==0) //当前时间一样
{
m_wordlen = m_time.GetLength();
m_word = m_time.Right(m_wordlen-10);
Str = file.GetPosition();//定位下一行
}
m_LRC=m_word;
UpdateData(FALSE);
}*/
break;
}
CDialog::OnTimer(nIDEvent);
}
BOOL DlgTest::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(0);
KillTimer(1);
delete m_ShowFont;
return CDialog::DestroyWindow();
}
void DlgTest::CreateDisplayFont(CFont *pFont, int nFontSize, LPCTSTR lpszStyle, BOOL bItalic)
{
ASSERT(pFont);
if(pFont==0)return;
pFont->CreateFont(nFontSize,0,0,0,FW_BOLD,bItalic,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH FF_SWISS,lpszStyle);
}
//DEL void DlgTest::OnBUTTON12OpenPC()
//DEL {
//DEL
//DEL // TODO: Add your control notification handler code here
//DEL char BASED_CODE szFilter[] = "图像文件 (*.JPG;*.PNG;*.GIF;)|所有文件(*.*)|*.*||";
//DEL CFileDialog dlg(TRUE,"JPG","*.JPG",OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT| OFN_ALLOWMULTISELECT,szFilter,this);
//DEL //CFileDialog dlg1(TRUE,"GIF","*.GIF",OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT| OFN_ALLOWMULTISELECT,szFilter,this);
//DEL //CFileDialog dlg2(TRUE,"PNG","*.PNG",OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT| OFN_ALLOWMULTISELECT,szFilter,this);
//DEL int ret=dlg.DoModal();
//DEL if(ret!=IDOK)
//DEL return;
//DEL CString sPath=dlg.GetPathName();
//DEL CDC* pDC = GetDlgItem(IDC_showPC1)->GetDC();
//DEL ShowJpgGif(pDC,sPath,0,0);
//DEL
//DEL }
//DEL BOOL DlgTest::ShowJpgGif(CDC *pDC, CString strPath, int x, int y)
//DEL {
//DEL
//DEL IStream *pStm;
//DEL CFileStatus fstatus;
//DEL CFile file;
//DEL LONG cb;
//DEL
//DEL //打开文件并检测文件的有效性
//DEL
//DEL if (file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&& ((cb = fstatus.m_size) != -1))
//DEL
//DEL {
//DEL HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
//DEL
//DEL LPVOID pvData = NULL;
//DEL
//DEL if (hGlobal != NULL)
//DEL
//DEL {
//DEL
//DEL pvData = GlobalLock(hGlobal);
//DEL
//DEL if (pvData != NULL)
//DEL
//DEL {
//DEL
//DEL file.ReadHuge(pvData, cb);
//DEL
//DEL GlobalUnlock(hGlobal);
//DEL
//DEL CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
//DEL
//DEL }
//DEL
//DEL }
//DEL
//DEL }
//DEL
//DEL else
//DEL
//DEL {
//DEL
//DEL return false;
//DEL
//DEL } //打开文件结束
//DEL
//DEL
//DEL
//DEL //显示JPEG和GIF格式的图片,GIF只能显示一帧,还不能显示动画,
//DEL
//DEL //要显示动画GIF请使用ACTIVE控件。
//DEL
//DEL IPicture *pPic;
//DEL
//DEL //load image from file stream
//DEL
//DEL if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
//DEL
//DEL {
//DEL
//DEL OLE_XSIZE_HIMETRIC hmWidth;
//DEL
//DEL OLE_YSIZE_HIMETRIC hmHeight;
//DEL
//DEL pPic->get_Width(&hmWidth);
//DEL
//DEL pPic->get_Height(&hmHeight);
//DEL
//DEL double fX,fY;
//DEL
//DEL //get image height and width
//DEL
//DEL fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
//DEL
//DEL fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
//DEL
//DEL //use render function display image
//DEL
//DEL if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
//DEL
//DEL {
//DEL
//DEL pPic->Release();
//DEL
//DEL return false;
//DEL
//DEL }
//DEL
//DEL pPic->Release();
//DEL
//DEL }
//DEL
//DEL else
//DEL
//DEL {
//DEL
//DEL return false;
//DEL
//DEL }
//DEL
//DEL return true;
//DEL
//DEL }
// 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 DlgTest::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR DlgTest::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//DEL void DlgTest::OnButton5Inject()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL int injectRadioButton;
//DEL
//DEL injectRadioButton=m_nButton53;
//DEL UpdateData(TRUE);
//DEL
//DEL if(m_nButton53==1)
//DEL {
//DEL Engine *ep;
//DEL double t[1];
//DEL
//DEL t[0]=6.28;
//DEL mxArray *T=NULL;
//DEL
//DEL if(!(ep=engOpen(NULL)))
//DEL {
//DEL AfxMessageBox("Can not open the matlab engine!");
//DEL exit(-1);
//DEL }
//DEL CString fname,pname;
//DEL engEvalString(ep,"[fname,pname]=uigetfile('*.wav','open the audio file')");
//DEL engEvalString(ep,"[fname,pname]=uigetfile('*.png;*.jpg;*.gif','open the watermark')");
//DEL }
//DEL UpdateData(false);
//DEL }
void DlgTest::OnButton1Open()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
char BASED_CODE szFilter[] = "媒体文件 (*.AVI;*.MPEG;*.MPG;*.RM)|*.AVI;*.MPEG;*.MPG;*.RM|所有文件(*.*)|*.*||";
CFileDialog dlg(TRUE,"WAV","*.WAV",OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT| OFN_ALLOWMULTISELECT,szFilter,this);
int ret=dlg.DoModal();
if(ret!=IDOK)
return;
fileName=dlg.GetPathName();
CString Title=dlg.GetFileTitle();
m_ListCtrl.InsertItem(Count,Title);
CString Ext=dlg.GetFileExt();
m_ListCtrl.SetItemText(Count,1,Ext);
CString PathName=dlg.GetPathName();
m_ListCtrl.SetItemText(Count,2,PathName);
Count++;
}
void DlgTest::OnButton11Deleate()
{
// TODO: Add your control notification handler code here
UINT i,uSelectedCount;
uSelectedCount=m_ListCtrl.GetSelectedCount();
for(i=0;i<uSelectedCount;i++)
{
POSITION pos=m_ListCtrl.GetFirstSelectedItemPosition();
int nItem=m_ListCtrl.GetNextSelectedItem(pos);
m_ListCtrl.DeleteItem(nItem);
}
Count-=uSelectedCount;
}
void DlgTest::OnButton12Delall()
{
// TODO: Add your control notification handler code here
m_ListCtrl.DeleteAllItems();
Count=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -