VC++如何给鼠标右键菜单 添加图标?

用普通的菜单方式加不了图标... 用普通的菜单方式 加不了图标 展开
 我来答
匿名用户
2013-06-07
展开全部
你好:利用SetMenuItemBitmaps这个函数可以做到 void CPopupMenuDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CMenu menu;//菜单
CMenu* pPopupMenu;//菜单指针
CBitmap m_bitmap1;//位图

menu.LoadMenu(IDR_MENU1);//加载ID为IDR_MENU1的菜单
m_bitmap1.LoadBitmap(IDB_BITMAP1);//加载ID为IDB_BITMAP1的位图 pPopupMenu = menu.GetSubMenu(0); //获取弹出菜单的第一层子菜单的类指针//为菜单的第一和第三项设置图标
pPopupMenu->SetMenuItemBitmaps(0,MF_BYPOSITION,&m_bitmap1,&m_bitmap1);
pPopupMenu->SetMenuItemBitmaps(2,MF_BYPOSITION,&m_bitmap1,&m_bitmap1); ClientToScreen(&point);//将鼠标单击处的坐标转换为屏幕坐标//弹出菜单函数,第一个参数表示快捷菜单的下边界与由参数y指定的坐标对齐 //第二和第三个为x、y坐标,第四个表示拥有此菜单的窗口句柄,//第五个默认为NULL,表示当用户在菜单以外的区域按鼠标键时,菜单会消失pPopupMenu->TrackPopupMenu(TPM_BOTTOMALIGN,point.x,point.y,this,NULL); CDialog::OnLButtonDown(nFlags, point);
} 实例连接是:http://www.cnblogs.com/anhuizhxd/archive/2009/06/20/cpopupmenu.html
匿名用户
2013-06-07
展开全部
编辑有关控件或者窗体的popupmenu属性
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2015-08-03
展开全部
参考例子如下,相关的解释已经在代码中标注;
Private Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
Const MF_BYPOSITION = &H400&
‘因为窗体鼠标右键上的菜单,在菜单编辑器中是隐藏的,获取不到句柄。

Private Sub Form_Load()

' --- 自定义图标-开始
Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
' 取得菜单的句柄并赋值给mHandle
mHandle = GetMenu(hwnd)
' 取得mHandle句柄所指菜单的第一个出式菜单的句柄并赋值给sHandle
sHandle = GetSubMenu(mHandle, 0)
' 将弹出式菜单的第一个弹出式菜单(0/2/4/6/8)加上图片, 跳过1/3/5/7, 因为是分隔线
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Image1.Picture, Image1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Image2.Picture, Image2.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, Image3.Picture, Image3.Picture)
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, Image4.Picture, Image4.Picture)
lRet = SetMenuItemBitmaps(sHandle, 8, MF_BYPOSITION, Image5.Picture, Image5.Picture)

' 取得mHandle句柄所指菜单的第二个弹出式菜单的句柄并赋值给sHandle
sHandle = GetSubMenu(mHandle, 1)
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, ImageA.Picture, ImageA.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, ImageB.Picture, ImageB.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, ImageC.Picture, ImageC.Picture)
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, ImageD.Picture, ImageD.Picture)
lRet = SetMenuItemBitmaps(sHandle, 8, MF_BYPOSITION, ImageE.Picture, ImageE.Picture)

' 取得mHandle句柄所指菜单的第三个弹出式菜单的句柄并赋值给sHandle
sHandle = GetSubMenu(mHandle, 2)
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Pic1.Picture, Pic1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Pic2.Picture, Pic2.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, Pic3.Picture, Pic3.Picture)
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, Pic4.Picture, Pic4.Picture)
lRet = SetMenuItemBitmaps(sHandle, 8, MF_BYPOSITION, Pic5.Picture, Pic5.Picture)

sHandle = GetSubMenu(mHandle, 3) '以下两个是定义托盘的两个按钮图标---未起作用
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Pic1.Picture, Pic1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Pic2.Picture, Pic2.Picture)

sHandle = GetSubMenu(mHandle, 4) '以下两个是定义窗体鼠标右键的三个按钮图标---未起作用
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Pic1.Picture, Pic1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Pic2.Picture, Pic2.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, Pic3.Picture, Pic3.Picture)

' --- 自定义图标-结束

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式