CodeItBetter Programming Another VB Programming Blog

How to Right align a menu

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'Forms - How to Right align a menu

Option Explicit
 
'Add a Command Button and a Menu to your form.

Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public Const MIIM_TYPE = &H10
Public Const MFT_RIGHTJUSTIFY = &H4000
Public Const MFT_STRING = &H0&
Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
End Type
 
Private Sub Command1_Click()
    Dim MnuInfo As MENUITEMINFO
    mnuH& = GetMenu(Me.hwnd)
    MnuInfo.cbSize = Len(MnuInfo)
    MnuInfo.fMask = MIIM_TYPE
    'If you want to align to right only few menus, and leave the rest in left side,
    'Replace the '0' below and the '0' two lines above the 'End Sub' with the number
    'of menus you want to leave in the left side.
    myTemp& = GetMenuItemInfo(mnuH&, 0, True, MnuInfo)
    MnuInfo.fType = MFT_RIGHTJUSTIFY Or MFT_STRING
    'Replace all 'MenuCaption' below with the caption of the first menu from left.
    MnuInfo.cch = Len("MenuCaption")
    MnuInfo.dwTypeData = "MenuCaption"
    MnuInfo.cbSize = Len(MnuInfo)
    myTemp& = SetMenuItemInfo(mnuH&, 0, True, MnuInfo)
    myTemp& = DrawMenuBar(Me.hwnd)
End Sub

Related posts:

  1. How to add Split in Menu
  2. How to add Circl check mark in Menu
  3. How to align Caption on Command Button
  4. How to add a bitmap to your menu
  5. How to Set the ShowInTaskBar Property at Runtime
  6. How to add a minimize Button to Form that has fixed Border
  7. How to Create a Menu completely at Runtime
  8. How to Enable/Disable Close Button in a form
  9. How to disable builtin right click context menu in text box
  10. How to add New Menu item to the Form’s Sytem Menu

Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.