www.pudn.com > yuplayer.rar > yuplayerDlg.cpp
// yuplayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "yuplayer.h"
#include "yuplayerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CYuplayerDlg dialog
CYuplayerDlg::CYuplayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CYuplayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CYuplayerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CYuplayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CYuplayerDlg)
DDX_Control(pDX, IDC_MEDIAPLAYER1, m_player);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CYuplayerDlg, CDialog)
//{{AFX_MSG_MAP(CYuplayerDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDC_FILE_OPEN, OnFileOpen)
ON_COMMAND(IDC_FILE_EXIT, OnFileExit)
ON_COMMAND(ID_MENUITEM_TOPMOST, OnMenuitemTopmost)
ON_COMMAND(ID_MENUITEM_RECOVER, OnMenuitemRecover)
ON_COMMAND(ID_MENUITEM32773, OnMenuitem32773)
ON_COMMAND(ID_ABOUT, OnAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYuplayerDlg message handlers
BOOL CYuplayerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CYuplayerDlg::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 CYuplayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CYuplayerDlg::OnFileOpen()
{
char szFileFilter[]=
"音频文件(*.mp3;*.Wma;*.wav;*.mid)|*.mp3;*.Wma;*.wav;*.mid|"
"视频文件(*.dat;*.avi;*.rm;*.rmvb;*.mov;*.mmm;*.mpeg)|*.dat;*.avi;*.rm;*.rmvb;*.mov;*.mmm;*.mpeg|"
"All File(*.*)|*.*||";//设置文件类型
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter);//书上P193
if(dlg.DoModal()==IDOK)
{
CString PathName=dlg.GetPathName();//得到整个路径的名
m_player.SetFileName(PathName);//打开路径文件
}
}
void CYuplayerDlg::OnFileExit()
{
OnOK();
}
void CYuplayerDlg::OnMenuitemTopmost()
{
::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_TOPMOST,//在最顶层
-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);
}
void CYuplayerDlg::OnMenuitemRecover()
{
::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_NOTOPMOST,//获得窗口的句柄,使窗体不在最顶层
-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE); //坐标,不移动窗体,不改变窗体大小
}
void CYuplayerDlg::OnMenuitem32773()
{
NOTIFYICONDATA nid; //结构体
nid.cbSize = sizeof(nid);//大小
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; //uCallbackMessage参数有效,hIcon参数有效
nid.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //获得窗体图标
strcpy(nid.szTip,"yu播放器");
nid.uCallbackMessage = WM_USER;//实现对用户鼠标操作的响应
nid.uID = 10; //图标的标识
nid.hWnd =m_hWnd; //消息接收窗口的句柄
Shell_NotifyIcon(NIM_ADD, &nid);
ShowWindow(SW_HIDE); // 隐藏主窗口
m_bIsShow = FALSE; //作为一个标志
}
LRESULT CYuplayerDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message==WM_USER && lParam == WM_LBUTTONDOWN)
if(!m_bIsShow)
{
ShowWindow(SW_SHOWNORMAL);
m_bIsShow = TRUE;
Onnohide();
}
return CDialog::DefWindowProc(message, wParam, lParam);
}
void CYuplayerDlg::Onnohide()
{
NOTIFYICONDATA nid; //结构体
nid.cbSize = sizeof(nid);//大小
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; //uCallbackMessage参数有效,hIcon参数有效
nid.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //获得窗体图标
strcpy(nid.szTip,"yu播放器");
nid.uCallbackMessage = WM_USER;//实现对用户鼠标操作的响应
nid.uID = 10; //图标的标识
nid.hWnd =m_hWnd; //消息接收窗口的句柄
Shell_NotifyIcon(NIM_DELETE, &nid);
}
void CYuplayerDlg::OnAbout()
{
MessageBox("作者:张瑜");
}