如何创建含有位图的菜单项

gougou2 2003-05-12 09:09:50

就是在在菜单项中加入位图图形
...全文
7 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dongyoushen 2003-05-12
Me too... UP
回复
固执的大叔 2003-05-12
来迟了!UP!
回复
LoveBH 2003-05-12
创建位图菜单其实非常简单,可以使用API函数SetMenuItemBitmaps来为菜单项添加位图。调用该函数时需要用到弹出菜单的句柄,以及要添加的位图。

弹出菜单的句柄可以使用API函数GetMenu与GetSubMenu来获得。位图则可以通过在窗体上放置图像框控件来提供。



Option Explicit


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, sHandle1 As Long
'获得菜单的句柄
mHandle = GetMenu(hwnd)
'获得“文件”菜单的句柄
sHandle = GetSubMenu(mHandle, 0)
'为“打开”菜单项添加位图
lRet = SetMenuItemBitmaps _
(sHandle, 0, MF_BYPOSITION, imOpen.Picture.Handle, imOpen.Picture.Handle)
'为“保存”菜单项添加位图
lRet = SetMenuItemBitmaps _
(sHandle, 1, MF_BYPOSITION, imSave.Picture, imSave.Picture)
'为“打印”菜单项添加位图
lRet = SetMenuItemBitmaps _
(sHandle, 3, MF_BYPOSITION, imPrint.Picture, imPrint.Picture)
'获得“其他”菜单的句柄
sHandle = GetSubMenu(mHandle, 1)
'获得“帮助”子菜单的句柄
sHandle1 = GetSubMenu(sHandle, 0)
'为“内容”菜单项添加位图
lRet = SetMenuItemBitmaps _
(sHandle1, 0, MF_BYPOSITION, imContent.Picture, imContent.Picture)
End Sub


欢迎光临电脑爱好者论坛 bbs.cfanclub.net
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-12 09:09
社区公告
暂无公告