CodeItBetter Programming Another VB Programming Blog

How to add Circl check mark in 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'Forms - How to add Circl check mark in Menu

Option Explicit
 
'Add a menu to your form and add two Sub Menus to that. Name them both as MySubMenu.
'Set the first sub menu index property to '0'. Set the second sub menu index property to '1'.
'At run time, press one of the sub menus and you will see that it has circle check marks.

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
 
Private Sub SetRadioMenuChecks(Mnu As Menu, ByVal mnuItem As Long)
    Dim hMenu As Long
    Dim mInfo As MENUITEMINFO
    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
Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.