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"
#Include "CommCtrl.inc"
%IDC_Toolbar = 501
%IDM_History1 = 601
%IDM_History2 = 602
%IDM_History3 = 603
%IDM_History4 = 604
%IDM_History5 = 605
%IDM_Sep = 606
%IDM_ClearMRU = 607
%IDT_Open = 700
Global hDlg,hToolbar,hPopupHistory As Dword
Global CFN, History1, History2, History3, History4, History5 As String
Function PBMain() As Long
Dialog New Pixels, 0, "MRU Demonstration",500,300,500,200, %WS_OverlappedWindow To hDlg
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0, %TbStyle_Tooltips Or %TbStyle_Flat Or %WS_Border Or %WS_Child
Control Handle hDlg, %IDC_Toolbar To hToolbar
SendMessage hToolbar, %TB_SETEXTENDEDSTYLE, 0, %TBSTYLE_EX_DRAWDDARROWS
Toolbar Add Button hDlg, %IDC_Toolbar, 1, %IDT_Open, %TbStyle_Button Or %TbStyle_DropDown, "Open"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x,y As Long, nmtb As TBNOTIFY Ptr, rc As RECT
Local P As ToolTipText Ptr, temp$, pt As Point, pLVDI As LV_DISPINFO Ptr
Select Case Cb.Msg
Case %WM_InitDialog
Settings_INI "get"
Menu New PopUp To hPopupHistory
AddCFNToHistory
Case %WM_Command
Select Case Cb.Ctl
Case %IDT_Open : SelectCFN : AddCFNToHistory
Case %IDM_History1 : CFN = History1 : AddCFNToHistory
Case %IDM_History2 : CFN = History2 : AddCFNToHistory
Case %IDM_History3 : CFN = History3 : AddCFNToHistory
Case %IDM_History4 : CFN = History4 : AddCFNToHistory
Case %IDM_History5 : CFN = History5 : AddCFNToHistory
Case %IDM_ClearMRU : History5="" : History4="" : History3="" : History2="" : History1="" : AddCFNToHistory
End Select
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_Toolbar
Select Case Cb.NmCode
Case %TBN_DropDown
nmtb = Cb.LParam
Select Case @nmtb.iItem
Case %IDT_Open
Call SendMessage(@nmtb.hdr.hwndFrom, %TB_GETRECT, @nmtb.iItem, VarPtr(rc))
Call MapWindowPoints(@nmtb.hdr.hwndFrom, %HWND_Desktop, ByVal VarPtr(rc), 2)
Call TrackPopupMenu (hPopUpHistory, 0, rc.nLeft, rc.nBottom, 0, CbHndl, ByVal %Null)
End Select
End Select
End Select
Case %WM_Destroy
Settings_INI "save"
End Select
End Function
Sub SelectCFN
Local title$, startfolder$, filter$, startfile$, defaultext$, flags&, filevar$, countvar&
title$ = "Open File"
filter$ = "All Files" + $Nul + "*.*" + $Nul
startfolder$ = CFN
startfile$ = CFN
defaultext$ = ""
flags& = %OFN_Explorer Or %OFN_FileMustExist Or %OFN_HideReadOnly
Display Openfile hDlg, 100, 100, title$, startfolder$, filter$, startfile$, defaultext$, flags& To filevar$, countvar&
If Len(filevar$) Then CFN = LCase$(filevar$)
End Sub
Sub Settings_INI(Task$)
Local x,y As Long, xResult, yResult, tempz, INIFileName As Asciiz*%Max_Path
'defines INI file name
INIFileName = EXE.Path$ + EXE.Name$ + ".ini"
If Task$ = "get" Then
'get dialog top/left from INI file and use to set Dialog location
GetPrivateProfileString "All", "Left", "300", xResult, %Max_Path, INIFileName
GetPrivateProfileString "All", "Top", "300", yResult, %Max_Path, INIFileName
Dialog Set Loc hDlg, Val(xResult$), Val(yResult$) 'left/top
'get dialog width/height from INI file and use to set Dialog size
GetPrivateProfileString "All", "Width", "300", xResult, %Max_Path, INIFileName
GetPrivateProfileString "All", "Height", "200", yResult, %Max_Path, INIFileName
Dialog Set Size hDlg,Val(xResult$), Val(yResult$) 'width/height
'get value for string variables
GetPrivateProfileString "All", "CFN" , "", tempz, %Max_Path, INIFileName : CFN = tempz
GetPrivateProfileString "All", "History1", "", tempz, %Max_Path, INIFileName : History1 = tempz
GetPrivateProfileString "All", "History2", "", tempz, %Max_Path, INIFileName : History2 = tempz
GetPrivateProfileString "All", "History3", "", tempz, %Max_Path, INIFileName : History3 = tempz
GetPrivateProfileString "All", "History4", "", tempz, %Max_Path, INIFileName : History4 = tempz
GetPrivateProfileString "All", "History5", "", tempz, %Max_Path, INIFileName : History5 = tempz
ElseIf Task$ = "save" Then
If IsFile(INIFileName) Then Kill INIFileName
'save dialog size/location unless minimized or maximized
If IsFalse(IsIconic(hDlg) Or IsZoomed(hDlg)) Then
Dialog Get Loc hDlg To x,y
WritePrivateProfileString "All", "Left", Str$(x), INIFileName
WritePrivateProfileString "All", "Top", Str$(y), INIFileName
Dialog Get Size hDlg To x,y
WritePrivateProfileString "All", "Width", Str$(x), INIFileName
WritePrivateProfileString "All", "Height", Str$(y), INIFileName
End If
'save string variables
WritePrivateProfileString "All", "CFN", (CFN), INIFileName
WritePrivateProfileString "All", "History1", (History1), INIFileName
WritePrivateProfileString "All", "History2", (History2), INIFileName
WritePrivateProfileString "All", "History3", (History3), INIFileName
WritePrivateProfileString "All", "History4", (History4), INIFileName
WritePrivateProfileString "All", "History5", (History5), INIFileName
End If
End Sub
Sub AddCFNToHistory
Menu Delete hPopupHistory, ByCmd %IDM_History1
Menu Delete hPopupHistory, ByCmd %IDM_History2
Menu Delete hPopupHistory, ByCmd %IDM_History3
Menu Delete hPopupHistory, ByCmd %IDM_History4
Menu Delete hPopupHistory, ByCmd %IDM_History5
Menu Delete hPopupHistory, ByCmd %IDM_ClearMRU
Menu Delete hPopupHistory, 1 'remove separator after all other menu items
If CFN = History1 Then
'nothing
ElseIf CFN = History2 Then
History2 = History1 : History1 = CFN
ElseIf CFN = History3 Then
History3 = History2 : History2 = History1 : History1 = CFN
ElseIf CFN = History4 Then
History4 = History3 : History3 = History2 : History2 = History1 : History1 = CFN
Else
History5 = History4 : History4 = History3 : History3 = History2 : History2 = History1 : History1 = CFN
End If
If Len(Dir$(History1)) Then Menu Add String, hPopupHistory, History1, %IDM_History1, %MF_Enabled
If Len(Dir$(History2)) Then Menu Add String, hPopupHistory, History2, %IDM_History2, %MF_Enabled
If Len(Dir$(History3)) Then Menu Add String, hPopupHistory, History3, %IDM_History3, %MF_Enabled
If Len(Dir$(History4)) Then Menu Add String, hPopupHistory, History4, %IDM_History4, %MF_Enabled
If Len(Dir$(History5)) Then Menu Add String, hPopupHistory, History5, %IDM_History5, %MF_Enabled
Menu Add String, hPopupHistory, "-", 0, %MF_Enabled 'always add this
Menu Add String, hPopupHistory, "Clear", %IDM_ClearMRU, %MF_Enabled 'always add this
End Sub
'gbs_00747
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm