Solved

Programmatically add files to Start Menu's "My Recent Documents" list

Posted on 2008-10-15
9
1,040 Views
Last Modified: 2013-11-20
How do I add files to the "My Recent Documents" list from within an MFC Windows C++ program ?

Whenever I Open/Save a file using the CFileDialog, it adds it OK. Whenever I open my application by clicking on one of its specific file types, it adds it OK. All this happens without me doing anything special.

When I open a file with drag/drop onto my application, that filename does not get added to the MRD list.

I am maintaining my own in-program Most Recently Used File list, and that works OK.
It's the MRD list on the Start Menu that I'm interested in.

Actually, this might not be an MFC thing; it might be a pure Windows API thing.
0
Comment
Question by:muttley3141
  • 3
  • 3
  • 3
9 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22724812
This KB article might be helpful http://support.microsoft.com/kb/243751
0
 
LVL 1

Author Comment

by:muttley3141
ID: 22725559
LOP: No, this isn't what I'm looking for. I'd already come across that Knowledge Base article. That article deals with handling the PROGRAM's MRU List. I'm interested in manipulating the one on the Start Menu. It's possible that using the former using the method implied in that KB Article automatically manages the latter. However, I'm managing this sort of thing myself.

I'd've thought there'd be a simple BOOL WINAPI AddFileToRecentDocumentsList(LPCTSTR *s) but there isn't.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22726752
Sorry, I am also not aware of such a function in the Windows API, the closest other information that might possibly be helpful is a C# project at http://www.codeproject.com/KB/cs/PruneMyRecentDocuments.aspx and a thread at http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/e48e9e81-2a78-4a07-a427-5ff0ced74d3d/ however someone might have a better suggestion.
0
 
LVL 1

Author Comment

by:muttley3141
ID: 22726958
Yes, I thought about manipulating the registry directly but I'm not convinced it's going to be in the same place or in the same format on all versions of Windows.

I'd already seen that piece on The Code Project.

I think what I'm going to try and do is to create a dummy CFileDialog, keep it invisible, and see if that "works" as a surrogate to writing to the MRD list.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22741662

SHAddToRecentDocs Function


Adds a document to the Shell's list of recently used documents or clears all documents from the list.
Syntax
void SHAddToRecentDocs(      
    UINT uFlags,SHAddToRecentDocs Function   
Adds a document to the Shell's list of recently used documents or clears all  documents from the list.  
Syntax void SHAddToRecentDocs(      
    UINT uFlags,
    LPCVOID pv
); 
Parameters  uFlags [in] Flag that indicates the meaning of the pv parameter. This flag  can be one of the following values:  SHARD_PATH The pv parameter points to a null-terminated string with the path and  file name of the object. SHARD_PIDL The pv parameter points to a pointer to an item identifier list  (PIDL) that identifies the document's file object. PIDLs that identify non-file  objects are not allowed. pv [in] A pointer to either a null-terminated string with the path and file  name of the document, or a PIDL that identifies the document's file object. Set  this parameter to NULL to clear all documents from the list.  

    LPCVOID pv
);

Open in new window

Parameters
uFlags[in] Flag that indicates the meaning of the pv parameter. This flag can be one of the following values: SHARD_PATHThe pv parameter points to a null-terminated string with the path and file name of the object.SHARD_PIDLThe pv parameter points to a pointer to an item identifier list (PIDL) that identifies the document's file object. PIDLs that identify non-file objects are not allowed.pv[in] A pointer to either a null-terminated string with the path and file name of the document, or a PIDL that identifies the document's file object. Set this parameter to NULL to clear all documents from the list.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 165 total points
ID: 22741675
Lets see if removing the formatting helps



SHAddToRecentDocs Function  
Adds a document to the Shell's list of recently used documents or clears all  documents from the list.  
Syntax void SHAddToRecentDocs(      
    UINT uFlags,
    LPCVOID pv
);
Parameters  uFlags [in] Flag that indicates the meaning of the pv parameter. This flag  can be one of the following values:  SHARD_PATH The pv parameter points to a null-terminated string with the path and  file name of the object. SHARD_PIDL The pv parameter points to a pointer to an item identifier list  (PIDL) that identifies the document's file object. PIDLs that identify non-file  objects are not allowed. pv [in] A pointer to either a null-terminated string with the path and file  name of the document, or a PIDL that identifies the document's file object. Set  this parameter to NULL to clear all documents from the list.  
0
 
LVL 19

Assisted Solution

by:LordOfPorts
LordOfPorts earned 35 total points
ID: 22742503
Respect to Andy for finding the function http://msdn.microsoft.com/en-us/library/bb762105(VS.85).aspx
0
 
LVL 1

Author Comment

by:muttley3141
ID: 22742955
OK. Thank you Andy. It wasn't an obviously-named function, which is what caused me to miss it.
Thank you also LOP for getting the KB article, which references the other interesting SH.. functions.

BTW, does anybody know if it's possible to leave a "tip", i.e. leaving more points than originally agreed, if some contributor goes A+BTCoD, such as providing lots of background knowledge that turned out to be very useful, but which was not explicitly asked for in the original question ?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22743066
Yeah, just increase the points for the question BEFORE hitting the accept button.

If you want afterwards then post a request in community support for the question to be reopened and your reasons why.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to stop a Microsoft scheduled Windows 10 upgrade 16 108
dog bark java program 15 82
ShiftLeft challenge 21 66
scoreUp challenge 14 48
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now