Date: 02-16-2022
Return to Index
created by gbSnippets
'This compilable example creates File, Edit and Help menus, each with sub-menus.
'The two Option menus include code to toggle the checkmark state of the sub-menus
'Note that since separators cannot be selected, a single equate was used by all of the separators
'The Callback code to respond to the menu clicks is also shown (puts menu name in the label)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32api.inc"
%IDM_Open = 400 : %IDM_Save = 401 : %IDM_Exit = 403
%IDM_Cut = 500 : %IDM_Copy = 502 : %IDM_Paste = 503
%IDM_ConfirmDelete = 600 : %IDM_SavePosition = 601
%IDM_Help = 700 : %IDM_About = 701
%IDM_Sep = 800
%IDC_Label = 900
Global hDlg As DWord, hMenu As DWord, hMenuFile As DWord, hMenuEdit As DWord
Global hMenuOptions as DWord, hMenuHelp as DWord
Function PBMain()
Dialog New Pixels, 0, "MRU Demo",300,300,300,200, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, %IDC_Label, " Selected menu description appears here", 30,30,240,125, %WS_Border
AddMenu
Dialog Show Modal hDlg Call DlgProc()
End Function
CallBack Function DlgProc() As Long
Local temp$, iReturn&
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case %IDM_Open : Control Set Text hDlg, %IDC_Label, " Open"
Case %IDM_Save : Control Set Text hDlg, %IDC_Label, " Save"
Case %IDM_Exit : Control Set Text hDlg, %IDC_Label, " Exit"
Case %IDM_Cut : Control Set Text hDlg, %IDC_Label, " Cut"
Case %IDM_Copy : Control Set Text hDlg, %IDC_Label, " Copy"
Case %IDM_Paste : Control Set Text hDlg, %IDC_Label, " Paste"
Case %IDM_About : Control Set Text hDlg, %IDC_Label, " About"
Case %IDM_ConfirmDelete
Menu Get State hMenuOptions, ByCmd %IDM_ConfirmDelete To iReturn 'get the state
Menu Set State hMenuOptions, ByCmd %IDM_ConfirmDelete, ABS(IsFalse iReturn)*8 'flip the state
Control Set Text hDlg, %IDC_Label, " Confirm Delete"
Case %IDM_SavePosition
Menu Get State hMenuOptions, ByCmd %IDM_SavePosition To iReturn 'get the state
Menu Set State hMenuOptions, ByCmd %IDM_SavePosition, ABS(IsFalse iReturn)*8 'flip the state
Control Set Text hDlg, %IDC_Label, " Save Position"
End Select
End Select
End Function
Sub AddMenu()
Menu New Bar To hMenu
Menu New Popup To hMenuFile
Menu New Popup To hMenuEdit
Menu New Popup To hMenuOptions
Menu New Popup To hMenuHelp
'Create File + Children -------------------------
Menu Add Popup, hMenu, "&File", hMenuFile, %MF_Enabled
Menu Add String, hMenuFile, "&Open" + $Tab + "Ctrl-O", %IDM_Open, %MF_Enabled
Menu Add String, hMenuFile, "&Save" + $Tab + "Ctrl-S", %IDM_Save, %MF_Enabled
Menu Add String, hMenuFile, "-", %IDM_Sep, 0
Menu Add String, hMenuFile, "E&xit", %IDM_Exit, %MF_Enabled
'Create Edit + Children -------------------------
Menu Add Popup, hMenu, "&Edit", hMenuEdit, %MF_Enabled
Menu Add String, hMenuEdit, "&Cut", %IDM_Cut, %MF_Enabled
Menu Add String, hMenuEdit, "C&opy", %IDM_Copy, %MF_Enabled
Menu Add String, hMenuEdit, "&Paste", %IDM_Paste, %MF_Enabled
'Create Options + Children -------------------------
Menu Add Popup, hMenu, "&Options", hMenuOptions, %MF_Enabled
Menu Add String, hMenuOptions, "&Confirm Delete", %IDM_ConfirmDelete, %MF_Enabled
Menu Add String, hMenuOptions, "-", %IDM_Sep, 0
Menu Add String, hMenuOptions, "&Save Position", %IDM_SavePosition, %MF_Enabled
'Create Edit + Children -------------------------
Menu Add Popup, hMenu, "&Help", hMenuHelp, %MF_Enabled
Menu Add String, hMenuHelp, "&About", %IDM_About, %MF_Enabled
Menu Attach hMenu, hDlg
End Sub
'gbs_00201
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm