Is there a way to posit a menu at the right side of the window like in this example?
Finally found a solution by myself:
Private Sub ShowMenuItemOnRight(windowHandle As Integer, menuIndex As Integer = 0)
#If TargetWindows Then
#If Target64Bit Then
Declare Function GetMenu Lib "user32" (hwnd As Integer) As Integer
Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" ( _
hMenu As Integer, uItem As UInt32, fByPosition As Boolean, lpMenuItemInfo As MENUITEMINFO) As Boolean
Declare Function SetMenuItemInfo Lib "user32.dll" Alias "SetMenuItemInfoA" ( _
hMenu As Integer, uItem As UInt32, fByPosition As Boolean, lpMenuItemInfo As MENUITEMINFO) As Boolean
#Else ' 32 bit version
Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" ( _
hmenu As Integer, uItem As Integer, fByPosition As Boolean, lpMenuItemInfo As Ptr) As Boolean
Declare Function SetMenuItemInfo Lib "user32.dll" Alias "SetMenuItemInfoA" ( _
hMenu As Integer, uItem As Integer, fByPosition As Boolean, lpMenuItemInfo As Ptr) As Boolean
#EndIf
Const MFT_BITMAP = &H4
Const MFT_MENUBARBREAK = &H20
Const MFT_MENUBREAK = &H40
Const MFT_OWNERDRAW = &H100
Const MFT_RADIOCHECK = &H200
Const MFT_RIGHTJUSTIFY = &H4000
Const MFT_RIGHTORDER = &H2000
Const MFT_SEPARATOR = &H800
Const MFT_STRING = &H0
Const MIIM_STATE = &H1
Const MIIM_ID = &H2
Const MIIM_SUBMENU = &H4
Const MIIM_CHECKMARKS = &H8
Const MIIM_TYPE = &H10
Const MIIM_DATA = &H20
Const MIIM_STRING = &H40
Const MIIM_BITMAP = &H80
Const MIIM_FTYPE = &H100
Dim menuHandle As Integer
Dim menuInfo As MENUITEMINFO
' Get the main menu handle.
menuHandle = GetMenu(windowHandle)
' Initialize the menu information.
menuInfo.cbSize = menuInfo.Size
menuInfo.fMask = MIIM_FTYPE
' Get the menu item's information.
Call GetMenuItemInfo(menuHandle, menuIndex, True, menuInfo)
' Indicate that we will set fType.
menuInfo.fMask = MIIM_FTYPE
menuInfo.fType = menuInfo.fType Or MFT_RIGHTJUSTIFY
' Set the MFT_RIGHTJUSTIFY flag.
Call SetMenuItemInfo(menuHandle, menuIndex, True, menuInfo)
#EndIf
End Sub
Structure MENUITEMINFO
cbSize As UInt32
fMask As UInt32
fType As UInt32
fState As UInt32
wID As UInt32
hSubMenu As Integer
hbmpChecked As Integer
hbmpUnchecked As Integer
dwItemData As Integer
dwTypeData As Ptr
cch As UInt32
hbmpItem As Integer
End Structure
4 Likes
Brilliant, Thomas.
Do you define a standard menu, then move it right?
Please show us a picture of the menu on the Windows menu bar.
Thank you for that compliment, Mike!
Yes, that’s exactly what I did. You can use the menu index to define the first menu to move to the right. This way you can move them all to the right if you want to.
Greetings
Thomas
BTW, I found out this, too: if you want to show a special symbol from the Segoe font set e.g. you must add it to the menu programmatically, otherwise it gets lost.
Here is an example for macOS and Windows. Perhaps someone finds out why it doesn’t work on macOS with dark mode active.
RightMenu.xojo_binary_project.zip (6.3 KB)