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

| |
[不指定 2019/07/15 13:49 | by admin ]
1、演示在VB菜单中加入图标的方法,使用了三个VB6.0 WINAPI函数,利用这三个函数,我们可以对菜单进行定义。

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&

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


Private Sub Form_Load()
    Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
    mHandle = GetMenu(hwnd)
    sHandle = GetSubMenu(mHandle, 0) '这里为第一个菜单栏
    lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Image1.Picture, Image1.Picture)
    sHandle = GetSubMenu(mHandle, 1) '这里为第二个菜单栏
    lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Image2.Picture, Image2.Picture)
    sHandle2 = GetSubMenu(sHandle, 0) '将次级菜单中的第1项加上图片,也就是说菜单下的子菜单下面的再一个子菜单图
    lRet = SetMenuItemBitmaps(sHandle2, 0, MF_BYPOSITION, Image3.Picture, Image3.Picture)
    End Sub
程序源码 | 评论(0) | 引用(0) | 阅读(219)