www.pudn.com > RealPlayer.rar > RealPlayerDlg.cpp
// RealPlayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "RealPlayer.h"
#include "RealPlayerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_DISPLAY WM_USER+1//播放显示消息
HHOOK g_hKeyboard=NULL;
//HHOOK g_hMouse;
HWND g_hWnd=NULL;
BOOL bIsDisplayAccelerate=FALSE;
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
//if(VK_SPACE==wParam || VK_RETURN==wParam)
/*if(VK_F4==wParam && (1==(lParam>>29 & 1)))
return 1;
else
return CallNextHookEx(g_hKeyboard,code,wParam,lParam);*/
if(VK_RETURN==wParam)
{
bIsDisplayAccelerate=TRUE;
::SendMessage(g_hWnd,WM_DISPLAY,0,0);
UnhookWindowsHookEx(g_hKeyboard);
// UnhookWindowsHookEx(g_hMouse);
}
if(VK_ESCAPE==wParam)
{
// bIsDisplayAccelerate=TRUE;
::SendMessage(g_hWnd,WM_DISPLAY,0,0);
UnhookWindowsHookEx(g_hKeyboard);
// UnhookWindowsHookEx(g_hMouse);
}
g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,NULL,GetCurrentThreadId());
return 1;
}
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CRealPlayerDlg dialog
CRealPlayerDlg::CRealPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRealPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRealPlayerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bIsFullscr=FALSE;
}
void CRealPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRealPlayerDlg)
DDX_Control(pDX, IDC_REALPLAYER, m_realPlayer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRealPlayerDlg, CDialog)
//{{AFX_MSG_MAP(CRealPlayerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDM_OPEN, OnOpen)
ON_COMMAND(IDM_FULLSCR, OnFullscr)
ON_WM_RBUTTONDOWN()
ON_COMMAND(IDM_MINSCR, OnMinscr)
ON_MESSAGE(WM_DISPLAY,OnDisplay)//添加自定义消息映射
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRealPlayerDlg message handlers
BOOL CRealPlayerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
GetWindowRect(&m_wndRc);
// m_realPlayer.SetEnableFullScreen(TRUE);
// m_realPlayer.SetWantKeyboardEvents(TRUE);
// m_realPlayer.SetWantMouseEvents(TRUE);
g_hWnd=m_hWnd;
// g_hMouse=SetWindowsHookEx(WH_MOUSE,MouseProc,NULL,GetCurrentThreadId());
g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,NULL,GetCurrentThreadId());
return TRUE; // return TRUE unless you set the focus to a control
}
void CRealPlayerDlg::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 CRealPlayerDlg::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 CRealPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRealPlayerDlg::OnOpen()
{
// TODO: Add your command handler code here
CString strFilePath;
CFileDialog fileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"RM文件(*.rm)|*.rm | RMVB文件(*.rmvb)|*.rmvb|");
if(fileDlg.DoModal()==IDOK){
strFilePath=fileDlg.GetPathName();
}
if(strFilePath!=""){
m_realPlayer.SetSource(strFilePath);//open the file
m_realPlayer.DoPlay();
}
// if(!m_realPlayer.GetEnableFullScreen())
// m_realPlayer.SetEnableFullScreen(TRUE);
}
void CRealPlayerDlg::OnFullscr()
{
// TODO: Add your command handler code here
if(!m_realPlayer.GetFullScreen()){
m_realPlayer.SetFullScreen();
m_bIsFullscr=TRUE;
}
}
void CRealPlayerDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMenu menu;
menu.LoadMenu(IDR_MENU1);
CMenu* pPopup = menu.GetSubMenu(0);
ClientToScreen(&point);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,this);//GetParent());
CDialog::OnRButtonDown(nFlags, point);
}
void CRealPlayerDlg::OnMinscr()
{
// TODO: Add your command handler code here
SendMessage(WM_SYSCOMMAND,SC_MINIMIZE,0);
}
//DEL void CRealPlayerDlg::OnCancel()
//DEL {
//DEL // TODO: Add extra cleanup here
//DEL
//DEL // Ensure that you reset all the values back to the
//DEL // ones before modification. This handler is called
//DEL // when the user doesn't want to save the changes.
//DEL UnhookWindowsHookEx(g_hKeyboard);
//DEL
//DEL CDialog::OnCancel();
//DEL }
/*
void CRealPlayerDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_ESCAPE){//"ESC"
this->MoveWindow(200,200,500,500);//&m_wndRc);
m_realPlayer.SetEnableFullScreen(FALSE);
}
CDialog::OnChar(nChar, nRepCnt, nFlags);
}
*/
void CRealPlayerDlg::OnDisplay(){
if(m_bIsFullscr){
m_bIsFullscr=FALSE;
this->MoveWindow((GetSystemMetrics(SM_CXSCREEN)-m_wndRc.Width())/2,
(GetSystemMetrics(SM_CYSCREEN)-m_wndRc.Height())/2,m_wndRc.Width(),m_wndRc.Height());
}
if(bIsDisplayAccelerate){
m_bIsFullscr=TRUE;
bIsDisplayAccelerate=FALSE;
m_realPlayer.SetFullScreen();
}
}
void CRealPlayerDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
UnhookWindowsHookEx(g_hKeyboard);
CDialog::OnClose();
}