Page 1 of 1

Right justify a menu item(s) - MS Windows

Posted: Wed Feb 10, 2010 4:17 am
by skywalk
If you want to shove Help or other menu items over to the right...

Code: Select all

Procedure menuRJustify(hWnd.l, menuindex.l)
  ; menuindex is the index of the main menu, counting from 0.
  Define.l hMenu
  Define.MENUITEMINFO mnuIteminfo
  hMenu = GetMenu_(hwnd)
  With mnuItemInfo
    \cbSize = SizeOf(menuiteminfo)
    \fMask = #MIIM_FTYPE
    GetMenuItemInfo_(hMenu, menuindex, #True, mnuiteminfo)    
    \fType = \fType | #MFT_RIGHTJUSTIFY
    SetMenuItemInfo_(hMenu, menuindex, #True, mnuiteminfo)
  EndWith
  ; This makes the changes stick!
  DrawMenuBar_(hwnd)  ; Repaint top level Menu
EndProcedure

If OpenWindow(0, 100, 200, 195, 260, "Help Menu Right Justified", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
  hWnd= WindowID(0)
  If CreateMenu(0, WindowID(0))
    MenuTitle("Project")
      MenuItem(0, "New")
      MenuItem(1, "Open")
      MenuItem(2, "Save")
    MenuTitle("Tool")
      MenuItem(0, "1")
      MenuItem(1, "2")
      MenuItem(2, "3")
    MenuTitle("Help")
      MenuItem(0, "1")
      MenuItem(1, "2")
      MenuItem(2, "3")
  EndIf
  menuRJustify(hWnd, 2)  ; 0-based index of main menu items to right justify
  Repeat
    Event = WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndSelect
  Until Quit = 1
EndIf
End
Windows XP SP3, PB 4.41

Re: Right justify a menu item(s) - MS Windows

Posted: Wed Feb 10, 2010 9:46 am
by Kwai chang caine
Super cool :D
Simple and very useful 8)
I use it immediately in my actual application
Thanks a lot for sharing :wink:

Re: Right justify a menu item(s) - MS Windows

Posted: Wed Feb 10, 2010 11:16 am
by bembulak
Useful, thanks for sharing.

Re: Right justify a menu item(s) - MS Windows

Posted: Wed Feb 10, 2010 5:20 pm
by +18
very cool, thanks man :D