Results 1 to 8 of 8

Thread: Icons in menu

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    South Africa, Bloemfontein, Free State
    Posts
    30

    Angry Icons in menu

    Hi, I need to know if there is a way to put an icon next to a menu option you create in vb's menu editor. So if I click on my program's file menu it will give me a drop-down with all the options an beside each option an icon.

    Is there a way to do this or am I mad to do something like this???

    Thanks in advance.

  2. #2
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Yes, its quite simple to put an icon next to a menu item.

    Here is but one of many many examples.

    VB Code:
    1. 'Download the full source+pictures+.. at [url]http://www.allapi.net/php/dlman/dm.cgi?id=bitmenu.zip&action=download[/url]
    2. Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
    3. Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    4. Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    5. Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
    6. Const MF_BITMAP = 4
    7. Const MF_CHECKED = 8
    8. Private Sub Form_Load()
    9.     'KPD-Team 1998
    10.     'URL: [url]http://www.allapi.net/[/url]
    11.     'E-Mail: [email][email protected][/email]
    12.     Dim hMenu As Long, hSubMenu As Long, lngID As Long
    13.  
    14.     'Get the handle of the form's menu
    15.     hMenu = GetMenu(Me.hWnd)
    16.     'Get the handle of the form's submenu
    17.     hSubMenu = GetSubMenu(hMenu, 0)
    18.  
    19.     'Change first item (index=0)
    20.     picBitmaps(0).Picture = picBitmaps(0).Image
    21.     lngID = GetMenuItemID(hSubMenu, 0)
    22.     Call ModifyMenu(hMenu, lngID, MF_BITMAP, lngID, CLng(picBitmaps(0).Picture))
    23.  
    24.     'Change second item (index=1)
    25.     picBitmaps(1).Picture = picBitmaps(1).Image
    26.     lngID = GetMenuItemID(hSubMenu, 1)
    27.     Call ModifyMenu(hMenu, lngID, MF_BITMAP, lngID, CLng(picBitmaps(1).Picture))
    28.  
    29.     'Change third item (index=2)
    30.     picBitmaps(2).Picture = picBitmaps(2).Image
    31.     lngID = GetMenuItemID(hSubMenu, 2)
    32.     Call ModifyMenu(hMenu, lngID, MF_BITMAP, lngID, CLng(picBitmaps(2).Picture))
    33.  
    34.     mnuBitmap1.Checked = True
    35. End Sub
    36. Private Sub mnuBitmap1_Click()
    37.     mnuBitmap1.Checked = Not mnuBitmap1.Checked
    38. End Sub
    39. Private Sub mnuBitmapEnd_Click()
    40.     End
    41. End Sub
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    South Africa, Bloemfontein, Free State
    Posts
    30
    Hi Arc thanks for your help.

    SeeYa
    Templar

  4. #4
    Lively Member
    Join Date
    Feb 2002
    Posts
    77
    I tried out the code and found out that it can only put icon and not Caption name + Icon. Can i know this problem is due to what reason ????

    Help is really appreciated...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    South Africa, Bloemfontein, Free State
    Posts
    30
    Hi Winsonlee, haven't tried the code out yet but will let you know the moment i do and i will see if i can find out how to create an icon+caption.

    SeeYa
    Templar

  6. #6
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    I was having the same problem last week and finally got it licked. When I used one example I would have an image but not text. I finally found something that worked so that the image would be there along with the text. It would only use bitmaps though. Icons didn't work for some reason.

    Anyway, now I can't find what I did with it. I spent the better part of today wiping out a virus and I think I lost that page. When I find it again, if you still don't have an answer I'll post it here for you.

  7. #7
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Found it

    I had to download the code again. I just checked it out and it is the code that has both bitmaps and text in the menu. I got it from www.vbcode.com. The zip file is attached intact as it was downloaded.
    Attached Files Attached Files

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2002
    Location
    South Africa, Bloemfontein, Free State
    Posts
    30

    Wink

    Thanks cafeenman for all your effort and help.

    Templar

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