How to change the color of one menu item RRS feed

  • Question

  • I have the code that once you click on the button it changes the color of the main menu or sub menu. Does anyone know if tt's possible to change the color of a specific one menu ?

    Private Const MIM_BACKGROUND As Long = &H2
    Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
    Private Type MENUINFO
    cbSize As Long
    fMask As Long
    dwStyle As Long
    cyMax As Long
    hbrBack As Long
    dwContextHelpID As Long
    dwMenuData As Long
    End Type

    Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
    Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long


    Private Sub Command1_Click()

    Dim mi As MENUINFO

    With mi
    .cbSize = Len(mi)
    .hbrBack = CreateSolidBrush(vbRed)
    SetMenuInfo GetMenu(Me.hWnd), mi   'main menu bar
    .hbrBack = CreateSolidBrush(vbCyan)
    SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 0), mi 'File menu (item 0)
    .hbrBack = CreateSolidBrush(vbBlue)
    SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 1), mi 'Edit menu (item 1)
    .hbrBack = CreateSolidBrush(vbRed)
    SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 2), mi 'Select menu (item 2)
    End With
    DrawMenuBar Me.hWnd
    End Sub




    • Moved by Calvin_Gao Tuesday, February 8, 2011 2:48 AM VB6 is off topic (From:Visual Basic General)
    Monday, January 31, 2011 2:58 PM

All replies