Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitlePut text with a color background in menus
DescriptionThis example shows how to put text with a color background in menus in Visual Basic 6.
Keywordsmenu, font, colored menu, ModifyMenu
CategoriesGraphics, Controls, API
 
Thanks to Sergio Perciballi.

This program makes bitmaps containing text with colored backgrounds. It then uses the ModifyMenu API function to make the menu items display the bitmaps.

This program uses the technique to display color values with corresponding background colors. For example, FF (red) with a red background, CBC6C3 (light gray) with a light gray background, etc.

 
Sub ChangeToBitmap(TopLevel As Integer, SubLevel As Integer)
    Dim x
    Static lastmenu
    Dim himage As Long
    Dim chWnd As Integer     ' Handle to the Microsoft
        ' Access window.
    Dim hmenutop As Integer  ' Handle to the Microsoft
        ' Access menu.
    Dim hsubmenu As Integer  ' Handle to the sub menu.
    Dim ItemID As Long    ' Ordinal position of menu item.
    'this doesn't seem to be needed;oigres P
    ' If the form is maximized, the system menu is added to
    ' the forms
    ' menu bar, so increment the actual TopLevel value by
    ' one.
'    If (IsZoomed(Screen.ActiveForm.hwnd)) Then
'        TopLevel = TopLevel + 1
'    End If

    ' Assign the menu handles so the API
    ' can find the items we are referring to...
    chWnd = FindWindow("ThunderFormDC", Form1.Caption)
    
    hmenutop = GetMenu(chWnd)
    'Get Colour menu; File=0,Colour=1
    hsubmenu = GetSubMenu(hmenutop, TopLevel + 1) _
        'File,Colour
    ''ItemID = GetMenuItemID(hsubmenu, 0)
   
    Picture1(0).Print Hex$(Picture1(0).BackColor)
    'assign persistent bitmap to picture
    Picture1(0).Picture = Picture1(0).Image
    'get handle of pictures and put in menu
    For x = 0 To 9
        himage = Picture1(x).Picture
        ItemID = GetMenuItemID(hsubmenu, x)
        ModifyMenu hsubmenu, x, MF_BITMAP Or MF_BYPOSITION, _
            ItemID, himage
    Next x
    
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated