PDA

Click to See Complete Forum and Search --> : Change the menu color in VB?


July
June 30th, 2002, 12:24 AM
Ok this is probably gonna sound really dumb and all. But That app I was talking about earlier I kind of want it to be white instead of that ugly greyish color. I can change the bgcolor ok, but how do I change the menu and the submenus? I atttached a little visual so you can see what I'm talking about. Yes I'm into VW's by the way and neuspeed... hehe.

jethro
June 30th, 2002, 12:30 AM
I *think*, that it's up to the user running the application.
I'm probably wrong, but I don't think you *can* change that colour...

July
June 30th, 2002, 12:44 AM
Maybe just doing images instead of the standard menu. Cause I could see that happening just by using the onclick() event for the picture. But I thought I might ask before I go off making images for a menu system.

hurt-conveyor
June 30th, 2002, 05:40 AM
well, there are a couple of ways...one way to go is to go download some type of 3rd party menu component that allows you to change that property. You could also create your own visual menu or do some subclassing (which would be quite difficult)

vbgamer45
June 30th, 2002, 06:30 AM
I have a code example on my website in which you can change the color of the menus and the font in VB. You can download it at http://www.homestead.com/vbgames6/files/dos-menu.zip

s0nIc
June 30th, 2002, 02:02 PM
i thought those menues and submenues are dynamically linked to the Desktop Properties of the end user..

jethro
June 30th, 2002, 03:41 PM
Yeah, that's what I thought as well. I have experience in the Windows API with C++ but not with VB, so maybe the setup is different...

Originally posted here (http://www.AntiOnline.com/showthread.php?threadid=#post) by s0nIc
i thought those menues and submenues are dynamically linked to the Desktop Properties of the end user..

vbgamer45
June 30th, 2002, 04:03 PM
July here is the code to make the menu bar white:
Using the sample i had in my previous post.
'Change Public Const COLOR_MENU =4 to Public Const COLOR_MENU = 9

Public Const COLOR_MENU = 9
'17 grey
'9 white
'8 BLACK
'4 normal
'2 dark blue
'1 light blue

July
June 30th, 2002, 06:09 PM
vbgamer Nice site. I was lookin at how much code samples you have. I could spend alot of time there. hehe.. I'm still not sure how I would get the menu to change using your code. Could you give me a dummy's guide how to?

vbgamer45
July 1st, 2002, 12:41 AM
Here you go July. I have done so of the work for you using the menus from program.gif. I have also included a text on how to add more menus to it and changing the color. To change the Font and the highlight color search in modmenu.bas and you should be able to do it.

vbgamer45
July 20th, 2002, 06:59 PM
I was searching today and I found a way that is alot easier.


Option Explicit

'******************************************************************************
'Required API call declarations
'******************************************************************************

'CreateBrushIndirect is used to create the background brush for the menus
Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long
'GetMenu is used to get the handle to the menus
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
'GetMenuInfo is used to get the current info for the menu (so we don't change anything we shouldn't by mistake)
Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As tagMENUINFO) As Long
'SetMenuInfo is used to set the background brush back to the menu and all sub-menus
Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As tagMENUINFO) As Long

'******************************************************************************
'Required API Type Definitions
'******************************************************************************

'Used in the Calls to CreateBrushIndirect
Private Type LOGBRUSH
lbStyle As Long 'Style type (we only need to create a solid background for this example)
lbColor As Long 'Set the color of the brush
lbHatch As Long 'Hatch style (not used in this example because it's ignored for Solid style)
End Type

'Used in GetMenuInfo and SetMenuInfo calls
Private Type tagMENUINFO
cbSize As Long 'The size of the type structure (use len to calculate)
fMask As Long 'Mask of information/Actions to process
dwStyle As Long 'Menu Style (not used in this example)
cyMax As Long 'Maximum height of menu in pixels (not used in this example)
hbrBack As Long 'Handle to background brush
dwContextHelpID As Long 'Help Context ID (not used in this example)
dwMenuData As Long 'Menu Data (again not used in this example)
End Type

'******************************************************************************
'API Constant declarations
'******************************************************************************

Private Const BS_SOLID = 0 'Solid style for brush
Private Const MIM_APPLYTOSUBMENUS = &H80000000 'Apply to Sub-Menus Mask
Private Const MIM_BACKGROUND = &H2 'Background Mask

Private Sub Form_Load()
Dim ret As Long 'Variable to hold return values from GetMenuInfo and SetMenuInfo
Dim hMenu As Long 'Variable to hold the handle to the menu
Dim hBrush As Long 'Variable to hold the handle to the background brush we are going to create
Dim lbBrushInfo As LOGBRUSH 'Variable to hold the information to pass to the CreateBrushIndirect API
Dim miMenuInfo As tagMENUINFO 'Variable to hold the menu info

lbBrushInfo.lbStyle = BS_SOLID 'Set our brush type to solid
lbBrushInfo.lbColor = vbWhite 'Here we set our brush color
lbBrushInfo.lbHatch = 0 'This value is ignored I set it to 0 to make sure nothing weird will happen
hBrush = CreateBrushIndirect(lbBrushInfo) 'We create our brush
hMenu = GetMenu(Me.hwnd) 'Get the handle to the menu that we are modifying (note we pass the form's hWnd because it is the owner of the menu)
miMenuInfo.cbSize = Len(miMenuInfo) 'Set the MenuInfo structure size so that we don't get errors
ret = GetMenuInfo(hMenu, miMenuInfo) 'Go and get the actual menu info should return non-zero if successful
miMenuInfo.fMask = MIM_APPLYTOSUBMENUS Or MIM_BACKGROUND 'Set the mask for the changes (changing the background for menu and all sub-menus)
miMenuInfo.hbrBack = hBrush 'Assign our brush to the menu info
ret = SetMenuInfo(hMenu, miMenuInfo) 'Write our info back to the menu and we're done. (should return non-zero if successful)
End Sub