Easy way to Check/UnCheck Menu Items

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Easy way to Check/UnCheck Menu Items

Post by BackupUser »

Code updated for 5.20+ (same as SetMenuItemState())

Restored from previous forum. Originally posted by plouf.

with the WinApi commant CheckMenuItem_(menuhandle,menuid,Constant)
Constand is #MF_CHECKED to check an item or #MF_UNCHECKED to uncheit
there is a more powerfull command SetMenuItemInfo_() but for for
check/uncheck is the simplest i found :)

Code: Select all

OpenWindow(0, 100, 100, 100, 100, "Test")
menuhandle.i = CreateMenu(0, WindowID(0))
MenuTitle("Test")
MenuItem(0, "Tick")
MenuItem(1, "Exit")

Repeat 
  windowevent = WaitWindowEvent() 
  If windowevent = #PB_Event_Menu
    menuevent = EventMenu()
    If menuevent = 0
      flip = 1 - flip
      If flip = 1
        CheckMenuItem_(menuhandle, 0, #MF_CHECKED)
      Else
        CheckMenuItem_(menuhandle, 0, #MF_UNCHECKED)
      EndIf
    EndIf
  ElseIf windowevent = #PB_Event_CloseWindow
    menuevent = 1
  EndIf
Until menuevent = 1
CloseWindow(0)
End
Christos