CMRUComboBox was written by Michael Dunn. Copyrighted and all that stuff. You can use it as you see fit as long as the copyright notices are kept in the source code.
Since the MFC class CRecentFileList has several parameters that can be set only in the constructor, CMRUComboBox keeps a CRecentFileList* variable, and allocates a CRecentFileList object in several circumstances. You do not need to worry about this dynamic allocation, since CMRUComboBox takes care of it, but it may be an issue in low-memory situations. CMRUComboBox methods catch CMemoryExceptions when possible, print out a debug message, and then re-throw the exception so that your code or the MFC framework can catch it and act accordingly.
CMRUComboBox uses CStrings and LPCTSTRs, so it should compile and run fine in Unicode. However, I do not have an NT box handy so I have not personally tested it in a Unicode app.
This is the default constructor. It calls the CComboBox constructor and initializes some member variables.
The class destructor saves the MRU to the registry if the AutoSaveOnDestroy flag is TRUE, and frees any memory used by the MRU.
Remarks
See also SetAutoSaveOnDestroy()
BOOL AddToMRU ( LPCTSTR szItem )
Parameters
szItem: String to be added to the MRU list. This may not be NULL.
Return value
TRUE if successful, FALSE if not. This function can fail if a new CRecentFileList object could not be allocated, or the MRU parameters were not valid.
Parameters
None.
Return value
None.
Remarks
This function removes all strings from the MRU, but does not update the combobox control. Call RefreshCtrl() to update the combobox.
Parameters
None.
Return value
TRUE if successful, FALSE if not. This function can fail if a new CRecentFileList object could not be allocated, or the MRU parameters were not valid.
Parameters
None.
Return value
TRUE if successful, FALSE if not. This function can fail if no CRecentFileList object has been allocated yet (meaning there was no MRU to save), if a new CRecentFileList object could not be allocated, or if the MRU parameters were not valid.
void SetMRURegKey ( LPCTSTR szRegKey )
Parameters
szRegKey: The registry key (or INI file section) in which the MRU will be saved. If you are saving settings to the registry (by calling CWinApp::SetRegistryKey()) then the registry key you specify will be created in HKCU\Software\<SetRegistryKey() parameter>\<your app name>.
Return Value
None.
const CString& GetMRURegKey() const
Parameters
None.
Return Value
A CString containing the current registry key (or INI file section) in which the MRU will be saved.
BOOL SetMRUValueFormat ( LPCTSTR szValueFormat )
Parameters
szValueFormat: A format string to use when creating registry or INI file entries. This string must not be NULL and must contain "%d".
Return Value
TRUE if the format is valid as described above, FALSE if not.
const CString& GetMRUValueFormat()
const
Parameters
None.
Return Value
A CString containing the current value format.
int SetMaxMRUSize ( int nMaxSize )
Parameters
nMaxSize: The new maximum size for the MRU.
Return Value
If successful, the previous max size of the MRU is returned. If there was no previous MRU, 0 is returned. If a new CRecentFileList couldn't be allocated, then -1 is returned.
Remarks
This function always results in a new CRecentFileList object being allocated immediately. If the new size is greater than or equal to the previous size, the previous MRU items are retained. If the new size is smaller, then the oldest items in the previous MRU are discarded. For example, if an MRU is sized from 5 down to 3, then the oldest 2 items will be discarded.
Parameters
None.
Return Value
The current maximum size of the MRU list.
BOOL SetAutoRefreshAfterAdd ( BOOL
bAutoRefresh
)
Parameters
bAutoRefresh: Pass TRUE to have the CMRUComboBox automatically call RefreshCtrl() after a successful call to AddToMRU(). Pass FALSE to disable this behavior.
Return Value
The previous setting of this flag.
Remarks
This flag defaults to FALSE.
BOOL SetAutoSaveAfterAdd ( BOOL bAutoSave )
Parameters
bAutoSave: Pass TRUE to have the CMRUComboBox automatically call SaveMRU() after a successful call to AddToMRU(). Pass FALSE to disable this behavior.
Return Value
The previous setting of this flag.
Remarks
This flag defaults to FALSE.
BOOL SetAutoSaveOnDestroy ( BOOL bAutoSave )
Parameters
bAutoSave: Pass TRUE to have the CMRUComboBox automatically call SaveMRU() from the destructor. Pass FALSE to disable this behavior.
Return Value
The previous setting of this flag.
Remarks
This flag defaults to TRUE. If the call to SaveMRU() in the destructor fails, a debug message is printed.
Parameters
None.
Return Value
None.
Remarks
This function removes all strings from the list box portion of the combobox control, and rebuilds it to match the current contents of the MRU. The text in the edit box portion of the control is preserved.