Solved

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

Posted on 2008-10-15
9
1,055 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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
 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
has77  challenge 9 85
Auto disconnecting Specific USB devices after an amount of time ? 6 122
Event ID: 1202 / Source: SceCli 6 107
Problem to open Excel file 15 134
Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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