跳到主要内容

VB6在窗体菜单中加入图标源码

·

1、演示在VB菜单中加入图标的方法,使用了三个VB6.0 WINAPI函数,利用这三个函数,我们可以对菜单进行定义。

1Option Explicit
2Private Declare Function GetMenu Lib "user32" _
3   (ByVal hwnd As Long) As Long
4Private Declare Function GetSubMenu Lib "user32" _
5   (ByVal hMenu As Long, ByVal nPos As Long) As Long
6Private Declare Function SetMenuItemBitmaps Lib "user32" _
7   (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
8    ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
9Const MF_BYPOSITION = &H400&

2、以下为启动窗体代码,Image为加载图片,图片为ico格式,大小为16*16过大会影响软件的美观。

 1Private Sub Form_Load()
 2    Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
 3    mHandle = GetMenu(hwnd)
 4    sHandle = GetSubMenu(mHandle, 0) '这里为第一个菜单栏
 5    lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Image1.Picture, Image1.Picture) 
 6    sHandle = GetSubMenu(mHandle, 1) '这里为第二个菜单栏
 7    lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Image2.Picture, Image2.Picture) 
 8    sHandle2 = GetSubMenu(sHandle, 0) '将次级菜单中的第1项加上图片,也就是说菜单下的子菜单下面的再一个子菜单图
 9    lRet = SetMenuItemBitmaps(sHandle2, 0, MF_BYPOSITION, Image3.Picture, Image3.Picture)
10    End Sub
白日映照满天星
作者
白日映照满天星
订阅我频道让你站在上帝角度观察视野! QQ:3925993 有尝解决技术问题【备注你的问题】 🐑

阅读量:评论:
赞赏码图