Date: 02-16-2022
Return to Index
created by gbSnippets
'Creating a menu consists of creating the menu bar and attaching it
'to the dialog. Then, a popup menu is created and attached to the
'menu bar. Sub-items to the popup are added as needed.
'Primary Code:
Sub CreateAppMenu
Menu New Bar To hMenu 'bar
Menu Attach hMenu, hDlg 'bar attached to Dialog
Menu New Popup To hMenuOptions 'popup
Menu Add Popup, hMenu, "&File", hMenuOptions, %MF_Enabled 'popup attached to bar
Menu Add String, hMenuOptions, "&Open", 500, %MF_Enabled 'sub-item to popup
Menu Add String, hMenuOptions, "&Save", 501, %MF_Enabled 'sub-item to popup
End Sub
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32api.inc"
Global hDlg As DWord, hMenu As DWord, hMenuOptions As DWord
Function PBMain()
Dialog New Pixels, 0, "MRU Demo",300,300,300,200, %WS_OverlappedWindow To hDlg
CreateAppMenu
Dialog Show Modal hDlg Call DlgProc()
End Function
Sub CreateAppMenu
Menu New Bar To hMenu
Menu Attach hMenu, hDlg
Menu New Popup To hMenuOptions
Menu Add Popup, hMenu, "&File", hMenuOptions, %MF_Enabled
Menu Add String, hMenuOptions, "&Open", 500, %MF_Enabled
Menu Add String, hMenuOptions, "&Save", 501, %MF_Enabled
Menu Attach hMenu, hDlg
End Sub
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 500 Then MsgBox "Open"
If CB.Msg = %WM_Command AND CB.Ctl = 500 Then MsgBox "Save"
End Function
'gbs_00295
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm