Create pictures for Menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuragshrivastava64
    New Member
    • Jan 2007
    • 66

    Create pictures for Menu

    Hi, All
    Is it possible to add icons in place of menu names in Menu Editor or any other way
  • gobblegob
    New Member
    • Dec 2007
    • 133

    #2
    Originally posted by anuragshrivasta va64
    Hi, All
    Is it possible to add icons in place of menu names in Menu Editor or any other way
    Hi anuragshrivasta va,
    Give this a try.

    this is for VB6

    Add a new Module (default name)

    Add this code:

    Code:
    Option Explicit
    
    Public Const MF_BITMAP = &H4&
    Public Const MIIM_ID = &H2
    Public Const MIIM_TYPE = &H10
    Public Const MFT_STRING = &H0&
    
    Public 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
    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
    =============== =============== =============== ==========

    On the Form add these menu's.....
    mnuFile
    mnuOpen
    mnuSave

    also add 3 pictureboxes ( 1 and 2 with the pictures you want in the menu, 3 left blank) and set properties Visible = False


    CODE: VB 6

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    On Error GoTo err
        Dim hMenu As Long, hSubmenu As Long
        Dim hID As Long
        
        Me.Hide
        
        'Get the menuhandle of your app
        hMenu = GetMenu(Me.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
        'You can add two bitmaps to a menuentry
        'One for the checked and one for the unchecked
        'state.
        SetMenuItemBitmaps hMenu, hID, MF_BITMAP, Me.Picture1.Picture, Me.Picture2.Picture
        
        ' repop the picture box
        Set Me.Picture3.Picture = LoadPicture(App.Path & "\lake.bmp")
        
        ' do the next submenu
        hID = GetMenuItemID(hSubmenu, 1)
        
        ' add the bitmap
        SetMenuItemBitmaps hMenu, hID, MF_BITMAP, Me.Picture3.Picture, Me.Picture3.Picture
        
        Me.Show
        Exit Sub
    err:
        err.Clear
        Me.Show
    End Sub

    Let us know if you have any luck with this.
    GobbleGob.

    Comment

    • anuragshrivastava64
      New Member
      • Jan 2007
      • 66

      #3
      Sorry sir but is there anything else i've to do
      Its not working at all

      Comment

      • gobblegob
        New Member
        • Dec 2007
        • 133

        #4
        Originally posted by anuragshrivasta va64
        Sorry sir but is there anything else i've to do
        Its not working at all
        What errors you getting?

        Comment

        • jamesd0142
          Contributor
          • Sep 2007
          • 471

          #5
          I tried out an idea and it might help...

          Use a toolstrip and dock it to the top of your form, add a button to the toolstrip and change the image... works for me...

          JAmes

          Comment

          Working...