// 模拟2Dlg.cpp : implementation file // #include "stdafx.h" #include "模拟2.h" #include "模拟2Dlg.h" #include #pragma comment(lib,"winmm.lib") #include "Digitalv.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CMy2Dlg dialog CMy2Dlg::CMy2Dlg(CWnd* pParent /*=NULL*/) : CDialog(CMy2Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CMy2Dlg) // m_vol = 0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy2Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMy2Dlg) DDX_Control(pDX, IDC_LISTMUSIC, m_list); DDX_Control(pDX, IDC_SLIDERTIME, m_sliderTime); DDX_Control(pDX, IDC_SLIDERVOL, m_sliderVol); // DDX_Text(pDX, IDC_EDIT_VOL, m_vol); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMy2Dlg, CDialog) //{{AFX_MSG_MAP(CMy2Dlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_ZK, OnZk) ON_BN_CLICKED(IDC_OPEN, OnOpen) ON_BN_CLICKED(IDC_ADD, OnAdd) ON_BN_CLICKED(IDC_PLAY, OnPlay) ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDERVOL, OnCustomdrawSlidervol) ON_LBN_SELCHANGE(IDC_LISTMUSIC, OnSelchangeListmusic) ON_BN_CLICKED(IDC_PREVIOUS, OnPrevious) ON_BN_CLICKED(IDC_LATE, OnLate) ON_BN_CLICKED(IDC_DELETE, OnDelete) ON_WM_TIMER() ON_BN_CLICKED(IDC_XUNHUAN, OnXunhuan) ON_WM_CTLCOLOR() ON_MESSAGE(WM_SHOWTASK,onShowTask) ON_BN_CLICKED(IDC_SMALLEST, OnSmallest) ON_BN_CLICKED(IDC_ABOUT, OnAbout) //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CMy2Dlg message handlers BOOL CMy2Dlg::OnInitDialog() { second=0; minute=0; hour=0; CDialog::OnInitDialog(); LoadImage("res//3.jpg"); // 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 initializ qation here m_hbrush=CreateSolidBrush(RGB(0,0,255)); 打开播放列表 CStdioFile *fsp=new CStdioFile(".\\list.txt",CFile::modeRead); CString str; while(fsp->ReadString(str)){ m_list.AddString(str); } fsp->Close(); delete fsp; //m_list.SetCurSel(0); SetDlgItemText(IDC_EDIT_MUSIC,"csy音乐播放器"); m_sliderVol.SetRange(0,2000); m_sliderVol.SetPos(1000); SetWindowPos(NULL,0,0,275,190,SWP_NOMOVE); // // return TRUE; // return TRUE unless you set the focus to a control } void CMy2Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { 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 CMy2Dlg::OnPaint() { CPaintDC dc(this); pIPicture->Render(dc.m_hDC,0,0,620,430,0,hmHeight,hmWidth,-hmHeight,NULL); if (IsIconic()) { // CPaintDC dc(this); // device context for painting CPaintDC dc(this); pIPicture->Render(dc.m_hDC,0,0,620,430,0,hmHeight,hmWidth,-hmHeight,NULL); 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 CMy2Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMy2Dlg::LoadImage(LPCTSTR szImagePath) { HANDLE hFile=CreateFile(szImagePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); //从指定的路径szImagePath中读取文件句柄 DWORD dwFileSize=GetFileSize(hFile, NULL); //获得图片文件的大小,用来分配全局内存 HGLOBAL hImageMemory=GlobalAlloc(GMEM_MOVEABLE, dwFileSize); //给图片分配全局内存 void *pImageMemory=GlobalLock(hImageMemory); //锁定内存 DWORD dwReadedSize; //保存实际读取的文件大小 ReadFile(hFile, pImageMemory, dwFileSize, &dwReadedSize, NULL); //读取图片到全局内存当中 GlobalUnlock(hImageMemory); //解锁内存 CloseHandle(hFile); //关闭文件句柄 IStream *pIStream;//创建一个IStream接口指针,用来保存图片流 //创建一个IPicture接口指针,表示图片对象 CreateStreamOnHGlobal(hImageMemory, false, &pIStream);//用全局内存初使化IStream接口指针 OleLoadPicture(pIStream, 0, false, IID_IPicture, (LPVOID*)&(pIPicture));//用OleLoadPicture获得IPicture接口指针 //得到IPicture COM接口对象后,你就可以进行获得图片信息、显示图片等操作 pIPicture->get_Width(&hmWidth); //用接口方法获得图片的宽和高 pIPicture->get_Height(&hmHeight); } void CMy2Dlg::OnZk() { // TODO: Add your control notification handler code here flag_1=!flag_1; if(!flag_1) SetWindowPos(NULL,0,0,275,350,SWP_NOMOVE); else SetWindowPos(NULL,0,0,275,190,SWP_NOMOVE); } void CMy2Dlg::OnOpen() { // TODO: Add your control notification handler code here flag_2=!flag_2; if(!flag_2) SetWindowPos(NULL,0,0,480,350,SWP_NOMOVE); else SetWindowPos(NULL,0,0,275,190,SWP_NOMOVE); } void CMy2Dlg::SetVol(DWORD vol) { MCI_DGV_SETAUDIO_PARMS setvolume; setvolume.dwCallback=NULL; setvolume.dwItem=MCI_DGV_SETAUDIO_VOLUME; setvolume.dwValue=vol; mciSendCommand(m_count,MCI_SETAUDIO,MCI_DGV_SETAUDIO_ITEM|MCI_DGV_SETAUDIO_VALUE,(DWORD)(LPVOID)&setvolume); // return 0; } void CMy2Dlg::OnAdd() { // TODO: Add your control notification handler code here char szFileFilter[]="mp3文件(*.mp3)|*.mp3|"; "wma文件(*.wma)|*.wma|" "wav文件(*.wav)|*.wav|"; CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR,szFileFilter); POSITION pos=dlg.GetStartPosition(); if(dlg.DoModal()==IDOK){ CString strFileName=dlg.GetFileName(); while(pos!=NULL){ m_pathname=dlg.GetNextPathName(pos); m_list.AddString(m_pathname); } } Save(); } void CMy2Dlg::OnPlay() { // TODO: Add your control notification handler code here flag_4=!flag_4; if(flag_4){ Resume(); SetDlgItemText(IDC_PLAY,"暂停"); } if(!flag_4){ Wait(); SetDlgItemText(IDC_PLAY,"开始"); } } DWORD CMy2Dlg::getinfo(DWORD item) { MCI_STATUS_PARMS mcistatusparms; mcistatusparms.dwItem=item; mciSendCommand(m_count,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mcistatusparms); return mcistatusparms.dwReturn; } void CMy2Dlg::OnCustomdrawSlidervol(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here CClientDC dc(this); dc.SetTextColor(RGB(255,0,0)); CString volstr; volstr.Format("%02d",m_sliderVol.GetPos()/20); dc.TextOut(220,95,volstr); UpdateData(true); // m_vol=m_sliderVol.GetPos()/20; SetVol(m_sliderVol.GetPos()); UpdateData(false); *pResult = 0; } void CMy2Dlg::Save() { CStdioFile file; file.Open(".\\list.txt",CFile::modeCreate|CFile::modeReadWrite|CFile::typeText); for(int i=0;iSetBkMode(TRANSPARENT); pDC->SetBkColor(RGB(0,0,255)); return m_hbrush; } else return CDialog::OnCtlColor(pDC,pWnd,nCtlColor); // TODO: Return a different brush if the default is not desired return hbr; } void CMy2Dlg::onTray() { NOTIFYICONDATA nid; nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA); nid.hWnd=this->m_hWnd; nid.uID=IDR_MAINFRAME; nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP; nid.uCallbackMessage=WM_SHOWTASK; nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME)); strcpy(nid.szTip,"剑在手"); Shell_NotifyIcon(NIM_ADD,&nid); ShowWindow(SW_HIDE); } LRESULT CMy2Dlg::onShowTask(WPARAM wParam,LPARAM lParam){ if(wParam!=IDR_MAINFRAME) return 1; switch(lParam){ case WM_RBUTTONUP:{ LPPOINT lpoint=new tagPOINT; ::GetCursorPos(lpoint); CMenu menu; menu.CreatePopupMenu(); menu.AppendMenu(MF_STRING,IDC_PLAY,"暂停/播放"); menu.AppendMenu(MF_STRING,IDC_PREVIOUS,"前一首"); menu.AppendMenu(MF_STRING,IDC_LATE,"后一首"); menu.AppendMenu(MF_STRING,WM_DESTROY,"关闭"); menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this); HMENU hmenu=menu.Detach(); menu.DestroyMenu(); delete lpoint; }break; case WM_LBUTTONDBLCLK:{ flag_5=!flag_5; if(!flag_5) this->ShowWindow(SW_SHOW); else onTray(); }break; } return 0; } void CMy2Dlg::OnSmallest() { // TODO: Add your control notification handler code here onTray(); } void CMy2Dlg::OnAbout() { // TODO: Add your control notification handler code here CAboutDlg dlg; dlg.DoModal(); }
转载于:https://blog.51cto.com/5857469/981107