Link to home
Start Free TrialLog in
Avatar of muttley3141
muttley3141

asked on

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.
Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

This KB article might be helpful http://support.microsoft.com/kb/243751
Avatar of muttley3141
muttley3141

ASKER

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.
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.
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.
Avatar of AndyAinscow

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.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ?
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.