By default, a basic MFC C++ project in Visual Studio 2010 will store all its workspace settings in the HKCU registry hive under a user-configurable key name. This includes last window size/position, ribbon settings, status bar, etc.
How can you disable this feature completely so as to not write to the registry at all?
I tried not setting SetRegistryKey()
, which gave me a debug assertion from the framework on first read/write to registry. SetRegistryKey((LPCTSTR)NULL)
gave the same results. SetRegistryBase()
seems to have no effect. No other methods in CWinApp
/CWinAppEx
seem to help.
Best Answer
Edit: My original answer was wrong. I have edited the answer.
You can tell MFC to store settings in an(Update: That only works if you are not using.ini
file instead of the registry. See this previous answer.CWinAppEx
.)If you want to prevent MFC from saving some of the state of the menus and toolbars
altogether, add the following to your app’s constructor:The
m_bSaveState
member is only defined if your app is derived fromCWinAppEx
.Alternatively, you can override
CWinAppEx::SaveState
andCWinAppEx::LoadState
.To eliminate the
WindowPlacement
registry key, overrideCWinAppEx::StoreWindowPlacement
.You may still get other registry entries being written. A complete solution would involve subclassing
CSettingsStore
and then, in your application, callingCSettingsStoreSP::SetRuntimeClass
. (See this for more information.) This is fairly difficult because there are a whole bunch of virtual functions you will have to override in your customCSettingsStore
class.