Last VFP files opened & Windows recent
*1*This programm uses the resource foxuser.dbf who memorize lot of vfp resources.
*The code creates a toolbar showing the last opened vfp files to re use.
*The toolbar created is docked in the vfp toolbar.For execute: do yMemo.
*for closing, drag the toolbar on the window command and click on (x) or put 'clea all' in window command.
*can put it at vfp start in tools/option (start program)-see the photo below.
*yMemo.prg
*Begin code
If !Pemstatus(_Screen,'myBar',5)
_Screen.AddProperty('myBar',.Null.)
Endif
If Vartype(_Screen.myBar) <> 'O'
_Screen.myBar = Newobject('myBarClass')
_Screen.myBar.Dock(0)
Endif
_Screen.myBar.Show()
Return
Define Class myBarClass As Toolbar
Caption = "yRecents"
Procedure Init
DoDefault()
This.AddObject("combo0","combo0")
This.AddObject("cmdRefresh","cmdRefresh")
This.AddObject("cmdMRU","cmdMRU")
crit="MRUL"
This.SetUpButtons()
Endproc
Procedure SetUpButtons
Local llSuccess, lcErrorMessage, lnErrorIcon
This.Visible=.F.
llSuccess = .T.
lcErrorMessage = ""
lnErrorIcon = 16
Local laResult[1], loException As Exception
Do Case
Case This.combo0.Value="PJX"
crit="MRUL"
Case This.combo0.Value="PRG"
crit="MRUB"
Case This.combo0.Value="SCX"
crit="MRUH"
Case This.combo0.Value="MNX"
crit="MRUE"
Case This.combo0.Value="DBF"
crit="MRUS"
Endcase
If m.llSuccess
Try
Select Data ;
FROM (Sys(2005)) Where Id=crit Into Array laResult
Catch To loException
llSuccess = .F.
Endtry
Endif
Local lnItem, lcItem
If m.llSuccess
lcList = laResult[1]
lcList = Strtran(m.lcList,Chr(0),Chr(44))
lcList = Strtran(m.lcList,Chr(4),Chr(44))
lcList = Strtran(m.lcList,Chr(32),Chr(44))
This.cmdMRU.Clear
For lnItem = 1 To Getwordcount(m.lcList,Chr(44))
lcItem = Getwordnum(m.lcList,m.lnItem,Chr(44))
If File(m.lcItem,1)
This.cmdMRU.AddItem(m.lcItem)
Endif
Endfor
Endif
This.Visible=.T.
Endproc
Enddefine
Define Class combo0 As ComboBox
Left=0
Height=24
Width=50
FontSize=8
ItemTips=.F.
Style=2
ToolTipText="Memo programs opened"
Visible=.T.
Procedure Init
This.AddItem("PJX")
This.AddItem("PRG")
This.AddItem("SCX")
This.AddItem("MNX")
This.AddItem("DBF")
This .ListIndex=1
Endproc
Procedure Click
This.Parent.CMDRefresh.Click
Endproc
Enddefine
Define Class cmdMRU As ComboBox
Left=51
Height=24
FontSize=8
ItemTips=.T.
Style=2
Visible=.T.
Procedure Init
This .ListIndex=1
Endproc
Procedure Click
Do Case
Case Lower(Justext(Alltrim(This.Value)))="pjx"
Modify Project (This.Value)
Case Lower(Justext(Alltrim(This.Value)))="prg"
Modi Comm (This.Value)
Case Lower(Justext(Alltrim(This.Value)))="scx"
Modify Form (This.Value)
Case Lower(Justext(Alltrim(This.Value)))="mnx"
Modi Menu (This.Value)
Case Lower(Justext(Alltrim(This.Value)))="dbf"
Use (This.Value) Again
Brow
Endcase
Endproc
Enddefine
Define Class CMDRefresh As CommandButton
Left=52
Height=24
FontSize=8
Caption="REFRESH"
ForeColor=Rgb(0,192,0)
AutoSize=.T.
Visible=.F.
Procedure Click
This.Parent.SetUpButtons()
Endproc
Enddefine
*End code
*2)*The special folder "recents" store all recent files or folder used by the user.
*The physical location depends on the windows OS used.
in win8.1 its "%APPDATA%\Microsoft\Windows\Recent\"
*in my machine,it is "c:\Users\yousfi\AppData\Roaming\Microsoft\Windows\Recent\"
*this code can locate for this special folder and list files stored to re use if necessary.
the files are all used by windows including vfp files.
*VFP lists only the last opened projects in menu (configurable in tools/options/)
*see this ref:http://yousfi.over-blog.com/2015/02/the-windows-special-folders.html
*Begin code
Publi yform
yform=Newobject("yRecents")
yform.Show
Read Events
Return
*
Define Class yRecents As Form
BorderStyle = 2
Height = 327
Width = 620
ShowWindow = 2
AutoCenter = .T.
Caption = "Recent files opened"
MaxButton = .F.
Name = "Form1"
Add Object combo1 As ComboBox With ;
Anchor = 0, ;
Height = 32, ;
Left = 163, ;
Top = 4, ;
Width = 133, ;
Name = "Combo1"
Add Object grid1 As Grid With ;
FontBold = .T., ;
FontSize = 10, ;
Anchor = 0, ;
DeleteMark = .F., ;
GridLines = 0, ;
Height = 263, ;
Left = 3, ;
RecordSource = ['"zcurs"'], ;
RowHeight = 19, ;
Top = 43, ;
Width = 610, ;
ForeColor = Rgb(0,0,255), ;
Name = "Grid1"
Add Object label1 As Label With ;
FontBold = .T., ;
FontSize = 12, ;
Anchor = 0, ;
Caption = "", ;
Height = 25, ;
Left = 398, ;
Top = 3, ;
Width = 156, ;
ForeColor = Rgb(255,0,0), ;
BackColor = Rgb(255,255,0), ;
Name = "Label1"
Add Object label2 As Label With ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Click on cfile to open cfile link (file or folder)with associated application", ;
Height = 17, ;
Left = 96, ;
Top = 310, ;
Width = 386, ;
ForeColor = Rgb(255,0,0), ;
Name = "Label2"
Procedure my
Lparameters nButton, nShift, nXCoord, nYCoord
&&shellexecute
Sele zcurs
If Messagebox("open the link :"+Justfname(cfilename)+" ?",4+64+4096)=6
result = ShellExecute(0, "open", cfilename,"","",1)
Endi
Endproc
Procedure Init
Set Date Long
With Thisform.combo1
.Value="*.*"
.Click()
Endwith
Endproc
Procedure Load
Close Data All
Declare Integer ShellExecute In SHELL32.Dll Integer nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow
Endproc
Procedure combo1.Click
m.ext=Lower(This.Value)
Local objShell,objFolder,objFolderItem
objShell = Createobject("Shell.Application")
objFolder = objShell.Namespace( 0x08)
objFolderItem = objFolder.Self
Local m.yrep
m.yrep=Addbs(objFolderItem.Path)
objShell=Null
objFolder=Null
objFolderItem=Null
*m.yrep="%APPDATA%\Microsoft\Windows\Recent\"
*win8.1 : m.yrep="c:\Users\yousfi\AppData\Roaming\Microsoft\Windows\Recent\"
gnbre=Adir(gabase,m.yrep+"*.*")
Create Cursor ycurs (cfile c(100),cfilename c(150),modified c(90))
For i=1 To gnbre
xcfilename=m.yrep+Substr(gabase(i,1),1,Len(gabase(i,1))-4)
xfile=Justfname(m.xcfilename)
xmodified=Ttoc(gabase(i,3))+" "+gabase(i,4)
Insert Into ycurs Values(xfile,xcfilename+".LNK",xmodified)
Endfor
If !m.ext=="*.*"
Sele * From ycurs Where Lower(Justext(cfile))==Lower(m.ext) Into Cursor zcurs
Sele zcurs
Else
Sele * From ycurs Into Cursor zcurs
Endi
Count To xr
With Thisform.grid1
.RecordSource=""
.RecordSource="zcurs"
.column2.Visible=.F.
.column1.Width=300
.column3.Width=300
.RecordSourceType=1
.column1.SetAll("mousepointer",15,"column")
.SetAll("backcolor",Rgb(100,10,120),"header")
.SetAll("forecolor",255,"header")
.Themes=.F.
.DeleteMark=.F.
.GridLines=0
.HeaderHeight=28
.RowHeight=18
.SetAll("fontbold",.T.,"header")
.SetAll("fontsize",14,"header")
.SetAll("DynamicBackColor","IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255) , RGB(0,255,0))", "Column")
Locate
.Refresh
Endwith
Thisform.label1.Caption=Trans(xr)+" files ("+m.ext+")"
Bindevent(Thisform.grid1.column1.text1,;
"mousedown",Thisform,"my")
Endproc
Procedure combo1.Init
With This &&can add other extensions
.AddItem("pjx")
.AddItem("prg")
.AddItem("vcx")
.AddItem("frx")
.AddItem("txt")
.AddItem("htm")
.AddItem("html")
.AddItem("exe")
.AddItem("scx")
.AddItem("mpr")
.AddItem("mnx")
.AddItem("h")
.AddItem("*.*")
.ListIndex=1
.Style=2
Endwith
Endproc
Procedure destroy
clea events
endproc
Enddefine
*
*End code
*how to access programmatly to the win folder C:\Users\yousfi\AppData\Roaming\Microsoft\Windows\Recent
(hardcoded path depends on the windows version)
&&shellexecute
DECLARE INTEGER ShellExecute IN SHELL32.DLL INTEGER nWinHandle,;
STRING cOperation,;
STRING cFileName,;
STRING cParameters,;
STRING cDirectory,;
INTEGER nShowWindow
result = ShellExecute(0, "open", "shell:recent","","",1)
or with wscript
local oshell
oshell=newObject("wscript.shell")
oshell.run["shell:recent"]
oshell=null