// mp3PlayerDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "mp3Player.h"
#include "mp3PlayerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// Cmp3PlayerDlg 对话框
Cmp3PlayerDlg::Cmp3PlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(Cmp3PlayerDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cmp3PlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Cmp3PlayerDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_NC,OnNotifyIcon)
//}}AFX_MSG_MAP
ON_WM_TIMER()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_DROPFILES()
ON_WM_RBUTTONDOWN()
ON_WM_MOUSEWHEEL()
ON_COMMAND(ID_0002, &Cmp3PlayerDlg::On0002)
ON_COMMAND(ID_0003, &Cmp3PlayerDlg::On0003)
ON_COMMAND(ID_0004, &Cmp3PlayerDlg::On0004)
ON_COMMAND(ID_0005, &Cmp3PlayerDlg::On0005)
ON_COMMAND(ID_0001, &Cmp3PlayerDlg::On0001)
ON_COMMAND(ID_0006, &Cmp3PlayerDlg::On0006)
ON_COMMAND(ID_0007, &Cmp3PlayerDlg::On0007)
ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()
// Cmp3PlayerDlg 消息处理程序
BOOL Cmp3PlayerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
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);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
// 获得当前DC
m_pDC = this->GetDC();
// 载入图片
m_image = new WinImage(m_pDC->m_hDC,AfxGetInstanceHandle());
m_image->loadImage(NULL,IDB_SLEEP_0);
m_image->loadImage(NULL,IDB_SLEEP_1);
m_image->loadImage(NULL,IDB_PAUSE_0);
m_image->loadImage(NULL,IDB_SING_0);
m_image->loadImage(NULL,IDB_SING_1);
// 根据BMP图片设置RGN
m_image->setRgn(0);
m_image->setRgn(3);
MOTION motion0[] =
{
{0,0,100},
{0,1,50},
};
MOTION motion1[] =
{
{0,2,100},
};
MOTION motion2[] =
{
{1,3,100},
{1,4,50},
};
m_image->setMotion(motion0,2);
m_image->setMotion(motion1,1);
m_image->setMotion(motion2,2);
// 根据RGN设置自定义窗口
m_image->setCustomWindow(m_hWnd, 0, RIGHT_DOWN);
// 设置播放器类
m_music = new D3DMusic();
m_music->setLoop(0);
// 设置绘制定时器
this->SetTimer(0,1,NULL); // 绘制定时器
this->SetTimer(1,0,NULL); // 拖动定时器
this->SetTimer(2,0,NULL); // 音乐监测定时器
// 默认没有移动
isMove = false;
// 初始化变量
m_iCount = 0;
m_iMotion = 0;
// 初始化播放列表
m_pPlayList = new CPlayList();
m_pPlayList->initMusic(m_music);
m_pPlayList->Create(IDD_PLAYLIST);
//m_image->setCustomWindow(m_pPlayList->m_hWnd,0);
ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);
NotifyIcon.cbSize=sizeof(NOTIFYICONDATA);
NotifyIcon.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
NotifyIcon.hWnd=m_hWnd;
wcscpy_s(NotifyIcon.szTip,sizeof(NotifyIcon.szTip),TEXT("mp3Player v1.0"));
NotifyIcon.uCallbackMessage=WM_NC;
NotifyIcon.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
Shell_NotifyIcon(NIM_ADD,&NotifyIcon);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void Cmp3PlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void Cmp3PlayerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
//
HCURSOR Cmp3PlayerDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Cmp3PlayerDlg::OnCancel()
{
// TODO: 在此添加专用代码和/或调用基类
Shell_NotifyIcon(NIM_DELETE,&NotifyIcon);
CDialog::OnCancel();
}
void Cmp3PlayerDlg::OnOK()
{
// TODO: 在此添加专用代码和/或调用基类
//CDialog::OnOK();
}
void Cmp3PlayerDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (nIDEvent == 0) {
draw();
}
if (nIDEvent == 1) {
// 获得窗口坐标
PWINDOWINFO wndInfo = new tagWINDOWINFO;
GetWindowInfo(wndInfo);
m_iWndX = wndInfo->rcWindow.left;
m_iWndY = wndInfo->rcWindow.top;
m_iWndWidth = wndInfo->rcWindow.right - m_iWndX;
m_iWndHeight = wndInfo->rcWindow.bottom - m_iWndY;
delete wndInfo;
// 获得鼠标位置
GetCursorPos(&m_point);
m_iMouseX = m_point.x;
m_iMouseY = m_point.y;
// 判断是否移动窗口
if(isMove)
{
m_iWndX = m_iWndX+(m_iMouseX-m_iLastX);
m_iWndY = m_iWndY+(m_iMouseY-m_iLastY);
MoveWindow(m_iWndX, m_iWndY,m_iWndWidth,m_iWndHeight);
}
m_iLastX = m_iMouseX;
m_iLastY = m_iMouseY;
}
if (nIDEvent == 2)
{
static int status;
static int curSel;
if (m_music)
status = m_music->musicStatus();
else
return;
if (status == 0)
{
curSel = m_pPlayList->m_comboBox.GetCurSel();
if (curSel == -1)
{
return;
}
if (curSel == m_pPlayList->m_comboBox.GetCount()-1)
{
m_pPlayList->m_comboBox.SetCurSel(0);
}
else
{
m_pPlayList->m_comboBox.SetCurSel(curSel+1);
}
m_pPlayList->UpdateData(TRUE);
m_music->release();
m_music->loadFile(m_pPlayList->strValue);
m_music->play();
m_image->resetMotion();
//check(m_pPlayList->strValue);
}
}
CDialog::OnTimer(nIDEvent);
}
//-----------------------------------------------------------------------------------------------------
// 名称: draw()
// 描述: 绘制已载入的位图
//---------------------------------------------------------------------------------------------