• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1136
  • Last Modified:

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

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
muttley3141
Asked:
muttley3141
  • 3
  • 3
  • 3
2 Solutions
 
LordOfPortsCommented:
This KB article might be helpful http://support.microsoft.com/kb/243751
0
 
muttley3141Author Commented:
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
 
LordOfPortsCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
muttley3141Author Commented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:

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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
LordOfPortsCommented:
Respect to Andy for finding the function http://msdn.microsoft.com/en-us/library/bb762105(VS.85).aspx
0
 
muttley3141Author Commented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now