Right justify a menu item(s) - MS Windows

Share your advanced PureBasic knowledge/code with the community.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Right justify a menu item(s) - MS Windows

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post 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:
Last edited by Kwai chang caine on Wed Feb 10, 2010 12:05 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

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

Post by bembulak »

Useful, thanks for sharing.
cheers,

bembulak
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

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

Post by +18 »

very cool, thanks man :D
Post Reply