CRegBinding - An alternative Registry Class
1. Automatic variable binding
Adding persistence to variables
Every value of registered variables would automatically read on startup.
On class destruction the values of the variables are written back to the registry.
2. Window state binding
Adding persistence to your CWnd object
Binding a CWnd to the CRegBinding object lets you save the window state, size and position in the registry.
How to use CRegBinding
In the Debug build the code contains many check routines that would detect improper use of the class object.
Step 1 - Place a CRegBinding member in your class declaration
In a class derived from CObject you can decide which member variables you want to bind to a CRegBinding object.Set the CRegBinding class member behind the last structure member.
For instance:
class A : public CDialog // (CWnd)
{
int a;
CByteArray b;
CString c;
DWORD dw;
CString d;
// .
// .
// .
// .
// place the CRegBinding object here
CRegBinding rs;
A();
};
Step 2 - Make the bindings
After you have declared the class 'A' you should make the bindings in the class constructor or any other initializing member function. The third optional parameter of the Bind() function lets you specify a default value for initialization.
A::A() : rs("My section")
{
rs.Bind(a, "a", 0);
rs.Bind(dw, "DW", 0xfffffffa);
rs.Bind(b, "b");
rs.Bind(c, "C-Key", "CCC");
rs.Bind(d, "D-Key");
CreateEx( ... );
// After you have created the window, you can also bind the CWnd object
rs.Bind(this, "Persistence Window");
}
If the window or class is about to be destroyed the current values of the
variables are written back to the registry.
The Source
The library itself comes as two source files, CRegBinding.cpp and CRegBinding.h. The header defines the CRegBinding class with the following members:CRegBinding::CRegBinding(const char *section)Construct a new binding object taking the name of the section for the specified keys in the registration database
void CRegBinding::Bind(int &value, const char *name, const int def) void CRegBinding::Bind(DWORD &value, const char *name, const DWORD def) void CRegBinding::Bind(CString &value, const char *name, const char *def) void CRegBinding::Bind(CByteArray &value, const char *name, const CByteArray *def) void CRegBinding::Bind(CWnd *value, const char *name)Bind member variables of various types.
value:
The class member variable to bind.
name:
The name of the key in the registry.
def:
Optionally you can specify a default value if the key not exist.
void CRegBinding::Write(const BOOL clear)Write data explicit to the registry. The parameter specifies whether to delete all bindings.
Date Last Updated: February 5, 1999

Comments
about registry parameters...
Posted by Legacy on 08/17/2003 12:00amOriginally posted by: rezbipul
hello,
Replyafter knowing the registry functions with the help of msdn,
i encounter the primary problem:
we know registry consists of a collection of 'name = value' pairs.
eg. 'content/type = xml' (say)
i want to learn all such names and the set of valid values for each name so that when a new software (eg Adobe photoshop) is installed it is able to instruct windows to open all files of type .psd automatically in adobe photoshop. also when some .psd files are copied to another hd, windows is also able to automatically show the appropriate icon in windows explorer.
i want to ve all possible name = value pairs for registry not just content/type.
thank u.
Great!, but with XP i have a problem.
Posted by Legacy on 07/04/2002 12:00amOriginally posted by: Willem Hofmans
ReplyProblem binding CWnd properties
Posted by Legacy on 11/22/2000 12:00amOriginally posted by: Lars Hegde
ReplyGood Idea but...
Posted by Legacy on 03/07/2000 12:00amOriginally posted by: anon
Reply
PCH problems.
Posted by Legacy on 03/01/2000 12:00amOriginally posted by: Brent Mantooth
I really like this class, but I have a problem that I can't figure out. If I compile my program in debug mode everything works fine, but if I compile in release mode I get the following error
CRegBinding.cpp
D:\Code\...\CRegBinding.cpp(346) : fatal error C1010: unexpected end of file while looking for precompiled header directive
the PCH settings for debug and release are the same - any thing I should be looking for?
thanks
ReplyVery useful and easy to use.
Posted by Legacy on 12/01/1999 12:00amOriginally posted by: Robert Laumeyer
My compliments on your very nice work with this class. I have used it in several areas either as a debugger or for persistent variables. You can just drop it in and not have to worry about it.
I would like to be able to use this to store derived class members though.
I haven't ever played with Hook/UnHook so maybe I am missing something obvious.
ReplyThanks for the Class.