Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDM_One = 500
%IDM_Two = 501
%IDM_Three = 502
%IDM_Exit = 503
Global hDlg, hContext, MenuValue As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_Popup Or %WS_ThickFrame To hDlg
Control Add Label, hDlg, 100, "Right-mouse click!", 10,10,100,20
CreateContextMenu
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x,y As Long
Select Case Cb.Msg
Case %WM_InitDialog
Setting_INI "get"
SetMenus
Case %WM_Destroy
Setting_INI "save"
Case %WM_Command
Select Case Cb.Ctl
Case %IDM_One
MenuValue = 1
CheckMenuRadioItem hContext, %IDM_One, %IDM_Three, %IDM_One, %MF_ByCommand
Case %IDM_Two
MenuValue = 5
CheckMenuRadioItem hContext, %IDM_One, %IDM_Three, %IDM_Two, %MF_ByCommand
Case %IDM_Three
MenuValue = 10
CheckMenuRadioItem hContext, %IDM_One, %IDM_Three, %IDM_Three, %MF_ByCommand
Case %IDM_Exit : Dialog End hDlg
End Select
Case %WM_ContextMenu
x = Lo(Integer,Cb.LParam) : y = Hi(Integer, Cb.LParam)
TrackPopupMenu hContext, %TPM_LeftAlign, x, y, 0, Cb.Hndl, ByVal 0
End Select
End Function
Sub CreateContextMenu
Menu New PopUp To hContext
Menu Add String, hContext, "One", %IDM_One, %MF_Enabled
Menu Add String, hContext, "Two", %IDM_Two, %MF_Enabled
Menu Add String, hContext, "Three", %IDM_Three, %MF_Enabled
Menu Add String, hContext, "Exit", %IDM_Exit, %MF_Enabled
End Sub
Sub Setting_INI(Task$)
Local tempz, INIFileName As Asciiz*%Max_Path
INIFileName = EXE.Path$ + "app.ini"
If Task$ = "get" Then
GetPrivateProfileString "All", "MenuValue", Str$(%IDM_One), tempz, %Max_Path, INIFileName : MenuValue = Val(tempz)
ElseIf Task$ = "save" Then
WritePrivateProfileString "All", "MenuValue", (Str$(MenuValue)), INIFileName
End If
End Sub
Sub SetMenus
Select Case MenuValue
Case 1 : CheckMenuRadioItem hContext, %IDM_One, %IDM_Three, %IDM_One, %MF_ByCommand
Case 5 : CheckMenuRadioItem hContext, %IDM_One, %IDM_Three, %IDM_Two, %MF_ByCommand
Case 10 : CheckMenuRadioItem hContext, %IDM_One, %IDM_Three, %IDM_Three, %MF_ByCommand
End Select
End Sub
'gbs_01040
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm