Results 1 to 4 of 4

Thread: Change colour of menu item

  1. #1

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233

    Change colour of menu item

    Hello,

    In VB6 I have a normal form with a menu on it (created with the menu editor).

    This works fine so no problem there.

    What I want to do is change the colour of the text or background of a specific menu item (depending on some checks I perform)

    So imagine I have the following menu structure:

    <File><New><Blank>


    Now if the user has no rights to create a new file, I want the <New> tag to have a red background colour or the text in red.

    Invisible or disabled are not an option because the user must be able to click it anyway (he has to be prompted with a message or so after clicking an 'invalid' menu item)

    How can I do this with a normal menu?
    If ot is not possible, are there other components I can use?

    Thanks for your time and your help!

    Christophe
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Here you go!

    VB Code:
    1. Option Explicit
    2.  
    3. Private Enum MENUINFO_STYLES
    4.     MNS_NOCHECK = &H80000000
    5.     MNS_MODELESS = &H40000000
    6.     MNS_DRAGDROP = &H20000000
    7.     MNS_AUTODISMISS = &H10000000
    8.     MNS_NOTIFYBYPOS = &H8000000
    9.     MNS_CHECKORBMP = &H4000000
    10. End Enum
    11.  
    12. Private Enum MENUINFO_MASKS
    13.     MIM_MAXHEIGHT = &H1
    14.     MIM_BACKGROUND = &H2
    15.     MIM_HELPID = &H4
    16.     MIM_MENUDATA = &H8
    17.     MIM_STYLE = &H10
    18.     MIM_APPLYTOSUBMENUS = &H80000000
    19. End Enum
    20.  
    21. Private Type MENUINFO
    22.     cbSize As Long
    23.     fMask As MENUINFO_MASKS
    24.     dwStyle As MENUINFO_STYLES
    25.     cyMax As Long
    26.     hbrBack As Long
    27.     dwContextHelpID As Long
    28.     dwMenuData As Long
    29. End Type
    30.  
    31. Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
    32. Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
    33. Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    34. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    35.  
    36. Private Sub Form_Load()
    37.    
    38.     Dim MyMenu As MENUINFO
    39.    
    40.     MyMenu.cbSize = Len(MyMenu)
    41.     MyMenu.fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
    42.     MyMenu.hbrBack = CreateSolidBrush(vbRed)
    43.     SetMenuInfo GetMenu(Me.hwnd), MyMenu
    44.    
    45. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Addicted Member chrisvl's Avatar
    Join Date
    Jul 2001
    Location
    Belgium - Somewhere between the bedroom and the toilet...or at work playing Oracle DBA :-)
    Posts
    233
    Thanks!

    But now my entire menu is in red

    How can you specify one specific item???
    I do not have a specific statement...
    so I will use one of my wife

    Veni, Vidi, Visa ... I came, I saw, I shopped

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Sorry, I don't know how...


    Has someone helped you? Then you can Rate their helpful post.

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