1、vc制作视频播放器VC:制作视频播放器(ActiveX控件、工具栏、菜单栏、滑块、打开对话框)1、先把文件AMOVIE.OCX复制到某一目录下,例如D:下,然后选择“开始”|“运行”命令,输入“regsvr32D:AMOVIE.OCX”,单击“确定”按钮后,弹出对话框,显示注册成功。2、利用类向导,创建一个基于对话框的应用程序,删除向导自动生成的确定、取消按钮。选择Project?ADD。添加ActiveMovie Control Object选项。3、单击Insert按钮,关闭该对话框,ActiveMovie控件便出现在控件面板中,调整好控件在对话框中的位置。4、添加菜单资源。5、添加工具栏
2、。6、添加滑块控件,及变量。系统实现:1、设置对话框的最小化,对话框属性对话框中选择Style标签。2、添加工具栏。在OnInitDialog()函数中: if (!m_toolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_BOTTOM |CBRS_TOOLTIPS ) | !m_toolbar.LoadToolBar(IDR_TOOLBAR1) TRACE0(Failed to create toolbarn); return -1; / fail to create RepositionBars(AF
3、X_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); m_toolbar.SetBarStyle(m_toolbar.GetBarStyle()|CBRS_BOTTOM|CBRS_SIZE_DYNAMIC|CBRS_SIZE_DYNAMIC);3、利用类向导,添加“WM_SIZE”的消息映射:void CVideoDlg:OnSize(UINT nType, int cx, int cy) CDialog:OnSize(nType, cx, cy); / TODO: Add your message handler code here /工具
4、栏处在对话框的下端 RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);/为了使滑块控件也可以一直显示在对话框的最下端位置 CRect rect; GetClientRect(rect);/得到客户端 int top=rect.top; rect.top=rect.bottom-60; rect.bottom=rect.top+30; if (IsWindow(m_sliderctrl.GetSafeHwnd() m_sliderctrl.MoveWindow(rect);/设置窗口大小 4、下面对菜单进行控制,
5、在对话框中的菜单资源是利用对话框属性在对话框中进行绑定的,这时的菜单资源仅仅是与对话框进行绑定。它不能响应ON_UPDATE_COMMAND_UI消息。为了响应这一事件,需要首先重载ON_WM_INITMENUPOPUP()消息。void CVideoDlg:OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) CDialog:OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); / TODO: Add your message handler code here ASSERT(pP
6、opupMenu != NULL); / Check the enabled state of various menu items. CCmdUI state; state.m_pMenu = pPopupMenu; ASSERT(state.m_pOther = NULL); ASSERT(state.m_pParentMenu = NULL); / Determine if menu is popup in top-level menu and set m_pOther to / it if so (m_pParentMenu = NULL indicates that it is se
7、condary popup). HMENU hParentMenu; if (AfxGetThreadState()-m_hTrackingMenu = pPopupMenu-m_hMenu) state.m_pParentMenu = pPopupMenu; / Parent = child for tracking popup. else if (hParentMenu = :GetMenu(m_hWnd) != NULL) CWnd* pParent = this; / Child windows dont have menus-need to go to the top! if (pP
8、arent != NULL &(hParentMenu = :GetMenu(pParent-m_hWnd) != NULL) int nIndexMax = :GetMenuItemCount(hParentMenu); for (int nIndex = 0; nIndex m_hMenu) / When popup is found, m_pParentMenu is containing menu. state.m_pParentMenu = CMenu:FromHandle(hParentMenu); break; state.m_nIndexMax = pPopupMenu-Get
9、MenuItemCount(); for (state.m_nIndex = 0; state.m_nIndex GetMenuItemID(state.m_nIndex); if (state.m_nID = 0) continue; / Menu separator or invalid cmd - ignore it. ASSERT(state.m_pOther = NULL); ASSERT(state.m_pMenu != NULL); if (state.m_nID = (UINT)-1) / Possibly a popup menu, route to first item o
10、f that popup. state.m_pSubMenu = pPopupMenu-GetSubMenu(state.m_nIndex); if (state.m_pSubMenu = NULL | (state.m_nID = state.m_pSubMenu-GetMenuItemID(0) = 0 | state.m_nID = (UINT)-1) continue; / First item of popup cant be routed to. state.DoUpdate(this, TRUE); / Popups are never auto disabled. else /
11、 Normal menu item. / Auto enable/disable if frame window has m_bAutoMenuEnable / set and command is _not_ a system command. state.m_pSubMenu = NULL; state.DoUpdate(this, FALSE); / Adjust for menu deletions and additions. UINT nCount = pPopupMenu-GetMenuItemCount(); if (nCount state.m_nIndexMax) stat
12、e.m_nIndex -= (state.m_nIndexMax - nCount); while (state.m_nIndex GetMenuItemID(state.m_nIndex) = state.m_nID) state.m_nIndex+; state.m_nIndexMax = nCount; void CVideoDlg:OnUpdateStop(CCmdUI* pCmdUI) / TODO: Add your command update UI handler code here pCmdUI-Enable(flag);6、为了使ActiveMovie控件进行播放,对Act
13、iveMovie控件进行属性设置。SelectionStart 0ShowDisplay 真ShowPositionContrls 真ShowSelectionControls 假ShowTracker 真Volume真等等。7、利用类向导为ActiveMovie控件添加变量CActiveMovie m_play;添加文件打开消息映射:void CVideoDlg:OnOpenFile() / TODO: Add your command handler code here CFileDialog FileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_ALLO
14、WMULTISELECT|OFN_NOCHANGEDIR, Video File(*.avi;*.asf;*.wmv;*.rm;*.rmvb)|*.avi;*.asf;*.wmv;*.rm;*.rmvb|Music Files(*.mp3;*.wav;*.cda)|*.mp3;*.wav;*.cda|Mpegvideo File(*.dat;*.mpg;*.mpeg)|*.dat;*.mpg;*.mpeg;*.mpe|); if(FileDlg.DoModal()=IDOK) filename=FileDlg.GetPathName(); m_player.SetFileName(filena
15、me); flag=true; toolbarctrl-EnableButton(IDM_PLAY,true); toolbarctrl-EnableButton(IDM_PLAYPAUSE,true); toolbarctrl-EnableButton(IDM_STOP,true); toolbarctrl-EnableButton(IDM_ADD_VOLUME,true); toolbarctrl-EnableButton(IDM_SUB_VOLUME,true); MoveMovieWindow(); int iInstallresult; iInstallresult=SetTimer
16、(1,1000,NULL); if(iInstallresult=0) MessageBox(fail to install the timer!); 8、改变对话框的大小以适应ActiveMovie控件的大小:void CVideoDlg:MoveMovieWindow()/改变窗口大小以适应控件大小 CRect rc1,rc2,rc3; /得到ActiveMovie控件大小 m_player.GetWindowRect(rc1);/保证对话框客户区的宽不小于300象素,高不小于225象素 if(rc1.Width()300|rc1.Height()EnableButton(IDM_PLAY
17、PAUSE,false); toolbarctrl-EnableButton(IDM_STOP,false); toolbarctrl-EnableButton(IDM_ADD_VOLUME,false); toolbarctrl-EnableButton(IDM_SUB_VOLUME,false);11、音量大小调整:void CVideoDlg:OnAddVolume() / TODO: Add your command handler code here long m_Reduce = m_player.GetVolume(); if(m_Reduce=-1500) m_player.P
18、ause(); m_player.SetVolume(m_Reduce-100); m_player.Run(); 12、选择视频大小:void CVideoDlg:OnSizeFour() / TODO: Add your command handler code here m_player.Pause(); m_player.SetFullScreenMode(false); m_player.SetMovieWindowSize(3); m_player.Run(); num=3;void CVideoDlg:OnUpdateSizeFour(CCmdUI* pCmdUI) / TODO
19、: Add your command update UI handler code here pCmdUI-Enable(flag); if(num=3) pCmdUI-SetCheck(true); else pCmdUI-SetCheck(false);void CVideoDlg:OnSizeSixten() / TODO: Add your command handler code here m_player.Pause(); m_player.SetFullScreenMode(false); m_player.SetMovieWindowSize(2); m_player.Run(
20、); num=2;void CVideoDlg:OnUpdateSizeSixten(CCmdUI* pCmdUI) / TODO: Add your command update UI handler code here pCmdUI-Enable(flag); if(num=2) pCmdUI-SetCheck(true); else pCmdUI-SetCheck(false);void CVideoDlg:OnSizeTwo() / TODO: Add your command handler code here m_player.Pause(); m_player.SetFullScreenMode(false); m_player.SetMovieWindowSize(4); m_player.Run(); num=4;void CVideoDlg:OnUpdateSizeTwo(CCmdUI* pCmdUI) / TODO: Add your command update UI handler code here pCmdUI-Enable(flag); if(num=4)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1