• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1995
  • Last Modified:

Change background color of a Pop up menu

I have written a vb6 code to change background color of a menu.
It works perfectly when the menu is set to visible, but wont work when menu is invisible.
How can i change the background color of a invisible menu?
I have attached my project. MDIback-color-change-notworking.zip
0
winman_soft
Asked:
winman_soft
  • 7
  • 6
  • 4
  • +2
1 Solution
 
kbireckiCommented:
I'm going to check out your project because it sounds like a cool idea to change the background color of a menu, but can you give an example of how you would use this feature of changing the color of an invisible menu?  And how would you tell the difference?  I'm thinking that since it is invisible, you could just tell people it can read minds and is magically their favorite color.  :)
0
 
winman_softAuthor Commented:
I am using popupmenu to display that menu at a button click.. BOOYA. it is visible again:)
0
 
Martin LissOlder than dirtCommented:
So change the color in the button click event.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
VBClassicGuyCommented:
Yeah, do what MartinLiss says. Right after the PopupMenu command, set the color. It'll happen so fast the user won't notice the color change.
0
 
Martin LissOlder than dirtCommented:
Or you could have several menus that are identical except for the color and then popup the one with the color you want.
0
 
winman_softAuthor Commented:
problem is I am not able to get the handle for that pop up menu.. In the project I change the color menu when it is invisible, and when I click the button to popup that menu the color is not changed.
0
 
judgekingCommented:
If the menu is invisible when you change it, then when do you see the menu?  Are you trying to popup Form2's menu when it's not visible?  Where in your code would you do that, you don't have any other forms.  Are you trying to do it on the Parent form or a Form3?
0
 
Martin LissOlder than dirtCommented:
        .cbSize = Len(mi)
        
        .fMask = MIM_BACKGROUND
        .hbrBack = CreateSolidBrush(vbYellow)
        'SetMenuInfo GetMenu(MDIForm1.hwnd), mi  'main menu bar
        
        .fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
        .hbrBack = CreateSolidBrush(vbCyan)
        SetMenuInfo GetSubMenu(GetMenu(MDIForm1.hwnd), 0), mi
        DrawMenuBar MDIForm1.hwnd

Open in new window

0
 
VBClassicGuyCommented:
This is the only way i could find to do it. Have a menu bar that has one or more visible menus, but your popup menu is invisible. The main trick is to set the invisible menu's caption to be blank. Here is the code, and attached is the source and compiled exe. i don't explain very well, just run the exe and see what it does.

BTW, exe files aren't allowed in zip attachments here, so I renamed Project1.exe to Project1.txt. Name it back then run it.

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 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 Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

Private Sub Form_Load()
   Dim mi As MENUINFO
   
   With mi
      .cbSize = Len(mi)
      .fMask = MIM_BACKGROUND
      .hbrBack = CreateSolidBrush(vbWhite)
       SetMenuInfo GetMenu(Me.hwnd), mi  'main menu bar
      .fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
    End With

End Sub

Private Sub Command1_Click(Index As Integer)
   Dim mi As MENUINFO
   
   With mi
      .cbSize = Len(mi)
      .fMask = MIM_BACKGROUND
      .hbrBack = CreateSolidBrush(vbWhite)
       SetMenuInfo GetMenu(Me.hwnd), mi  'main menu bar
      .fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
    End With

   Select Case Index
      Case 0
         Rem *** RED ***
         mi.hbrBack = CreateSolidBrush(vbCyan)
      Case 1
         Rem *** GRN ***
         mi.hbrBack = CreateSolidBrush(vbGreen)
      Case 2
         Rem *** BLU ***
         mi.hbrBack = CreateSolidBrush(vbRed)
   End Select
   
   mnuMisc.Visible = True
   
   SetMenuInfo GetSubMenu(GetMenu(Me.hwnd), 1), mi 'Misc menu (item 1)
   PopupMenu mnuMisc
   mnuMisc.Visible = False

End Sub

PopupMenu.zip
0
 
Martin LissOlder than dirtCommented:
@VBClassicGuy: I see you incorporated my code, but if you just substitute my code for the With mi code in the author's Command1_Click code it works.
0
 
VBClassicGuyCommented:
Sorry Martin, I didn't even look at your code, didn't know I copied it. I grabbed an example I found from Googling, which did a lot more than change popup menus, it did system menus, buttons, listboxes, etc. Then I culled out all the stuff that didn't apply to this issue, played with it for a long time and made some changes, and posted what I wound up with.

Again, sorry. Didn't mean to step on any toes.

It's probably not what Winman_soft wants anyway, because you have to have a visible menu bar at the top of your form. If you do, then it's a piece of cake hiding the invisible submenu. But he probably wants NO menu bar to show, which is a sticky wicket.
0
 
Martin LissOlder than dirtCommented:
No worries, I wear steal-toed boots:)
0
 
VBClassicGuyCommented:
@MartinLiss: BOOOO...very punny!  :-)
0
 
winman_softAuthor Commented:
@VBclassicguy
Even in ur code when I uncheck visible for file menu the pop up menu colors wont be changed.
Anyhow, Thank u for the comments.
I found the answer in a project called ODmenus.

http://www.xtremevbtalk.com/showpost.php?p=1011714&postcount=13
0
 
Martin LissOlder than dirtCommented:
Did you simply try my code in your command button click event?
0
 
winman_softAuthor Commented:
@MartinLiss

I did try ur code by replacing the code in with mi.. Even then the color wont be changed when the visible parameter in unchecked in menu editor
0
 
Martin LissOlder than dirtCommented:
ColorMenu.zip

It works for me.
0
 
winman_softAuthor Commented:
@Martin
Still.. when I hide menu "a" the popup menu will not be colored...
Let me explain my scenario again..
In our product we have a toolbar instead of a traditional menu and when we click on that we popup the submenu..
(So "a" must not be visible and the popup menu must be colored)
0
 
judgekingCommented:
Is the toolbar on the parent MDI form?  If so, why not use its menu instead of Form2?
0
 
winman_softAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 7
  • 6
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now