📄 flashplayview.cpp
字号:
}
m_flash.LoadMovie (0,strFileName);
//设置影片背景色,很重要!!!
m_flash.SetBackgroundColor(m_flash.GetBackgroundColor());
//获得影片总帧数
long nLength = m_flash.GetTotalFrames();
CString strCurPos;
strCurPos.Format(ID_INDICATOR_TOTALFRM, nLength);
CStatusBar *pStatusBar = ((CMainFrame *)GetParent())->GetStatusBar();
pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_TOTALFRM),strCurPos);
//设置工具条的范围
(((CMainFrame *)GetParent())->GetToolBar1())->GetSlider().SetRange(0,nLength);
(((CMainFrame *)GetParent())->GetToolBar1())->m_wndSpinCurFrame.SetRange(0,nLength);
m_bMovieExist = TRUE; //控件里有影片
//m_nTimer = SetTimer(1, 100, 0);
}
void CFlashPlayView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
long nCurrentFrm = m_flash.CurrentFrame();
if( m_bMovieExist && m_bIsPlaying )
{
((CMainFrame *)GetParent())->m_strCur.Format(ID_INDICATOR_TOTALFRM, nCurrentFrm);
//CString strCurPos;
//strCurPos.Format(ID_INDICATOR_TOTALFRM, nCurrentFrm);
//CStatusBar *pStatusBar = ((CMainFrame *)GetParent())->GetStatusBar();
//pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_CURFRM),strCurPos);
{
(((CMainFrame *)GetParent())->GetToolBar1())
->GetSlider().SetPos(nCurrentFrm);
(((CMainFrame *)GetParent())->GetToolBar1())
->m_wndSpinCurFrame.SetPos(nCurrentFrm);
}
}
CView::OnTimer(nIDEvent);
}
LRESULT CFlashPlayView::OnMsgChangPosition(WPARAM wParam,LPARAM lParam)
{
m_flash.StopPlay();
//KillTimer(1);
long nSetCurFrame = lParam;
if( wParam )
m_flash.SetFrameNum(nSetCurFrame);
char buffer[10];
/* Format and print various data: */
sprintf( buffer,"%d", nSetCurFrame );
// Update Status Bar
CStatusBar *pStatusBar = ((CMainFrame *)GetParent())->GetStatusBar();
pStatusBar->SetPaneText(
pStatusBar->CommandToIndex(ID_INDICATOR_CURFRM),
buffer);
return 0;
}
void CFlashPlayView::OnClose()
{
// TODO: Add your message handler code here and/or call default
// can't set KillTimer(m_nTimer)/SetTimer(....) in construction/distruction
KillTimer(m_nTimer);
CView::OnClose();
}
void CFlashPlayView::OnToolsOption()
{
// TODO: Add your command handler code here
COptionSet OptionDlg;
OptionDlg.m_bFileType = m_bFileType; //设置文件类型关联
OptionDlg.m_bPopupMenu = m_bEnableRBtn; //右键菜单是否有效
OptionDlg.m_bHideMouse = m_bHideMouse; //全屏播放时间是否隐藏鼠标指针
OptionDlg.m_bOnTop = m_bOnTop;
if( m_nEditHideTime>20 ) m_nEditHideTime = 20;
OptionDlg.m_nEditHideTime = m_nEditHideTime; //全屏播放时鼠标静止后多少秒隐藏
if( OptionDlg.DoModal() == IDOK )
{
// enable right mouse pop up
m_bEnableRBtn = OptionDlg.m_bPopupMenu;
m_flash.SetMenuEnable(m_bEnableRBtn);
m_bFileType = OptionDlg.m_bFileType;
m_bHideMouse = OptionDlg.m_bHideMouse;
m_nEditHideTime = OptionDlg.m_nEditHideTime;
m_bOnTop = OptionDlg.m_bOnTop;
char * strSection = "Option";
char * strStringFileAssoc = "File Type Associate";
//char * strIntEnablePopup = "Enable popup menu";
char * strIntHideMouse = "Hide Mouse pointer while Full Screen";
char * strIntHideTime = "Hide time";
char * strIntOnTop = "Always on top";
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt(strSection, strStringFileAssoc, m_bFileType);
//pApp->WriteProfileInt(strSection, strIntEnablePopup, m_bEnableRBtn);
pApp->WriteProfileInt(strSection, strIntHideMouse, m_bHideMouse);
pApp->WriteProfileInt(strSection, strIntHideTime, m_nEditHideTime);
pApp->WriteProfileInt(strSection, strIntOnTop, m_bOnTop);
// set the main window is on top of all window on desktop
if( m_bOnTop ) ::SetWindowPos( pApp->m_pMainWnd->GetSafeHwnd(),
HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
else ::SetWindowPos( pApp->m_pMainWnd->GetSafeHwnd(),
HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
FileTypeAssociate( m_bFileType );
}
}
// 处理ESCAPE键的函数,总是一旦点击主画面就无效
extern CFlashPlayApp theApp;
void CFlashPlayView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch (nChar)
{
case VK_ESCAPE:
if(((CMainFrame *)theApp.m_pMainWnd)->m_bFullScreenMode)
((CMainFrame *)theApp.m_pMainWnd)->FullScreenModeOff();
if(((CMainFrame *)theApp.m_pMainWnd)->m_bIsCompactMode)
((CMainFrame *)theApp.m_pMainWnd)->CompactModeOff();
break;
default:
break;
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CFlashPlayView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
// Make sure window is active
//GetParentFrame()->ActivateFrame();
BCMenu menu;
if (menu.LoadMenu(IDR_MENU_POPUP))
{
menu.LoadToolbar(IDR_MAINFRAME);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(NULL != pPopup);
CMainFrame *pMainWnd = (CMainFrame *)AfxGetMainWnd();
if( pMainWnd->m_bFullScreenMode )
{
pPopup->ModifyMenu(ID_VIEW_FULL_SCREEN, MF_BYCOMMAND,
ID_VIEW_FULL_SCREEN, _T("Normal Mode"));
pPopup->SetDefaultItem(ID_VIEW_FULL_SCREEN);
}
else if(pMainWnd->m_bIsCompactMode )
{
pPopup->ModifyMenu(ID_VIEW_COMPACT_MODE, MF_BYCOMMAND,
ID_VIEW_COMPACT_MODE, _T("Normal Mode"));
pPopup->SetDefaultItem(ID_VIEW_COMPACT_MODE);
}
pPopup->TrackPopupMenu( TPM_RIGHTBUTTON | TPM_LEFTALIGN,
point.x,point.y, this); //AfxGetMainWnd() Route commands through the main window
return;
}
Default(); // Default message handling if we didn't do anything
}
void CFlashPlayView::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
TCHAR * strSection = _T("Option");
TCHAR * strIntEnablePopup = _T("Enable popup menu");
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt(strSection, strIntEnablePopup, m_bEnableRBtn);
CView::PostNcDestroy();
}
void CFlashPlayView::FileTypeAssociate(BOOL IsRight)
{
DWORD dwDisposition;
CRegistry regSWF,regSWF_AUTO_FILE;
regSWF.Create( dwDisposition,HKEY_CLASSES_ROOT,_T(".swf") );
regSWF_AUTO_FILE.Create( dwDisposition,HKEY_CLASSES_ROOT,_T("swf_auto_file") );
if( IsRight )
{
try
{
//--------文件名根键--------------------
const unsigned char szFileBase[] = "swf_auto_file";
regSWF.Write( NULL,szFileBase,sizeof(szFileBase) );
//--------文件关联细则------------------
const unsigned char szFileDisp[] = "ShockWave Flash Object";
regSWF_AUTO_FILE.Write( NULL,szFileDisp,sizeof(szFileDisp) );
DWORD Flags = 0;
regSWF_AUTO_FILE.Write( "EditFlags",(CONST BYTE *)&Flags,sizeof(Flags),REG_DWORD );
Flags = 8;
regSWF_AUTO_FILE.Write( "BrowserFlags",(CONST BYTE *)&Flags,sizeof(Flags),REG_DWORD );
//--------更多的明细--------------------
LPTSTR FullFileName = new TCHAR[1024];
::GetModuleFileName(NULL,FullFileName,1024);
CRegistry DefaultIcon,Shell,ShellOpenCommand,ShellOpenDdeexec,
Application,Topic;
//--------1.默认图标---------------------------------
DefaultIcon.Create( dwDisposition,HKEY_CLASSES_ROOT,"swf_auto_file\\DefaultIcon" );
LPTSTR pszDefaultIcon = new TCHAR[1024];
sprintf( pszDefaultIcon,"%s,1",FullFileName);
DefaultIcon.Write( NULL,(CONST BYTE *)pszDefaultIcon,sizeof(pszDefaultIcon) );
//--------2.Open-------------------------------------
Shell.Create( dwDisposition,HKEY_CLASSES_ROOT,"swf_auto_file\\shell\\open" );
const unsigned char szOpen[] = "open";
Shell.Write( NULL,szOpen,sizeof(szOpen) );
//--------3.command----------------------------------
ShellOpenCommand.Create( dwDisposition,HKEY_CLASSES_ROOT,"swf_auto_file\\shell\\open\\command" );
LPTSTR pszCommand = new TCHAR[1024];
sprintf( pszCommand,"%s /dde %%1",FullFileName);
ShellOpenCommand.Write( NULL,(CONST BYTE *)pszCommand,sizeof(pszCommand) );
//--------4.ShellOpenDdeexec------------------------
ShellOpenDdeexec.Create( dwDisposition,HKEY_CLASSES_ROOT,"swf_auto_file\\shell\\open\\ddeexec" );
const unsigned char szDdeexec[] = "[open(\\""%1\\"")]";
ShellOpenDdeexec.Write( NULL,szDdeexec,sizeof(szDdeexec) );
//--------5.Application-----------------------------
Application.Create( dwDisposition,HKEY_CLASSES_ROOT,"swf_auto_file\\shell\\open\\ddeexec\\Application" );
const unsigned char szApp[] = "FlashPlay";
ShellOpenDdeexec.Write( NULL,szApp,sizeof(szApp) );
//--------6.Topic----------------------------------
Topic.Create( dwDisposition,HKEY_CLASSES_ROOT,"swf_auto_file\\shell\\open\\ddeexec\\Topic" );
const unsigned char szTopic[] = "System";
Topic.Write( NULL,szTopic,sizeof(szTopic) );
}
catch( CRegistryException *regError )
{
// display the error
regError->ReportError();
// now delete the handle
regError->Delete();
}
/*( HKEY_CLASSES_ROOT,".swf" )( HKEY_CLASSES_ROOT,"swf_auto_file")
try
{
regConfig.Open( HKEY_LOCAL_MACHINE, "SOFTWARE\\CLASSES" );
DWORD nLen;
BYTE nSomeByteData;
char szSomeStringData;
DWORD nSomeDWordData;
// if you dont want the type of the data to be returned...
// then specify NULL on the third parameter...
regConfig.Read( &nSomeByteData, ( nLen=sizeof( nSomeByteData ), &nLen ), NULL, "Some Byte Data" );
regConfig.Read(( LPBYTE )&szSomeStringData, ( nLen=sizeof( szSomeStringData ), &nLen ), NULL, "Some String Data" );
regConfig.Read(( LPBYTE )&nSomeDWordData, ( nLen=sizeof( nSomeDWordData ), &nLen ), NULL, "Some DWord Data" );
//... but if you want the data type, then pass a DWORD pointer
DWORD nType;
char nSomeUnknownData[ 50 ];
regConfig.Read(( LPBYTE )&nSomeUnknownData, ( nLen=sizeof( nSomeUnknownData ), &nLen ), &nType, "Some Unknown Data" );
// your nType now may have the following value: REG_BINARY, REG_DWORD, REG_SZ....
}
catch( CRegistryException *regError )
{
// display the error
regError->ReportError();
// now delete the handle
regError->Delete();
}
//*/
}
else
{
TRUE;
}
}
BOOL CFlashPlayView::OnCommand(WPARAM wParam, LPARAM lParam)
{
//以下两行代码的次序不能变,否则内存泄漏
CView::OnCommand(wParam, lParam);
//ID_VIEW_FULL_SCREEN ID_VIEW_COMPACT_MODE
//很重要,不然弹出菜单的某些项不能执行
::SendMessage(GetParent()->GetSafeHwnd(),WM_COMMAND,wParam,lParam );
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -