Page 1 of 1

How to put an image in a menubar

Posted: Mon Nov 08, 2004 10:14 pm
by thefool
How to put an image in a menubar?

Just wondering if it was possible at all. Since i have an image on the whole form, and the MenuBar is all grey, i wondered if it was possible to do that.

thanks in advance :D

Posted: Sun Nov 14, 2004 12:11 pm
by thefool
No one???

Posted: Sat Nov 20, 2004 12:50 am
by thefool
Hi. Im sorry this is the 3 post here, but i really need this. Can it be done or not? :(

Posted: Sat Nov 20, 2004 1:01 am
by PB
I don't know what you mean. Have you got a screenshot of another app
that has it, so we can see what you're talking about? It's not this, is it:

viewtopic.php?t=13156 :?:

Posted: Sat Nov 20, 2004 10:44 am
by thefool
Hi. Sorry for bein unclear. Thats not what i mean (i have purevision to do that.).

In the menubar (top of an app. ehhh file, edit, view menus etc.) Can you change color or put an image to that bar? (covering. So if form is blue, menubar will be blue, not grey.)

Posted: Sat Nov 20, 2004 4:08 pm
by Sparkie
I pieced this together from a lib I'm working on. You can select a color or image for the main and/or popup menu).

Code: Select all

UseJPEGImageDecoder()

#MIM_BACKGROUND = 2  
#MIM_APPLYTOSUBMENUS = $80000000  

Structure myMENUINFO 
  cbSize.l 
  fMask.l 
  dwStyle.l 
  cyMax.l 
  hbrBack.l 
  dwContextHelpID.l 
  dwMenuData.l 
EndStructure 

Global hBrush

; --> Create our menu background
Procedure myMenuBg(hMnu.l, bkImg$, bkColor.l, subMenu)
  ; --> Reset menu to default background
  myMenu.myMENUINFO\cbSize = SizeOf(myMENUINFO)
  GetMenuInfo_(hMnu, @myMenu)
  myMenu\fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS
  myMenu\hbrBack = 0
  SetMenuInfo_(hMnu, myMenu) 
  ; --> If there is an image or RGB color, change the menu background
  If bkImg$ <> "" Or bkColor <> -1
    ; --> Load our image 
    If bkImg$ <> ""
      If LoadImage(0, bkImg$) 
        myImg = ImageID()
        If myImg <> 0
          myBrush.LOGBRUSH\lbStyle = #BS_PATTERN
          myBrush.LOGBRUSH\lbHatch = myImg
        EndIf
      EndIf
    EndIf
    ; --> If no image, use RGB color
    If myImg = 0
      myBrush.LOGBRUSH\lbStyle = #BS_SOLID
      myBrush.LOGBRUSH\lbColor = bkColor 
    EndIf
    hBrush = CreateBrushIndirect_(myBrush) 
    ; --> Define menu info 
    If subMenu = 1
      myMenu\fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS
    Else
      myMenu\fMask = #MIM_BACKGROUND
    EndIf
    myMenu\hbrBack = hBrush
    SetMenuInfo_(hMnu, myMenu)
    ; --> Free image 0 for other use
    If myImg <> 0
      FreeImage(0)
    EndIf
  EndIf
  ; --> Upadte the menu
  RedrawWindow_(WindowID(), 0, 0, #RDW_INVALIDATE|#RDW_FRAME|#RDW_UPDATENOW)
  ProcedureReturn hBrush
EndProcedure

; --> Reset menu to default background.
Procedure myMenuDefault(hMnu)
  myMenuBg(hMnu, "", -1, 1)
EndProcedure

; --> Clean-up on exit
Procedure myMenu_End()
  DeleteObject_(hBrush)
EndProcedure

If OpenWindow(0, 200, 200, 400, 110, #PB_Window_SystemMenu, "Set Menu Background") And CreateGadgetList(WindowID(0))
  TextGadget(0, 140, 20, 150, 20, "Right-click for Popup menu.")
  ; --> Create a menu and use the returned handle for setting background
  hMenu = CreateMenu(0, WindowID())
  If hMenu <> 0
    MenuTitle("Main Menu") 
    OpenSubMenu("Select Background")
    MenuItem(1, "Choose Color...") 
    MenuItem(2, "Choose Image...")
    CloseSubMenu()
    MenuBar()
    MenuItem(3, "Include Submenus")
    SetMenuItemState(0, 3, 1)
    MenuItem(4, "Reset")
    DisableMenuItem(4, 1)
    MenuTitle("Popup Menu") 
    OpenSubMenu("Select Background")
    MenuItem(5, "Choose Color...") 
    MenuItem(6, "Choose Image...")
    CloseSubMenu()
    MenuBar()
    MenuItem(7, "Include Submenus")
    SetMenuItemState(0, 7, 1)
    MenuItem(8, "Reset")
    DisableMenuItem(8, 1)
  EndIf
  ; --> Create a popup menu and use the returned handle for setting background
  hPop = CreatePopupMenu(1)
  If hPop <> 0
    MenuTitle("Testing")
    MenuItem(9, "Open")
    MenuItem(10, "Save") 
    MenuItem(11, "Save as") 
    MenuItem(12, "Quit") 
    MenuBar() 
    OpenSubMenu("More Testing") 
    MenuItem(13, "Test") 
    MenuItem(14, "Test") 
    CloseSubMenu() 
    MenuItem(15, "Edit") 
    MenuItem(16, "Options") 
  EndIf 
 
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_EventMenu
        Select EventMenuID()
          Case 1
            ; --> Use color for main menu
            menuColor = ColorRequester()
            If menuColor > -1
              menuImage$ = ""
              myMenuBg(hMenu, menuImage$, menuColor, GetMenuItemState(0, 3))
              DisableMenuItem(4, 0)
            EndIf
          Case 2
            ; --> Use image for main menu
            menuImage$ = OpenFileRequester("Choose Main Menu Background", "C:\Windows\", "BMP, JPG, JPEG Image files|*.bmp;*.jpg;*.jpeg", 0)
            If menuImage$ <> ""
              menuColor = -1
              myMenuBg(hMenu, menuImage$, menuColor, GetMenuItemState(0, 3))
              DisableMenuItem(4, 0)
            EndIf
          Case 3
            ; --> Include main menu submenus yes/no
            If GetMenuItemState(0, 3) = 0
              SetMenuItemState(0, 3, 1)
            Else
              SetMenuItemState(0, 3, 0)
            EndIf
            If menuImage$ <> "" Or menuColor <> -1
              myMenuBg(hMenu, menuImage$, menuColor, GetMenuItemState(0, 3))
              DisableMenuItem(4, 0)
            EndIf
          Case 4
            ; --> Reset main menu to deafult background
            myMenuDefault(hMenu)
            menuColor = -1
            menuImage$ = ""
            DisableMenuItem(4, 1)
          Case 5
            ; --> Use color for popup menu
            popColor = ColorRequester()
            If popColor > -1
              popImage$ = ""
              myMenuBg(hPop, popImage$, popColor, GetMenuItemState(0, 7))
              DisableMenuItem(8, 0)
            EndIf
          Case 6
            ; --> Use image for popup menu
            popImage$ = OpenFileRequester("Choose Popup Menu Background", "C:\Windows\", "BMP, JPG, JPEG Image files|*.BMP;*.jpg;*.jpeg", 0)
            If popImage$ <> ""
              popColor = -1
              myMenuBg(hPop, popImage$, popColor, GetMenuItemState(0, 7))
              DisableMenuItem(8, 0)
            EndIf
          Case 7
            ; --> Include popup submenus yes/no
            If GetMenuItemState(0, 7) = 0
              SetMenuItemState(0, 7, 1)
            Else
              SetMenuItemState(0, 7, 0)
            EndIf
            If popImage$ <> "" Or popColor <> -1
              myMenuBg(hPop, popImage$, popColor, GetMenuItemState(0, 7))
              DisableMenuItem(8, 0)
            EndIf
          Case 8
            ; --> Reset popup to deafult background
            myMenuDefault(hPop)
            popColor = -1
            popImage$ = ""
            DisableMenuItem(8, 1)
        EndSelect
      Case #WM_RBUTTONDOWN
        DisplayPopupMenu(1, WindowID())  
    EndSelect
  Until event = #PB_Event_CloseWindow 
  myMenu_End()
EndIf
End

Posted: Sat Nov 20, 2004 5:13 pm
by thefool
Thanks a lot mate :D
exactly what i needed!

What lib? A gadget style lib? Would be really great to have

Posted: Thu Dec 27, 2007 1:46 pm
by Kwai chang caine
Hello all

It is possible to change the color of font ? :roll:

Thanks for your answer. 8)

Posted: Thu Dec 27, 2007 6:13 pm
by Sparkie
You can change menu text color with ownerdrawing. Here's one example...

http://www.purebasic.fr/english/viewtop ... rdraw+menu

Posted: Thu Dec 27, 2007 11:59 pm
by yrreti
Thanks for the code Sparkie :D
It's kind of neat what you can do with it.

Posted: Fri Dec 28, 2007 9:22 am
by Kwai chang caine
Thanks SPARKIE

I love BATMAN now :D