vc制作视频播放器汇总.docx
《vc制作视频播放器汇总.docx》由会员分享,可在线阅读,更多相关《vc制作视频播放器汇总.docx(15页珍藏版)》请在冰豆网上搜索。
vc制作视频播放器汇总
VC:
制作视频播放器(ActiveX控件、工具栏、菜单栏、滑块、打开对话框))
1、先把文件AMOVIE.OCX复制到某一目录下,例如D:
\下,然后选择“开始”|“运行”命令,输入“regsvr32D:
\AMOVIE.OCX”,单击“确定”按钮后,弹出对话框,显示注册成功。
2、利用类向导,创建一个基于对话框的应用程序,删除向导自动生成的确定、取消按钮。
选择Project?
ADD。
。
。
添加ActiveMovieControlObject选项。
3、单击Insert按钮,关闭该对话框,ActiveMovie控件便出现在控件面板中,调整好控件在对话框中的位置。
4、添加菜单资源。
。
5、添加工具栏。
。
。
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("Failedtocreatetoolbar\n");
return-1; //failtocreate
}
RepositionBars(AFX_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”的消息映射:
voidCVideoDlg:
:
OnSize(UINTnType,intcx,intcy)
{
CDialog:
:
OnSize(nType,cx,cy);
//TODO:
Addyourmessagehandlercodehere
//工具栏处在对话框的下端
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
//为了使滑块控件也可以一直显示在对话框的最下端位置
CRectrect;
GetClientRect(rect);//得到客户端
inttop=rect.top;
rect.top=rect.bottom-60;
rect.bottom=rect.top+30;
if(IsWindow(m_sliderctrl.GetSafeHwnd()))
{
m_sliderctrl.MoveWindow(rect);//设置窗口大小
}
}
4、下面对菜单进行控制,在对话框中的菜单资源是利用对话框属性在对话框中进行绑定的,这时的菜单资源仅仅是与对话框进行绑定。
它不能响应ON_UPDATE_COMMAND_UI消息。
为了响应这一事件,
需要首先重载ON_WM_INITMENUPOPUP()消息。
voidCVideoDlg:
:
OnInitMenuPopup(CMenu*pPopupMenu,UINTnIndex,BOOLbSysMenu)
{
CDialog:
:
OnInitMenuPopup(pPopupMenu,nIndex,bSysMenu);
//TODO:
Addyourmessagehandlercodehere
ASSERT(pPopupMenu!
=NULL);
//Checktheenabledstateofvariousmenuitems.
CCmdUIstate;
state.m_pMenu=pPopupMenu;
ASSERT(state.m_pOther==NULL);
ASSERT(state.m_pParentMenu==NULL);
//Determineifmenuispopupintop-levelmenuandsetm_pOtherto
//itifso(m_pParentMenu==NULLindicatesthatitissecondarypopup).
HMENUhParentMenu;
if(AfxGetThreadState()->m_hTrackingMenu==pPopupMenu->m_hMenu)
state.m_pParentMenu=pPopupMenu;//Parent==childfortrackingpopup.
elseif((hParentMenu=:
:
GetMenu(m_hWnd))!
=NULL)
{
CWnd*pParent=this;
//Childwindowsdon'thavemenus--needtogotothetop!
if(pParent!
=NULL&&(hParentMenu=:
:
GetMenu(pParent->m_hWnd))!
=NULL)
{
intnIndexMax=:
:
GetMenuItemCount(hParentMenu);
for(intnIndex=0;nIndex {
if(:
:
GetSubMenu(hParentMenu,nIndex)==pPopupMenu->m_hMenu)
{
//Whenpopupisfound,m_pParentMenuiscontainingmenu.
state.m_pParentMenu=CMenu:
:
FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax=pPopupMenu->GetMenuItemCount();
for(state.m_nIndex=0;state.m_nIndex {
state.m_nID=pPopupMenu->GetMenuItemID(state.m_nIndex);
if(state.m_nID==0)
continue;//Menuseparatororinvalidcmd-ignoreit.
ASSERT(state.m_pOther==NULL);
ASSERT(state.m_pMenu!
=NULL);
if(state.m_nID==(UINT)-1)
{
//Possiblyapopupmenu,routetofirstitemofthatpopup.
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;//Firstitemofpopupcan'tberoutedto.
}
state.DoUpdate(this,TRUE);//Popupsareneverautodisabled.
}
else
{
//Normalmenuitem.
//Autoenable/disableifframewindowhasm_bAutoMenuEnable
//setandcommandis_not_asystemcommand.
state.m_pSubMenu=NULL;
state.DoUpdate(this,FALSE);
}
//Adjustformenudeletionsandadditions.
UINTnCount=pPopupMenu->GetMenuItemCount();
if(nCount {
state.m_nIndex-=(state.m_nIndexMax-nCount);