VB中API菜單編輯器的實現

时间:2010-01-28 13:49:46  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: As Long    Declare Function GetSubMenu Lib "user32" _    (ByVal hMenu As Long, ByVal nPos As Long) As Long    Declare Function GetMenuItemID Lib "user32" _    (ByVal hMenu As Long, ByVal nPos As Long) As Long   &nb...
  正文:

下面的这段代码将Picture1的图形作为菜单项。
    首先建立一个模块,并加入下面的语句。
    Declare Function GetMenu Lib "user32" _
    (ByVal hwnd As Long) As Long
    Declare Function GetSubMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Declare Function GetMenuItemID Lib "user32" _
    (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Declare Function SetMenuItemBitmaphotoshop/ target=_blank class=infotextkey>ps Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, _
    ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, _
    ByVal hBitmapChecked As Long) As Long

    Public Const MF_BITMAP = &H4&

    Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
    End Type

    Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long
    Declare Function GetMenuItemInfo Lib "user32" _
    Alias "GetMenuItemInfoA" (ByVal hMenu As Long, _
    ByVal un As Long, ByVal b As Boolean, _
    lpMenuItemInfo As MENUITEMINFO) As Boolean

    Public Const MIIM_ID = &H2
    Public Const MIIM_TYPE = &H10
    Public Const MFT_STRING = &H0&

form1中 ```


   Private Sub Form1_load()

    ' 获得你的菜单的句柄
    hMenu& = GetMenu(Form1.hwnd)

    ' 获得第一个子菜单的句柄
    hSubMenu& = GetSubMenu(hMenu&, 0)

    ' 获得第一个菜单项
    hID& = GetMenuItemID(hSubMenu&, 0)

    '加入位图

    SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
    Picture1.Picture, _
    Picture1.Picture
    End Sub
    上面的代码使菜单项为图片,如果你只希望菜单项的左边有一个小位图,而右边仍为文字。可以先在Picture1绘制图片,在利用Picture1.Print加上文字,然后用Picture1.Picture加入菜单项。

Option Explicit
'【vb声明】
'  Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long

'【说明】
'  取得窗口中一个菜单的句柄

'【返回值】
'  Long,依附于指定窗口的一个菜单的句柄(如果有菜单);否则返回零

'【参数表】
'  hwnd -----------  Long,窗口句柄。对于vb,这应该是一个窗体句柄。注意可能不是子窗口的句柄
Private Declare Function GetMenu Lib "user32" _
   (ByVal hwnd As Long) As Long
'-------------------------------------------------
'【VB声明】
'  Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

'【说明】
'  取得一个弹出式菜单的句柄,它位于菜单中指定的位置

'【返回值】
'  Long,位于指定位置的弹出式菜单的句柄(如果有的话);否则返回零
"VB中API菜單編輯器的實現"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/VB/12562.html


关键字:

关于《VB中API菜單編輯器的實現》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td