Results 1 to 2 of 2

Thread: menu

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    how do you put icons with the menu items

    eg:just like the File -> Open Project menu of vb or File -> Save Project menu

  2. #2
    Junior Member
    Join Date
    Nov 1999
    Location
    chennai,tamilnadu,india
    Posts
    18

    Post

    Hi,

    Try using this Api.

    Add the following code to the declarations section of a module:
    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 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

    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&

    Code

     Add one form to the project.
     Add a picturebox (Autosize = True) with a bitmap (not an icon!!!), max. 13X13
     Add a commandbutton with following code:
    Private Sub Command1_Click()

    'Get the menuhandle of your app
    hMenu& = GetMenu(Form1.hwnd)

    'Get the handle of the first submenu (Hello)
    hSubMenu& = GetSubMenu(hMenu&, 0)

    'Get the menuId of the first entry (Bitmap)
    hID& = GetMenuItemID(hSubMenu&, 0)

    'Add the bitmap

    SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
    Picture1.Picture, _
    Picture1.Picture
    'You can add two bitmaps to a menuentry
    'One for the checked and one for the unchecked
    'state.

    End Sub
     Run the Project and click the button.

    I hope this would help.

    bye....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width