How to put an image in a menubar

Just starting out? Need help? Post your questions and find answers here.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

How to put an image in a menubar

Post 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
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

No one???
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Hi. Im sorry this is the 3 post here, but i really need this. Can it be done or not? :(
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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 :?:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Thanks a lot mate :D
exactly what i needed!

What lib? A gadget style lib? Would be really great to have
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Hello all

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

Thanks for your answer. 8)
ImageThe happiness is a road...
Not a destination
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You can change menu text color with ownerdrawing. Here's one example...

http://www.purebasic.fr/english/viewtop ... rdraw+menu
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Post by yrreti »

Thanks for the code Sparkie :D
It's kind of neat what you can do with it.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Thanks SPARKIE

I love BATMAN now :D
ImageThe happiness is a road...
Not a destination
Post Reply