How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Just starting out? Need help? Post your questions and find answers here.
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
hSubmenu = OpenSubMenu("sub")
Windows only trick. :wink:

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")
    hSubmenu = OpenSubMenu("sub")
    For i = 15 To 50
      MenuItem(i, "item " + i, hImg) ; Want a split in the middle of these items.
    Next
    CloseSubMenu()
    
    Define item.MENUITEMINFO
    If hSubMenu
      item\cbSize = SizeOf(MENUITEMINFO)
      item\fMask = #MIIM_FTYPE | #MIIM_ID| #MIIM_DATA
      
      split_point = (50 - 15) / 2 + 1
      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
BarryG
Addict
Addict
Posts: 4269
Joined: Thu Apr 18, 2019 8:17 am

Re: How use #MFT_MENUBARBREAK for SetMenuItemInfo ?

Post by BarryG »

@breeze4me: Your code works perfect on PureBasic 6.10, but then a PureBasic update broke it because the icon X/Y positions are cropped by 1 pixel now, and the menu item spacing is now also smaller vertically. See below.

Fred says the menu system uses the Windows API so he can't fix it... but it clearly worked before. Is this something you can fix or work around? Because it looks like I'm stuck with 6.10 forever. :(

Image
Post Reply