TextGadget on window's menu bar?

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

TextGadget on window's menu bar?

Post by BarryG »

I would like to put a message in the far-right unused area of my window's menu bar, like the fake image below (from the manual's Menu example). ChatGPT said to use a floating window on top of the menu, which works but lags when you move the window around. Is there a better way to do it?

I've tried various versions of SetParent_() and BringWindowToTop_() but they failed, due to the menu being outside of the window's client area. So, is this possible to do in some way? Even if I have a menu item set to the far-right somehow? Thanks.

Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: TextGadget on window's menu bar?

Post by RASHAD »

Hi BarryG
If You don't want exactly TextGadget() you can align the last menu title to right
Else

Code: Select all

Global CaptionH,MenuH

Procedure sizeCB()
  ResizeWindow(1,WindowX(0)+WindowWidth(0)-200,WindowY(0)+CaptionH,198,MenuH)
EndProcedure

If OpenWindow(0, 0, 0, 600, 400, "PureBasic - Menu",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
  WindowBounds(0,400,200,#PB_Default,#PB_Default)
  CaptionH = WindowY(0,#PB_Window_InnerCoordinate) - WindowY(0,#PB_Window_FrameCoordinate)
  If CreateMenu(0, WindowID(0))
    MenuTitle("File")
    MenuItem( 1, "&Load...")
    MenuItem( 2, "Save")
    MenuItem( 3, "Save As...")
    MenuBar()
    OpenSubMenu("Recents")
    MenuItem( 5, "Pure.png")
    MenuItem( 6, "Basic.jpg")
    OpenSubMenu("Even more !")
    MenuItem( 12, "Yeah")
    CloseSubMenu()
    MenuItem( 13, "Rocks.tga")
    CloseSubMenu()
    MenuBar()
    MenuItem( 7, "&Quit")
    
    MenuTitle("Edition")
    MenuItem( 8, "Cut")
    MenuItem( 9, "Copy")
    MenuItem(10, "Paste")
    
    MenuTitle("?")
    MenuItem(11, "About")
    MenuItem(14, "Check/Uncheck Me")
    
  EndIf
  
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  
  MenuH = MenuHeight()-1
  
  OpenWindow(1,WindowX(0)+WindowWidth(0)-200,WindowY(0)+CaptionH,198,MenuH,"",#PB_Window_BorderLess,WindowID(0))
  SetWindowColor(1,0)
  UseGadgetList(WindowID(1))
  TextGadget(0,0,0,198,MenuH,"this a test",#SS_CENTER|#SS_CENTERIMAGE)
  SetGadgetColor(0, #PB_Gadget_BackColor ,$C3FCFE)
  SetGadgetColor(0, #PB_Gadget_FrontColor ,$0000FF)  
  HideWindow(0,0)
  UseGadgetList(WindowID(0))
  
  BindEvent(#PB_Event_SizeWindow,@sizeCB())
  BindEvent(#PB_Event_MoveWindow,@sizeCB())    
  Repeat
    
    Select WaitWindowEvent()
        
      Case #PB_Event_Menu
        
        Select EventMenu()  ; To see which menu has been selected
            
          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)
            
          Case 14 ; Check/Uncheck Me
            If GetMenuItemState(0,14) = 1   ; Checked
              SetMenuItemState(0,14,0)      ; So uncheck Me
            Else                            ; Else
              SetMenuItemState(0,14,1)      ; Check Me
            EndIf
            
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
            
        EndSelect
        
      Case #PB_Event_CloseWindow
        Quit = 1
        
    EndSelect
    
  Until Quit = 1
  
EndIf

End
Last edited by RASHAD on Sat Mar 29, 2025 8:25 am, edited 1 time in total.
Egypt my love
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: TextGadget on window's menu bar?

Post by BarryG »

RASHAD wrote: Sat Mar 29, 2025 8:20 amIf you don't want exactly TextGadget() you can align the last menu title to right
Oh yes, that would be better! How, though? (And your TextGadget example works great, too, so don't remove it).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: TextGadget on window's menu bar?

Post by RASHAD »

Right aligned Title
You can change the title at any time
But not the color :)

Code: Select all

Procedure MenuTitleRight(hWnd, hMenu, TitleIndex)
  Protected Minfo.MENUITEMINFO
  Minfo\cbSize = SizeOf(Minfo)
  Minfo\fMask = #MIIM_FTYPE
  GetMenuItemInfo_(hMenu, TitleIndex, #True,Minfo)   
  Minfo\fType = Minfo\fType | #MFT_RIGHTJUSTIFY
  SetMenuItemInfo_(hMenu, TitleIndex, #True, Minfo)
  DrawMenuBar_(hWnd)
EndProcedure

If OpenWindow(0, 0, 0, 600, 400, "MenuTitle Right", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  WindowBounds(0,300,200,#PB_Default,#PB_Default)
  If CreateMenu(0, WindowID(0))
    MenuTitle("Title 1") ; title 0
    MenuItem(1, "Item 1")
    MenuItem(2, "Item 2")
    MenuTitle("Title 2")   ;title 1
    
    MenuTitle("This is BarryG TEST")  ;title 2
    
    MenuTitleRight(WindowID(0), MenuID(0), 2)
    Repeat
      Select  WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1
      EndSelect
    Until Quit = 1
  EndIf
EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: TextGadget on window's menu bar?

Post by BarryG »

Perfect, Rashad! :) And the color doesn't matter; I only made it red in my screenshot to stand out. I didn't need to have it in color.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: TextGadget on window's menu bar?

Post by PBJim »

Very impressive Rashad.

If you add | #MFT_SEPARATOR you can prevent the text from responding to mouseover and also greyed out slightly.

Code: Select all

Procedure MenuTitleRight(hWnd, hMenu, TitleIndex)
  Protected Minfo.MENUITEMINFO
  Minfo\cbSize = SizeOf(Minfo)
  Minfo\fMask = #MIIM_FTYPE
  GetMenuItemInfo_(hMenu, TitleIndex, #True,Minfo)   
  Minfo\fType = Minfo\fType | #MFT_RIGHTJUSTIFY ; | #MFT_SEPARATOR
  SetMenuItemInfo_(hMenu, TitleIndex, #True, Minfo)
  DrawMenuBar_(hWnd)
EndProcedure

Glad that you had this idea Barry, as the menu bar is mostly wasted space.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: TextGadget on window's menu bar?

Post by BarryG »

PBJim wrote: Sat Mar 29, 2025 9:17 amGlad that you had this idea Barry, as the menu bar is mostly wasted space.
Thanks, PBJim! I like that disabled look, too.

I had the idea to show "For private home use only" in my menu bar to stop people buying a cheap license for my app to use in their business. For a business license they're meant to pay a higher fee, so I wanted a message that was always visible so employees could see that their boss/company wasn't doing the right thing. ;)
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: TextGadget on window's menu bar?

Post by PBJim »

BarryG wrote: Sat Mar 29, 2025 9:30 am I had the idea to show "For private home use only" in my menu bar
Yes, I imagined it was for some sort of status. It's quite a prominent position, better than the lower status bar in some ways.

I would tend to consider a possible form of restriction in a home version, such as maximum number of records.
Post Reply