Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Showing recently opened files and paths
#1
I like how QM shows the (resent files) when you press File->Recent Files. Could you give me an example of how you do this?

Function DialogWithMenu
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str rea3
if(!ShowDialog("DialogWithMenu" &DialogWithMenu &controls 0 0 0 0 0 0 0 "dialog.ico" "DialogWithMenu")) ret

;BEGIN DIALOG
;0 "" 0x10CF0A44 0x100 0 0 294 190 "Dialog"
;3 RichEdit20A 0x54233044 0x200 0 0 294 190 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2020009 "*" ""

ret
;messages
sel message
,case WM_INITDIALOG
,
,case WM_SIZE
,RECT r; GetClientRect(hDlg &r)
,siz r.right r.bottom id(3 hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,;menu items:
,case 101    ;; Menu File>>Open
,,str s fileTxt
,,if OpenSaveDialog(0 s "Text files[]*.txt[]Image files[]*.bmp;*.gif[]All Files[]*.*[]")
,,,fileTxt.getfile(s)
,,,fileTxt.setwintext(id(3 hDlg))
,case 103 out "Cut"
,case 104 out "Select All"
,case 105 out "Help"
,
,case IDOK
,case IDCANCEL
ret 1

;BEGIN MENU
;>&File
,;&Open : 101 0 0 Co
,;-
,;>&Recent
,,;Empty : 102 0 3
,,;<
,;<
;>&Edit
,;Cu&t : 103 0 0 Cx
,;-
,;Select &All : 104 0 0 Ca
,;<
;&Help : 105 0
;END MENU
.
#2
Function dlg_recent_files_menu
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

def X48_RFM_MAXITEMS 2 ;;max number of recent files in menu. Change this.
def X48_RFM_MENUFIRSTID 10000 ;;change only if conflicts with some id, eg control id
def X48_RFM_REGKEY "\mycompany\myprogram" ;;change to your registry key
def X48_RFM_REGVALUE "recent" ;;change to your registry value

str controls = "3"
str rea3
if(!ShowDialog("dlg_recent_files_menu" &dlg_recent_files_menu &controls 0 0 0 0 0 0 0 "dialog.ico" "dlg_recent_files_menu")) ret

;BEGIN DIALOG
;0 "" 0x10CF0A44 0x100 0 0 294 190 "Dialog"
;3 RichEdit20A 0x54233044 0x200 0 0 294 190 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2020009 "*" ""

ret
;messages
sel message
,case WM_INITDIALOG
,;get handles of all submenus that we'll need (eg with WM_INITMENUPOPUP)
,type X48_POPUPMENUS menubar file file_recent ;;popup menu handles. Add more if needed.
,X48_POPUPMENUS- pm
,pm.menubar=GetMenu(hDlg)
,pm.file=MenuFindSubMenu(pm.menubar "&File" 1)
,pm.file_recent=MenuFindSubMenu(pm.file "&Recent" 1)
,
,case WM_INITMENUPOPUP
,if(wParam=pm.file_recent)
,,RfmCreateMenu wParam X48_RFM_REGKEY X48_RFM_REGVALUE X48_RFM_MENUFIRSTID
,
,case WM_SIZE
,RECT r; GetClientRect(hDlg &r)
,siz r.right r.bottom id(3 hDlg)
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,;menu items:
,case 101 ;; Menu File>>Open
,,str s fileTxt
,,if OpenSaveDialog(0 s "Text files[]*.txt[]Image files[]*.bmp;*.gif[]All Files[]*.*[]")
,,,;open
,,,fileTxt.getfile(s)
,,,fileTxt.setwintext(id(3 hDlg))
,,,
,,,RfmAddFile s X48_RFM_REGKEY X48_RFM_REGVALUE X48_RFM_MAXITEMS
,case 103 out "Cut"
,case 104 out "Select All"
,case 105 out "Help"
,
,case else
,if(wParam>=X48_RFM_MENUFIRSTID and wParam<X48_RFM_MENUFIRSTID+X48_RFM_MAXITEMS)
,,MenuGetString pm.file_recent wParam &s
,,if(dir(s)) goto open
,
,case IDOK
,case IDCANCEL
ret 1

;BEGIN MENU
;>&File
,;&Open : 101 0 0 Co
,;-
,;>&Recent
,,;Empty : 102 0 3
,,;<
,;<
;>&Edit
,;Cu&t : 103 0 0 Cx
,;-
,;Select &All : 104 0 0 Ca
,;<
;&Help : 105 0
;END MENU

Function RfmAddFile
Code:
Copy      Help
;/
function $_file $regkey $regname nmax

str s; int i
rget s regname regkey
ARRAY(str) a=s ;;list -> array
for(i a.len-1 -1 -1) if(a[i]~_file) a.remove(i) ;;remove duplicates
rep() if(a.len>=nmax) a.remove(0); else break ;;limit number of items
a[]=_file ;;add _file
s=a ;;array -> list
rset s regname regkey

Function RfmCreateMenu
Code:
Copy      Help
;/
function hmenu $regkey $regname firstitemid

MenuDeleteItems hmenu
str s; int i
rget s regname regkey
ARRAY(str) a=s
for i 0 a.len
,AppendMenuW hmenu 0 firstitemid+i @a[a.len-i-1]

Function MenuDeleteItems
Code:
Copy      Help
;/
function hmenu [nLeave]
//nLeave: if negative, delete from beginning and leave -nLeave at the end of the menu

int i=GetMenuItemCount(hmenu);
if(nLeave<0) i+=nLeave; nLeave=0;
for(i i-1 nLeave-1 -1) DeleteMenu(hmenu, i, MF_BYPOSITION);

Function MenuFindSubMenu
Code:
Copy      Help
;/
function# hmenu $itemstring [flags] ;;flags: 1 error if not found

int i j; str s
for i 0 GetMenuItemCount(hmenu)
,MenuGetString hmenu -i &s
,j=findc(s 9); if(j>=0) s.fix(j)
,if(s=itemstring) ret GetSubMenu(hmenu i)
if(flags&1) end "menu item '%s' not found" 0 itemstring
#3
I am using QM version 2.3.0.3

I do not have function – MenuFindSubMenu

Error in "dlg_recent_files_menu /1027"odlg_recent_files_menu: unknown identifier.
#4
forgot it, now added
#5
Fantastic Thank You


Forum Jump:


Users browsing this thread: 1 Guest(s)