Results 1 to 6 of 6

Thread: Adding icons to Menus????

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    Scotland, UK
    Posts
    68

    Question Adding icons to Menus????

    Morning everyone,

    Does anyone know how to add icons to menus? I have tried using the 'Adding Bitmaps to Menus' example on VB World but I could only get a bitmap image to appear next to the first item on my form menu.

    My form menu structure is as follows:

    File: New, Open, Close, Exit
    Edit: Cut, Copy, Paste

    What I need to do is add icons to the 'New, Open, Exit' items under the file menu and to 'Cut, Copy & Paste' under the edit menu.

    The code I am using at the moment is the code from vb world:

    The code below is in a code module
    Code:
    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&
    The code below is in a Form
    Code:
    hMenu& = GetMenu(Form1.hwnd)
    hSubMenu& = GetSubMenu(hMenu&, 0)
    hID& = GetMenuItemID(hSubMenu&, 0)
    SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
    Picture1.Picture, Picture1.Picture
    Thanks in advance for any help,

    Xan

  2. #2
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Try the control on VbSmart. There is alsoa tutorial on how to use the control and an example app which uses it.

    Hopethishelpsyou

  3. #3
    khalik
    Guest
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetMenu Lib "user32" _
    4.    (ByVal hwnd As Long) As Long
    5.  
    6. Private Declare Function GetSubMenu Lib "user32" _
    7.    (ByVal hMenu As Long, ByVal nPos As Long) As Long
    8.  
    9. Private Declare Function SetMenuItemBitmaps Lib "user32" _
    10.    (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
    11.     ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
    12.  
    13. Const MF_BYPOSITION = &H400&
    14.  
    15. Private Sub Form_Load()
    16.  
    17. Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
    18.     mHandle = GetMenu(Me.hwnd)
    19.     sHandle = GetSubMenu(mHandle, 0)
    20.     '--NEW
    21.     I1.Picture = imlToolbarIcons.ListImages(1).Picture
    22.     lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, I1.Picture, I1.Picture)
    23.     '--VIEW
    24.     I1.Picture = imlToolbarIcons.ListImages(2).Picture
    25.     lRet = SetMenuItemBitmaps(sHandle, 1, MF_BYPOSITION, I1.Picture, I1.Picture)
    26.     '--DELETE
    27.     I1.Picture = imlToolbarIcons.ListImages(3).Picture
    28.     lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, I1.Picture, I1.Picture)
    29.     '--SAVE
    30.     I1.Picture = imlToolbarIcons.ListImages(4).Picture
    31.     lRet = SetMenuItemBitmaps(sHandle, 3, MF_BYPOSITION, I1.Picture, I1.Picture)
    32.     '--PRINT
    33.     I1.Picture = imlToolbarIcons.ListImages(5).Picture
    34.     lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, I1.Picture, I1.Picture)
    35.     '--CLEAR
    36.     I1.Picture = imlToolbarIcons.ListImages(6).Picture
    37.     lRet = SetMenuItemBitmaps(sHandle, 5, MF_BYPOSITION, I1.Picture, I1.Picture)
    38.     '--CLOSE
    39.     I1.Picture = imlToolbarIcons.ListImages(7).Picture
    40.     lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, I1.Picture, I1.Picture)
    41.  
    42.  
    43.  
    44. End Sub


    imlToolbarIcons.ListImages(7).Picture
    is imagelist attached to toolbar...

    u can use picture1.picture

  4. #4
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Oh and to post code, use [vbcode] [/vbcode] tags instead of the code tags to give the color formating

  5. #5
    khalik
    Guest
    thanks

  6. #6
    Lively Member The Hand's Avatar
    Join Date
    Jun 2001
    Posts
    88

    Post

    There is also a full-source module you can add in, found here. It works for single window apps, MDI, and toolbar buttonmenus.
    Visit EliteVB for slimy subclassing tricks and GDI32 goodness.

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