How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by gurj »

How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Code: Select all

;rewrite from:
; PopupMenu_BoldItem.pb 
; English forum: http://www.purebasic.fr/english/viewtopic.php?p=70325#70325 
; Author: GreenGiant (updated for PB 4.00 by edel)
; Date:  26. September 2004 
; OS: Windows 
; Demo: No 


OpenWindow(0,0,0,400,400,"test",#PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
CreatePopupMenu(0) 
MenuItem(0,"Normal1") 
MenuItem(1,"Normal2") 
MenuItem(2,"Bold") 
MenuItem(3,"Normal3") 

bold.MENUITEMINFO 
bold\cbSize=SizeOf(bold) 
bold\fMask=#MIIM_TYPE
bold\fType=#MFT_MENUBARBREAK
;bold\dwItemData=?
SetMenuItemInfo_(MenuID(0),2,#True,bold) 

Repeat 
  ev=WaitWindowEvent() 
  If ev=#WM_RBUTTONUP 
    DisplayPopupMenu(0,WindowID(0)) 
  EndIf 
Until ev=#PB_Event_CloseWindow 
my pb for chinese:
http://ataorj.ys168.com
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by RSBasic »

Image
Image
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by gurj »

thanks RSBasic !
my pb for chinese:
http://ataorj.ys168.com
User avatar
kenmo
Addict
Addict
Posts: 2034
Joined: Tue Dec 23, 2003 3:54 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by kenmo »

Great tip, I never knew you could do that...
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by gurj »

That link isn't a *.htm.
is *.pb:

Code: Select all

If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  TextGadget(1,10,10,400,20,"Dr點ken Sie die rechte Maustaste, um das Popup-Men?zu 鰂fnen.",0)
  
  If CreatePopupMenu(1)
    For a=1 To 5
      MenuItem(a,"Item "+Str(a))
    Next
    AppendMenu_(MenuID(1),#MF_MENUBARBREAK,6,"Item 6")
    For a=7 To 10
      MenuItem(a,"Item "+Str(a))
    Next
  EndIf
  
Repeat
EventID=WaitWindowEvent()
Select EventID
  Case #WM_RBUTTONDOWN
    DisplayPopupMenu(1,WindowID(0))
EndSelect
If EventID=#PB_Event_CloseWindow
  Quit=1
EndIf
Until Quit=1
EndIf
my pb for chinese:
http://ataorj.ys168.com
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by electrochrisso »

That link isn't a *.htm.
is *.pb:
Yes, that way you can save the page from the browser save option to your computer, Chrome adds a txt extension at the end, probably because it do not know what it is, anyway you can just modify the name and put the pb extension instead of the txt and save it, but it is much easier just to copy the text from the page and paste it into PB.
PureBasic! Purely the best 8)
BarryG
Addict
Addict
Posts: 4160
Joined: Thu Apr 18, 2019 8:17 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by BarryG »

Can #MF_MENUBARBREAK be used for an app's normal title area menu, instead of a popup menu? I tried and it didn't work.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by RASHAD »

You can make the Menubar Multi Rows :)

Code: Select all

If OpenWindow(0, 100, 150, 195, 260, "PureBasic - Menu")
  
  
  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(12, "Check/Uncheck Me")
    
    For item = 4 To 10
      MenuTitle("")
    Next
    MenuTitle("OVER")
    MenuItem(13, "Over 1")
    MenuItem(14, "Over 2")
    
  EndIf
  
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  
  
  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
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by RASHAD »

Crazy idea :mrgreen:
We can keep all windows active all time for good looking and the Window position too

Code: Select all

Procedure smCB()
  ResizeWindow(1,WindowX(0)+100, WindowY(0)+30, 150, 40)
  ResizeWindow(2,WindowX(0)+250, WindowY(0)+30, 150, 40)
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "PureBasic - Menu",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  OpenWindow(1, WindowX(0)+100, WindowY(0)+30, 150, 40, "",#PB_Window_BorderLess,WindowID(0))  
  If CreateMenu(0, WindowID(1))
    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")
  EndIf
  
  OpenWindow(2, WindowX(0)+250, WindowY(0)+30, 150, 40, "",#PB_Window_BorderLess,WindowID(0))  
  If CreateMenu(1, WindowID(2))
    MenuTitle("File")
    MenuItem( 14, "&Load...")
    MenuItem( 15, "Save")
    MenuItem( 16, "Save As...")
    MenuBar()   
    MenuTitle("Edition")
    MenuItem( 17, "Cut")
    MenuItem( 18, "Copy")
    MenuItem( 19, "Paste")
  EndIf
  
  BindEvent(#PB_Event_MoveWindow,@smCB())
  
  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
            Debug "14"
            
          Case 19
            Debug "19"
            
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
            
        EndSelect
        
      Case #PB_Event_CloseWindow
        Quit = 1
        
    EndSelect
    
  Until Quit = 1
  
EndIf
End

Egypt my love
BarryG
Addict
Addict
Posts: 4160
Joined: Thu Apr 18, 2019 8:17 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by BarryG »

I was hoping to have only one title bar menu which opens split like this when it drops down:

Image

Not possible? I may have to fake it by opening a pop-up menu where the title menu is. The reason for my question is that my app's main title bar menu now has 30 menu items added to it, and I'd prefer to have two columns of 15 items instead, to look and work better on smaller desktops.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by breeze4me »

BarryG wrote: Sun Mar 30, 2025 2:51 am I was hoping to have only one title bar menu which opens split like this when it drops down:

Image

Not possible? I may have to fake it by opening a pop-up menu where the title menu is. The reason for my question is that my app's main title bar menu now has 30 menu items added to it, and I'd prefer to have two columns of 15 items instead, to look and work better on smaller desktops.
You can do this.

Code: Select all

If OpenWindow(0, 200, 200, 200, 100, "Menu Example")
  
  If CreateMenu(0, WindowID(0))
    MenuTitle("title1")
    MenuItem(31, "Open"   +Chr(9)+"Ctrl+O")
    MenuItem(32, "Save"   +Chr(9)+"Ctrl+S")
    MenuItem(33, "Save as"+Chr(9)+"Ctrl+A")
    MenuItem(34, "Close"  +Chr(9)+"Ctrl+C")
    
    
    MenuTitle("title2")
    For i = 1 To 15
      MenuItem(i, "item " + i)
    Next
    
    ; Get the handle of the second menu title.
    Define item.MENUITEMINFO
    item\cbSize = SizeOf(MENUITEMINFO)
    item\fMask = #MIIM_SUBMENU
    GetMenuItemInfo_(MenuID(0), 1, #True, item)
    
    If item\hSubMenu
      AppendMenu_(item\hSubMenu, #MF_MENUBARBREAK, 16, "Item 16")
    EndIf
    
    For i = 17 To 30
      MenuItem(i, "item " + i)
    Next
    
    MenuTitle("title3")
    MenuItem(41, "Open"   +Chr(9)+"Ctrl+O")
    MenuItem(42, "Save"   +Chr(9)+"Ctrl+S")
    MenuItem(43, "Save as"+Chr(9)+"Ctrl+A")
    MenuItem(44, "Close"  +Chr(9)+"Ctrl+C")
  EndIf
  
  Repeat
    e = WaitWindowEvent()
    If e = #PB_Event_Menu
      Debug EventMenu()
    EndIf
  Until e = #PB_Event_CloseWindow
EndIf
BarryG
Addict
Addict
Posts: 4160
Joined: Thu Apr 18, 2019 8:17 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by BarryG »

Hi breezeforme. :) Close, and it works perfectly for standard window menus, but I forgot to mention that I'm actually using an image menu. So your code below doesn't insert the menu item:

Code: Select all

If OpenWindow(0, 200, 200, 200, 100, "Menu Example")

  CreateImage(0,16,16,24,#Red)
  
  If CreateImageMenu(0, WindowID(0))
  
    MenuTitle("title1")
    MenuItem(31, "Open"   +Chr(9)+"Ctrl+O")
    MenuItem(32, "Save"   +Chr(9)+"Ctrl+S")
    MenuItem(33, "Save as"+Chr(9)+"Ctrl+A")
    MenuItem(34, "Close"  +Chr(9)+"Ctrl+C")
    
    MenuTitle("title2")
    For i = 1 To 15
      MenuItem(i, "item " + i)
    Next
    
    ; Get the handle of the second menu title.
    Define item.MENUITEMINFO
    item\cbSize = SizeOf(MENUITEMINFO)
    item\fMask = #MIIM_SUBMENU
    GetMenuItemInfo_(MenuID(0), 1, #True, item)
    
    If item\hSubMenu
      AppendMenu_(item\hSubMenu, #MF_MENUBARBREAK, 16, "Item 16") ; Doesn't appear in menu.
      SetMenuItemBitmaps_(MenuID(0),16,#MF_BYPOSITION,ImageID(0),ImageID(0)) ; Doesn't help.
    EndIf
    
    For i = 17 To 30
      MenuItem(i, "item " + i)
    Next
    
    MenuTitle("title3")
    MenuItem(41, "Open"   +Chr(9)+"Ctrl+O")
    MenuItem(42, "Save"   +Chr(9)+"Ctrl+S")
    MenuItem(43, "Save as"+Chr(9)+"Ctrl+A")
    MenuItem(44, "Close"  +Chr(9)+"Ctrl+C")

  EndIf
  
  Repeat
    e = WaitWindowEvent()
    If e = #PB_Event_Menu
      Debug EventMenu()
    EndIf
  Until e = #PB_Event_CloseWindow

EndIf
User avatar
mk-soft
Always Here
Always Here
Posts: 6231
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by mk-soft »

Chr(9) = #TAB$
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by breeze4me »

BarryG wrote: Sun Mar 30, 2025 11:58 am ... using an image menu.

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0, 200, 200, 200, 100, "Menu Example")
  hImg = LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png")
  
  If CreateImageMenu(0, WindowID(0))
  
    MenuTitle("title1")
    MenuItem(31, "Open"   +Chr(9)+"Ctrl+O")
    MenuItem(32, "Save"   +Chr(9)+"Ctrl+S")
    MenuItem(33, "Save as"+Chr(9)+"Ctrl+A")
    MenuItem(34, "Close"  +Chr(9)+"Ctrl+C")
    
    MenuTitle("title2")
    For i = 1 To 30
      If i = 16
        MenuItem(i, "item " + i, hImg)
      Else
        MenuItem(i, "item " + i)
      EndIf
    Next
    
    ; Get the handle of the second menu title.
    Define item.MENUITEMINFO
    item\cbSize = SizeOf(MENUITEMINFO)
    item\fMask = #MIIM_SUBMENU
    GetMenuItemInfo_(MenuID(0), 1, #True, item)
    
    If item\hSubMenu
      hSubMenu = item\hSubMenu
      FillMemory(@item, SizeOf(MENUITEMINFO))
      
      item\cbSize = SizeOf(MENUITEMINFO)
      item\fMask = #MIIM_FTYPE | #MIIM_ID| #MIIM_DATA
      
      If GetMenuItemInfo_(hSubMenu, 15, #True, item)
        item\fType | #MFT_MENUBARBREAK
        SetMenuItemInfo_(hSubMenu, 15, #True, item)
      EndIf
    EndIf
    
    MenuTitle("title3")
    MenuItem(41, "Open"   +Chr(9)+"Ctrl+O")
    MenuItem(42, "Save"   +Chr(9)+"Ctrl+S")
    MenuItem(43, "Save as"+Chr(9)+"Ctrl+A")
    MenuItem(44, "Close"  +Chr(9)+"Ctrl+C")

  EndIf
  
  Repeat
    e = WaitWindowEvent()
    If e = #PB_Event_Menu
      Debug EventMenu()
    EndIf
  Until e = #PB_Event_CloseWindow

EndIf
BarryG
Addict
Addict
Posts: 4160
Joined: Thu Apr 18, 2019 8:17 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by BarryG »

Thanks again, breeze4me. Your example works perfectly by itself, but not in my real app, which I think is to do with it having a submenu. :(

Here's your code with how my app is doing it... if you can make the below split the submenu of title2 into two parts, I would be eternally grateful. :)

Code: Select all

UsePNGImageDecoder()

If OpenWindow(0, 600, 250, 200, 100, "Menu Example")
  
  hImg = LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png")
  
  menu_app = CreateImageMenu(#PB_Any, WindowID(0))
  
  If menu_app
    
    MenuTitle("title1") ; Index 0
    MenuItem(10, "10"   +Chr(9)+"Ctrl+O")
    MenuItem(11, "11"   +Chr(9)+"Ctrl+S")
    MenuItem(12, "12"+Chr(9)+"Ctrl+A")
    MenuItem(13, "13"  +Chr(9)+"Ctrl+C")
    
    MenuTitle("title2") ; Index 1
    MenuItem(14, "item 14")
    OpenSubMenu("sub")
    For i = 15 To 50
      MenuItem(i, "item " + i, hImg) ; Want a split in the middle of these items.
    Next
    CloseSubMenu()
    
    ; Get the handle of the second menu title.
    Define item.MENUITEMINFO
    item\cbSize = SizeOf(MENUITEMINFO)
    item\fMask = #MIIM_SUBMENU
    GetMenuItemInfo_(MenuID(menu_app), 1, #True, item) ; 1 = Index 1
    If item\hSubMenu
      hSubMenu = item\hSubMenu
      FillMemory(@item, SizeOf(MENUITEMINFO))
      item\cbSize = SizeOf(MENUITEMINFO)
      item\fMask = #MIIM_FTYPE | #MIIM_ID| #MIIM_DATA
      split_point = (50 - 15) / 2
      If GetMenuItemInfo_(hSubMenu, split_point, #True, item)
        item\fType | #MFT_MENUBARBREAK
        SetMenuItemInfo_(hSubMenu, split_point, #True, item)
      EndIf
    EndIf
    
    MenuTitle("title3") ; Index 2
    MenuItem(51, "51"   +Chr(9)+"Ctrl+O")
    MenuItem(52, "52"   +Chr(9)+"Ctrl+O")
    MenuItem(52, "53"   +Chr(9)+"Ctrl+S")
    
  EndIf
  
  Repeat
    e = WaitWindowEvent()
    If e = #PB_Event_Menu
      Debug EventMenu()
    EndIf
  Until e = #PB_Event_CloseWindow
  
EndIf
Post Reply