Mar 26th, 2003, 10:46 PM
#1
Thread Starter
Member
Change the color of the menu bar,tool bar,status bar?
hi,i have a quick question:
how can i change the color of the menu bar,status bar,tool bar
to a custom color?
another question: how can i control the close button in the
control box (top right) ?
thnx anyway
Mar 27th, 2003, 12:04 AM
#2
Lively Member
Well for menu color, you can accompish it by using APIs. Try this:
VB Code:
Option Explicit
Private Enum MENUINFO_STYLES
MNS_NOCHECK = &H80000000
MNS_MODELESS = &H40000000
MNS_DRAGDROP = &H20000000
MNS_AUTODISMISS = &H10000000
MNS_NOTIFYBYPOS = &H8000000
MNS_CHECKORBMP = &H4000000
End Enum
Private Enum MENUINFO_MASKS
MIM_MAXHEIGHT = &H1
MIM_BACKGROUND = &H2
MIM_HELPID = &H4
MIM_MENUDATA = &H8
MIM_STYLE = &H10
MIM_APPLYTOSUBMENUS = &H80000000
End Enum
Private Type MENUINFO
cbSize As Long
fMask As MENUINFO_MASKS
dwStyle As MENUINFO_STYLES
cyMax As Long
hbrBack As Long
dwContextHelpID As Long
dwMenuData As Long
End Type
Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Sub Form_Load()
Dim MyMenu As MENUINFO
MyMenu.cbSize = Len(MyMenu)
MyMenu.fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
MyMenu.hbrBack = CreateSolidBrush(vbWhite)
SetMenuInfo GetMenu(Me.hwnd), MyMenu
End Sub
You can also do this to set the menu color:
add this to a module
VB Code:
Private Declare Function GetMenuInfo Lib "user32" _
(ByVal hMenu As Long, _
mi As MENUINFO) As Long
Private Declare Function SetMenuInfo Lib "user32" _
(ByVal hMenu As Long, _
mi As MENUINFO) As Long
Private Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" _
(ByVal crColor As Long) As Long
Private Type MENUINFO
cbSize As Long
fMask As MENUINFO_MASKS
dwStyle As Long
cyMax As Long
hbrBack As Long
dwContextHelpID As Long
dwMenuData As Long
End Type
Private Enum MENUINFO_MASKS
MIM_MAXHEIGHT = &H1
MIM_BACKGROUND = &H2
MIM_HELPID = &H4
MIM_MENUDATA = &H8
MIM_STYLE = &H10
MIM_APPLYTOSUBMENUS = &H80000000
End Enum
Public Sub SetMenuColor(frm As Form, _
ByVal MenuColor As Long, _
Optional ByVal ApplyToSubMenus As Boolean = True)
Dim vMenuInfo As MENUINFO
Dim vMenuInfoMask As Long
If ApplyToSubMenus Then
vMenuInfoMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
Else
vMenuInfoMask = MIM_BACKGROUND
End If
With vMenuInfo
.cbSize = Len(vMenuInfo)
.fMask = vMenuInfoMask
.hbrBack = CreateSolidBrush(MenuColor)
SetMenuInfo GetMenu(frm.hwnd), vMenuInfo
End With
End Sub
Then create a form with a menu and either in the form_load event or in a button or whatever put
VB Code:
SetMenuColor Me, RGB(123, 123, 123)
RGB= the red green and blue.. values from 0 to 255 which gives you about any color there is.
As far as the close button goes; if by "Control it" you mean you want to disable it, use the following code:
VB Code:
Option Explicit
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060&
Private Sub Form_Load() 'or whatever
Dim systemmenu As Long
systemmenu = GetSystemMenu(Form1.hwnd, False)
DeleteMenu systemmenu, SC_CLOSE, MF_BYCOMMAND
End Sub
Mar 31st, 2003, 02:51 AM
#3
I use the same code as the first example, but so far to date, I
cannot paint the main menu when the item is clicked upon.
Ex. 'Option' will still be gray but the submenus are colored.
When I click an item to close the menu, the main menu bar is colored again.
I subclassed the form at the 'WM_INITMENUPOPUP' message
and tried to repaint the menu using the menuinfo type so the
menu will always be vbWhite whether its clicked on or not,
but it didn't work.
Any suggestions
Last edited by RobDog888; Mar 31st, 2003 at 02:54 AM .
Mar 31st, 2003, 03:00 AM
#4
Hyperactive Member
If you want to perform code when X is pressed you need to do sth like this:
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
' this is your X Button
Case vbFormCode
' your form gets closed by any other code IE an Button
Case vbAppTaskManager
' your app gets closed by the Task manager
.
.
.
End Select
End Sub
Hope I could help,
Stephan
Keep Smiling - even if its hard
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
Mar 31st, 2003, 03:39 AM
#5
To disable the 'x'...
Code:
Option Explicit
Private Const MF_BYPOSITION = &H400&
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long , ByVal nPosition As Long , ByVal wFlags As Long ) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long , ByVal bRevert As Long ) As Long
Private Sub Form_Load()
RemoveMenu GetSystemMenu(hwnd, 0), 6, MF_BYPOSITION
End Sub
Mar 31st, 2003, 03:57 AM
#6
Hyperactive Member
Originally posted by Sgt-Peppa
If you want to perform code when X is pressed you need to do sth like this:
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
' this is your X Button
Case vbFormCode
' your form gets closed by any other code IE an Button
Case vbAppTaskManager
' your app gets closed by the Task manager
.
.
.
End Select
End Sub
Hope I could help,
Stephan
i tried that with the following code and it didnt work
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Select Case UnloadMode
Case vbFormControlMenu
frmSStatus.Hide
stSMain.InTray = True
Exit Sub
Case vbAppTaskManager
frmSStatus.Hide
stSMain.InTray = True
Exit Sub
Case vbFormCode
frmSStatus.Hide
stSMain.InTray = True
Exit Sub
End Select
End Sub
(stSMain is the system tray icon control)
Mar 31st, 2003, 04:10 AM
#7
Hyperactive Member
is frmSStatus.Hide the form from where you press the X button?
If so don`t think you can hide a form which gets Unloaded!
Try this simple example I included:
Hope I could help,
Stephan
Attached Files
Keep Smiling - even if its hard
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width