📄 faq51.htm
字号:
<HTML>
<HEAD>
<TITLE>Add a file to the list of recently opened files</TITLE>
<META NAME="Author" CONTENT="Harold Howe">
</HEAD>
<BODY BGCOLOR="WHITE">
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">
<TR>
<TD>
<H3>
Add a file to the list of recently opened files
</H3>
<P>
Windows 95 and Windows NT 4 allow users to re-open previous files by selecting
the Documents menu option under the Start taskbar menu. For example, if you open
a document in Microsoft Word, the filename is added to the recently opened
documents list so you can access the file from the taskbar. To add a document to
the list of recently opened files, use the <TT>SHAddToRecentDocs</TT> API function.
Here is an example:
<pre>
<font color="green">#include <shlobj.h></font>
<b>...</b>
SHAddToRecentDocs<b>(</b>SHARD_PATH<b>,</b> <font color="blue">"c:\\cbuilder\\readme.hlp"</font><b>)</b><b>;</b>
</pre>
<P>
<B>Note:</B> The first argument to <TT>SHAddToRecentDocs</TT> should be either
<TT>SHARD_PATH</TT> or <TT>SHARD_PIDL</TT>. If you want to pass the filename as a
string, use the <TT>SHARD_PATH</TT> value. <TT>SHARD_PIDL</TT> allows you to pass
a pointer to an <TT>ITEMIDLIST</TT> (the <TT>ITEMIDLIST</TT> structure relates to shell
programming with the shell namespace functions; <TT>SHGetDesktopFolder</TT>,
<TT>SHGetMalloc</TT> and friends).
</P>
<P>
<B>Note:</B> You can clear all of the items in the list of recent files by passing <TT>NULL</TT>
as the second example.
</P>
<pre>
<font color="navy">// Clear out all documents in the list</font>
SHAddToRecentDocs<b>(</b>SHARD_PATH<b>,</b> NULL<b>)</b><b>;</b>
</pre>
<P>
<B>Note:</B> While testing the code for this FAQ, I found out that the shell will not allow you to add a file to
the recent files list if that file does not have an associated program. For example, I tried to add the file
<TT>UNIT1.~H</TT> to the list. Since files with the <TT>~H</TT> extension don't have a registered program that opens
them, the shell refused to put <TT>UNIT1.~H</TT> in the list. This makes sense. When you select a file from the recent
files list, Windows opens that file with its associated viewer. It can't open a file that has no associated viewer.
This behavior was witnessed on Windows NT 4.
</P>
<P>
<B>Note:</B> There is a a problem with <TT>shlobj.h</TT> and BCB 5. If you include <TT>shlobj.h</TT> in a BCB5 GUI project,
you may get a strange compiler error, such as this:
</P>
<PRE>
[C++ Error] shlobj.h(1762): E2238 Multiple declaration for 'FVSHOWINFO'
[C++ Error] shlobj.h(1936): E2238 Multiple declaration for 'FOLDERSETTINGS'
[C++ Error] shlobj.h(3717): E2238 Multiple declaration for 'DESKBANDINFO'
[C++ Error] shlobj.h(4808): E2238 Multiple declaration for 'SHELLFLAGSTATE'
</PRE>
<P>
You can eliminate these errors by adding the string NO_WIN32_LEAN_AND_MEAN to the conditional defines of your project.
To see what impact this has, open the file <TT>vcl0.h</TT> in a text editor.
</P>
</TD> </TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -