Convert Menu 'V' Checkmark To Circle

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add menu to your form. Add 2 Sub Menus to this menu. Name them both MySubMenu.
'Set the first sub menu index property to '0'. Set the second sub menu index property to '1'.
'After you run the program, press on one of the sub menus and you will see that he has
'circle checkmarks.
'Insert this code to the module :

Public Const MIIM_STATE = &H1
Public Const MIIM_ID = &H2
Public Const MIIM_SUBMENU = &H4
Public Const MIIM_CHECKMARKS = &H8
Public Const MIIM_TYPE = &H10
Public Const MIIM_DATA = &H20
Public Const MFT_RADIOCHECK = &H200&
Public 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
Public Declare Function SetMenuItemInfo Lib "user32" Alias _
"SetMenuItemInfoA" (ByVal hMenu As Long, ByVal uItem As Long, ByVal _
fByPosition As Long, lpmii As MENUITEMINFO) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetSubMenu Lib "user32" (ByVal _
hMenu As Long, ByVal nPos As Long) As Long

'Insert the following code to your form:

Private Sub SetRadioMenuChecks(Mnu As Menu, ByVal mnuItem As Long)
Dim hMenu As Long
Dim mInfo As MENUITEMINFO
'Replace the '0' below with the menu position. In this case put '0' because the menu that you
'want to change his checkmark is the first menu from the left. If the menu position was the 'second from the left, you've should been put there '1'.

hMenu& = GetSubMenu(GetMenu(Mnu.Parent.hwnd), 0)
With mInfo
.cbSize = Len(mInfo)
.fType = MFT_RADIOCHECK
.fMask = MIIM_TYPE
.dwTypeData = Mnu.Caption & Chr$(0)
End With
SetMenuItemInfo hMenu&, mnuItem&, 1, mInfo
End Sub

Private Sub Form_Load()
'Replace the 'MySubMenu(0)' below with the name of the sub menu that you want to change
'his checkmark. Replace the '0' below (that found after the comma) with the position
'of the sub menu that you want to change his checkmark. In this case we put '0' because
'the 'MySubMenu(0)' sub menu is the top sub menu. if the sub menu position was the
'second from top, you've should put there '1'.

SetRadioMenuChecks MySubMenu(0), 0
SetRadioMenuChecks MySubMenu(1), 1
End Sub

Private Sub MySubMenu_Click(Index As Integer)
Static prevSelection As Integer
MySubMenu(prevSelection).Checked = False
MySubMenu(Index).Checked = True
prevSelection = Index
End Sub

Go Back