CMenu MoviePopupMenu;//声明
MoviePopupMenu.CreatePopupMenu();//创建弹出菜单
根据对象类型增加弹出项
if(nTemp == WB_OBJ_FLASH && nSelectedObj == ) // FLASH对象
{
CString strPlay;
strPlay = ReadConfigText(_T("WhiteBoardMenuListText"), _T("movie_play"));
if (strPlay.IsEmpty())
{
strPlay = _T("播放");
}
CString strStop;
strStop = ReadConfigText(_T("WhiteBoardMenuListText"), _T("movie_Stop"));
if (strStop.IsEmpty())
{
strStop = _T("停止");
}
CString strPause;
strPause = ReadConfigText(_T("WhiteBoardMenuListText"), _T("movie_pause"));
if (strPause.IsEmpty())
{
strPause = _T("暂停");
}
CString strLoop;
strLoop = ReadConfigText(_T("WhiteBoardMenuListText"), _T("movie_loop"));
if (strLoop.IsEmpty())
{
strLoop = _T("循环播放");
}
if (((CWBFlash *)pObj)->m_bIsRunning)
{
if (((CWBFlash *)pObj)->m_bIsPause)
{
MoviePopupMenu.AppendMenu(MF_STRING, ID_OBMENU_MOVIE_PALY, strPlay);
MoviePopupMenu.AppendMenu(MF_GRAYED|MF_STRING, ID_OBMENU_MOVIE_PAUSE, strPause);
}
else
{
MoviePopupMenu.AppendMenu(MF_GRAYED|MF_STRING, ID_OBMENU_MOVIE_PALY, strPlay);
MoviePopupMenu.AppendMenu(MF_STRING, ID_OBMENU_MOVIE_PAUSE, strPause);
}
MoviePopupMenu.AppendMenu(MF_STRING, ID_OBMENU_MOVIE_STOP,strStop);
}
else
{
MoviePopupMenu.AppendMenu(MF_STRING, ID_OBMENU_MOVIE_PALY, strPlay);
MoviePopupMenu.AppendMenu(MF_GRAYED|MF_STRING, ID_OBMENU_MOVIE_PAUSE, strPause);
MoviePopupMenu.AppendMenu(MF_GRAYED|MF_STRING, ID_OBMENU_MOVIE_STOP, strStop);
}
MoviePopupMenu.AppendMenu(MF_SEPARATOR);//增加一条分割线
声明位图对象
CBitmap m_MoviePlayBmp; //播放
CBitmap m_MoviePauseBmp; //暂停
CBitmap m_MovieStopBmp; //停止
CBitmap m_MovieCircleBmp; //循环播放
CBitmap m_MediaCatchFrameBmp; //截图
CBitmap m_MediaSetmuteBmp; //有音
CBitmap m_MediaNoSetmuteBmp; //静音
//菜单中加载图片
//视频 MoviePopupMenu.SetMenuItemBitmaps(ID_OBMENU_MOVIE_PALY, MF_BYCOMMAND, &m_MoviePlayBmp,NULL); // 播放
MoviePopupMenu.SetMenuItemBitmaps(ID_OBMENU_MOVIE_PAUSE, MF_BYCOMMAND, &m_MoviePauseBmp,NULL); // 暂停
MoviePopupMenu.SetMenuItemBitmaps(ID_OBMENU_MOVIE_STOP, MF_BYCOMMAND, &m_MovieStopBmp,NULL); // 停止
MoviePopupMenu.SetMenuItemBitmaps(ID_OBMENU_MOVIE_CIRCLE, MF_BYCOMMAND, &m_MovieCircleBmp,NULL); // 循环播放
PopupMenu.SetMenuItemBitmaps(ID_OBMENU_MEDIA_CATCHFRAME, MF_BYCOMMAND, &m_MediaCatchFrameBmp,NULL);//截图
PopupMenu.SetMenuItemBitmaps(ID_OBMENU_MEDIA_SETMUTE, MF_BYCOMMAND, &m_MediaSetmuteBmp,&m_MediaNoSetmuteBmp); //静音
void CWhiteBoardView::LoadPopupMenuBitmap()
{
//视频
m_MoviePlayBmp.LoadBitmap(IDB_OBMENU_MOVIE_PALY); // 视频播放
TranslateBitmapSizeToFitXP(&m_MoviePlayBmp);
m_MoviePauseBmp.LoadBitmap(IDB_OBMENU_MOVIE_PAUSE); //视频暂停
TranslateBitmapSizeToFitXP(&m_MoviePauseBmp);
m_MovieStopBmp.LoadBitmap(IDB_OBMENU_MOVIE_STOP); //视频停止
TranslateBitmapSizeToFitXP(&m_MovieStopBmp);
m_MovieCircleBmp.LoadBitmap(IDB_OBMENU_MOVIE_CIRCLE); //视频循环播放
TranslateBitmapSizeToFitXP(&m_MovieCircleBmp); m_MediaCatchFrameBmp.LoadBitmap(IDB_OBMENU_MEDIA_CATCHFRAME); //截图
TranslateBitmapSizeToFitXP(&m_MediaCatchFrameBmp);
m_MediaSetmuteBmp.LoadBitmap(IDB_OBMENU_MEDIA_SETMUTE); //有音
TranslateBitmapSizeToFitXP(&m_MediaSetmuteBmp);
m_MediaNoSetmuteBmp.LoadBitmap(IDB_OBMENU_MEDIA_NOSETMUTE); //静音
TranslateBitmapSizeToFitXP(&m_MediaNoSetmuteBmp);
}
上面是载入菜单项对应的自定义位图资源声明
#define IDB_OBMENU_MOVIE_PALY 3407
#define IDB_OBMENU_MOVIE_PAUSE 3408
#define IDB_OBMENU_MOVIE_STOP 3409
#define IDB_OBMENU_MOVIE_CIRCLE 3410
//下面是菜单项的资源声明
#define ID_OBMENU_MOVIE_PALY 8822
#define ID_OBMENU_MOVIE_STOP 8823
#define ID_OBMENU_MOVIE_PAUSE 8824
#define ID_OBMENU_MOVIE_CIRCLE 8825
BOOL CWhiteBoardView::OnCommand(WPARAM wParam, LPARAM lParam)
{
UINT nItemID = LOWORD(wParam);
switch (nItemID)
{
case ID_OBMENU_MOVIE_PALY: //视频播放
{
CWBObject *pObj = g_pWBPage->FindByLayerIndex(m_dwMenuLayerIndex);
if (pObj == NULL)
{
break;
}
WB_OBJ_TYPE ntemptype = (WB_OBJ_TYPE)pObj->GetType();
if ( ntemptype== WB_OBJ_FLASH) //如果对象是flash
{
((CWBFlash *)pObj)->Start();
}
if (ntemptype == WB_OBJ_MEDIA)
{
if (((CWBMedia*)pObj)->IsActiveCreated())
{
((CWBMedia*)pObj)->MediaPlay();
}
else
{
((CWBMedia*)pObj)->SetMediaPlayState(Media_playing);
}
}
Invalidate();
//发送同步信息
XMemIni xmlObj;
pObj->SetXmlValue(xmlObj);
if (ntemptype == WB_OBJ_MEDIA || ntemptype == WB_OBJ_FLASH)
{
xmlObj.Set(KEY_MEDIA_OPERATION, WB_MOVIE_START);
}
g_pWhiteBoardView->ChangeObj(xmlObj);
}
break;
case ID_OBMENU_MOVIE_STOP: //视频停止
{
CWBObject *pObj = g_pWBPage->FindByLayerIndex(m_dwMenuLayerIndex);
if (pObj == NULL)
{
break;
}
WB_OBJ_TYPE ntemptype = (WB_OBJ_TYPE)pObj->GetType();
if (ntemptype == WB_OBJ_FLASH) //如果对象是flash
{
((CWBFlash *)pObj)->Stop();
}
if (ntemptype == WB_OBJ_MEDIA)
{
if (((CWBMedia*)pObj)->IsActiveCreated())
{
((CWBMedia*)pObj)->MediaStop();
}
else
{
((CWBMedia*)pObj)->SetMediaPlayState(Media_stop);
}
}
Invalidate();
//发送同步信息
XMemIni xmlObj;
pObj->SetXmlValue(xmlObj);
if (ntemptype == WB_OBJ_MEDIA || ntemptype == WB_OBJ_FLASH)
{
xmlObj.Set(KEY_MEDIA_OPERATION, WB_MOVIE_STOP);
}
g_pWhiteBoardView->ChangeObj(xmlObj);
}
break;
case ID_OBMENU_MOVIE_PAUSE: //视频暂停
.
.
.
}
}
.rc文件
IDB_BITMAP_EMPTY_MENU_ITEM BITMAP "res\\image\\EmptyMenuItem.bmp"
IDB_OBMENU_MOVIE_PALY BITMAP "res\\image\\Menu\\IDB_OBMENU_MOVIE_PALY.bmp"
IDB_OBMENU_MOVIE_PAUSE BITMAP "res\\image\\Menu\\IDB_OBMENU_MOVIE_PAUSE.bmp"
IDB_OBMENU_MOVIE_STOP BITMAP "res\\image\\Menu\\IDB_OBMENU_MOVIE_STOP.bmp"
IDB_OBMENU_MOVIE_CIRCLE BITMAP "res\\image\\Menu\\IDB_OBMENU_MOVIE_CIRCLE.bmp"