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.


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
Oh yes, that would be better! How, though? (And your TextGadget example works great, too, so don't remove it).RASHAD wrote: Sat Mar 29, 2025 8:20 amIf you don't want exactly TextGadget() you can align the last menu title to right
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
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)
EndProcedureThanks, PBJim! I like that disabled look, too.PBJim wrote: Sat Mar 29, 2025 9:17 amGlad that you had this idea Barry, as the menu bar is mostly wasted space.
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.BarryG wrote: Sat Mar 29, 2025 9:30 am I had the idea to show "For private home use only" in my menu bar