1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 * Base class for the registry classes.
34 * - win98 or later, win2k or later, win95 with IE4 or later, winNT4 with IE4 or later
35 * - import library Shlwapi.lib
44 * String type specific operations.
47 virtual LPCTSTR
GetPlainString (const S
& s
) const = 0;
48 virtual DWORD
GetLength (const S
& s
) const = 0;
52 /** Default constructor.
57 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
58 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
59 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
61 CRegBaseCommon(const S
& key
, bool force
, HKEY base
= HKEY_CURRENT_USER
);
64 * Removes the whole registry key including all values. So if you set the registry
65 * entry to be HKCU\Software\Company\Product\key\value there will only be
66 * HKCU\Software\Company\Product key in the registry.
67 * \return ERROR_SUCCESS or an nonzero error code. Use FormatMessage() to get an error description.
71 * Removes the value of the registry object. If you set the registry entry to
72 * be HKCU\Software\Company\Product\key\value there will only be
73 * HKCU\Software\Company\Product\key\ in the registry.
74 * \return ERROR_SUCCESS or an nonzero error code. Use FormatMessage() to get an error description.
79 * Returns the string of the last error occurred.
81 virtual S
getErrorString()
86 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
87 FORMAT_MESSAGE_FROM_SYSTEM
|
88 FORMAT_MESSAGE_IGNORE_INSERTS
,
91 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
95 return (LPCTSTR
)lpMsgBuf
;
100 typedef S StringT
; ///< used in subclass templates to specify the correct string type
103 HKEY m_base
; ///< handle to the registry base
104 S m_key
; ///< the name of the value
105 S m_path
; ///< the path to the key
106 LONG LastError
; ///< the value of the last error occurred
108 bool m_read
; ///< indicates if the value has already been read from the registry
109 bool m_force
; ///< indicates if no cache should be used, i.e. always read and write directly from registry
110 bool m_exists
; ///< true, if the registry actually exists
113 // implement CRegBaseCommon<> members
116 CRegBaseCommon
<S
>::CRegBaseCommon()
117 : m_base (HKEY_CURRENT_USER
)
120 , LastError (ERROR_SUCCESS
)
128 CRegBaseCommon
<S
>::CRegBaseCommon (const S
& key
, bool force
, HKEY base
)
132 , LastError (ERROR_SUCCESS
)
140 DWORD CRegBaseCommon
<S
>::removeKey()
146 RegOpenKeyEx (m_base
, GetPlainString (m_path
), 0, KEY_WRITE
, &hKey
);
147 return SHDeleteKey(m_base
, GetPlainString (m_path
));
151 LONG CRegBaseCommon
<S
>::removeValue()
157 RegOpenKeyEx(m_base
, GetPlainString (m_path
), 0, KEY_WRITE
, &hKey
);
158 return RegDeleteValue(hKey
, GetPlainString (m_key
));
163 * Base class for MFC type registry classes.
166 #ifdef __CSTRINGT_H__
167 class CRegBase
: public CRegBaseCommon
<CString
>
172 * String type specific operations.
175 virtual LPCTSTR
GetPlainString (const CString
& s
) const {return (LPCTSTR
)s
;}
176 virtual DWORD
GetLength (const CString
& s
) const {return s
.GetLength();}
180 /** Default constructor.
185 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
186 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
187 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
189 CRegBase(const CString
& key
, bool force
, HKEY base
= HKEY_CURRENT_USER
);
192 * Returns the string of the last error occurred.
194 CString
getErrorString()
196 CString error
= CRegBaseCommon
<CString
>::getErrorString();
197 #if defined IDS_REG_ERROR
199 sTemp
.Format(IDS_REG_ERROR
, (LPCTSTR
)m_key
, (LPCTSTR
)error
);
208 typedef std::wstring wide_string
;
211 # define stdstring wide_string
213 # define stdstring std::string
219 * Base class for STL string type registry classes.
222 class CRegStdBase
: public CRegBaseCommon
<stdstring
>
227 * String type specific operations.
230 virtual LPCTSTR
GetPlainString (const stdstring
& s
) const {return s
.c_str();}
231 virtual DWORD
GetLength (const stdstring
& s
) const {return static_cast<DWORD
>(s
.size());}
235 /** Default constructor.
240 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
241 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
242 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
244 CRegStdBase(const stdstring
& key
, bool force
, HKEY base
= HKEY_CURRENT_USER
);
249 * DWORD value in registry. with this class you can use DWORD values in registry
250 * like normal DWORD variables in your program.
252 * in your header file, declare your registry DWORD variable:
254 * CRegDWORD regvalue;
256 * next initialize the variable e.g. in the constructor of your class:
258 * regvalue = CRegDWORD("Software\\Company\\SubKey\\MyValue", 100);
260 * this will set the registry value "MyValue" under HKEY_CURRENT_USER with path
261 * "Software\Company\SubKey" to the variable. If the key does not yet exist or
262 * an error occurred during read from the registry, a default
263 * value of 100 is used when accessing the variable.
264 * now the variable can be used like any other DWORD variable:
266 * regvalue = 200; //stores the value 200 in the registry
267 * int temp = regvalue + 300; //temp has value 500 now
268 * regvalue += 300; //now the registry has the value 500 too
270 * to avoid too much access to the registry the value is cached inside the object.
271 * once the value is read, no more read accesses to the registry will be made.
272 * this means the variable will contain a wrong value if the corresponding registry
273 * entry is changed by anything else than this variable! If you think that could happen
278 * to force a refresh of the variable with the registry.
279 * a write to the registry is only made if the new value assigned with the variable
280 * is different than the last assigned value.
281 * to force a write use the method write();
282 * another option to force reads and writes to the registry is to specify TRUE as the
283 * third parameter in the constructor.
285 template<class T
, class Base
>
286 class CRegTypedBase
: public Base
290 T m_value
; ///< the cached value of the registry
291 T m_defaultvalue
; ///< the default value to use
294 * sub-classes must provide type-specific code to extract data from
295 * and write data to an open registry key.
298 virtual void InternalRead (HKEY hKey
, T
& value
) = 0;
299 virtual void InternalWrite (HKEY hKey
, const T
& value
) = 0;
304 * We use this instead of a default constructor because not all
305 * data types may provide an adequate default constructor.
307 CRegTypedBase(const T
& def
);
311 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
312 * \param def the default value used when the key does not exist or a read error occurred
313 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
314 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
316 CRegTypedBase(const typename
Base::StringT
& key
, const T
& def
, bool force
= FALSE
, HKEY base
= HKEY_CURRENT_USER
);
319 * reads the assigned value from the registry. Use this method only if you think the registry
320 * value could have been altered without using the CRegDWORD object.
321 * \return the read value
323 void read(); ///< reads the value from the registry
324 void write(); ///< writes the value to the registry
331 CRegTypedBase
<T
,Base
>& operator=(const T
& rhs
);
334 // implement CRegTypedBase<> members
336 template<class T
, class Base
>
337 CRegTypedBase
<T
, Base
>::CRegTypedBase (const T
& def
)
339 , m_defaultvalue (def
)
343 template<class T
, class Base
>
344 CRegTypedBase
<T
, Base
>::CRegTypedBase (const typename
Base::StringT
& key
, const T
& def
, bool force
, HKEY base
)
345 : Base (key
, force
, base
)
347 , m_defaultvalue (def
)
351 template<class T
, class Base
>
352 void CRegTypedBase
<T
, Base
>::read()
354 m_value
= m_defaultvalue
;
358 if ((LastError
= RegOpenKeyEx (m_base
, GetPlainString (m_path
), 0, KEY_EXECUTE
, &hKey
))==ERROR_SUCCESS
)
362 T value
= m_defaultvalue
;
363 InternalRead (hKey
, value
);
365 if (LastError
==ERROR_SUCCESS
)
371 LastError
= RegCloseKey(hKey
);
375 template<class T
, class Base
>
376 void CRegTypedBase
<T
, Base
>::write()
381 if ((LastError
= RegCreateKeyEx(m_base
, GetPlainString (m_path
), 0, _T(""), REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, &disp
))!=ERROR_SUCCESS
)
386 InternalWrite (hKey
, m_value
);
387 if (LastError
==ERROR_SUCCESS
)
392 LastError
= RegCloseKey(hKey
);
396 template<class T
, class Base
>
397 CRegTypedBase
<T
, Base
>::operator const T
&()
399 if ((m_read
)&&(!m_force
))
411 template<class T
, class Base
>
412 CRegTypedBase
<T
, Base
>& CRegTypedBase
<T
, Base
>::operator =(const T
& d
)
414 if ((d
==m_value
)&&(!m_force
))
416 //no write to the registry required, its the same value
427 * DWORD value in registry. with this class you can use DWORD values in registry
428 * like normal DWORD variables in your program.
430 * in your header file, declare your registry DWORD variable:
432 * CRegDWORD regvalue;
434 * next initialize the variable e.g. in the constructor of your class:
436 * regvalue = CRegDWORD("Software\\Company\\SubKey\\MyValue", 100);
438 * this will set the registry value "MyValue" under HKEY_CURRENT_USER with path
439 * "Software\Company\SubKey" to the variable. If the key does not yet exist or
440 * an error occurred during read from the registry, a default
441 * value of 100 is used when accessing the variable.
442 * now the variable can be used like any other DWORD variable:
444 * regvalue = 200; //stores the value 200 in the registry
445 * int temp = regvalue + 300; //temp has value 500 now
446 * regvalue += 300; //now the registry has the value 500 too
448 * to avoid too much access to the registry the value is cached inside the object.
449 * once the value is read, no more read accesses to the registry will be made.
450 * this means the variable will contain a wrong value if the corresponding registry
451 * entry is changed by anything else than this variable! If you think that could happen
456 * to force a refresh of the variable with the registry.
457 * a write to the registry is only made if the new value assigned with the variable
458 * is different than the last assigned value.
459 * to force a write use the method write();
460 * another option to force reads and writes to the registry is to specify TRUE as the
461 * third parameter in the constructor.
464 class CRegDWORDCommon
: public CRegTypedBase
<DWORD
,Base
>
469 * provide type-specific code to extract data from and write data to an open registry key.
472 virtual void InternalRead (HKEY hKey
, DWORD
& value
);
473 virtual void InternalWrite (HKEY hKey
, const DWORD
& value
);
477 CRegDWORDCommon(void);
480 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
481 * \param def the default value used when the key does not exist or a read error occurred
482 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
483 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
485 CRegDWORDCommon(const typename
Base::StringT
& key
, DWORD def
= 0, bool force
= false, HKEY base
= HKEY_CURRENT_USER
);
487 CRegDWORDCommon
& operator=(DWORD rhs
) {CRegTypedBase
<DWORD
, Base
>::operator =(rhs
); return *this;}
488 CRegDWORDCommon
& operator+=(DWORD d
) { return *this = *this + d
;}
489 CRegDWORDCommon
& operator-=(DWORD d
) { return *this = *this - d
;}
490 CRegDWORDCommon
& operator*=(DWORD d
) { return *this = *this * d
;}
491 CRegDWORDCommon
& operator/=(DWORD d
) { return *this = *this / d
;}
492 CRegDWORDCommon
& operator%=(DWORD d
) { return *this = *this % d
;}
493 CRegDWORDCommon
& operator<<=(DWORD d
) { return *this = *this << d
;}
494 CRegDWORDCommon
& operator>>=(DWORD d
) { return *this = *this >> d
;}
495 CRegDWORDCommon
& operator&=(DWORD d
) { return *this = *this & d
;}
496 CRegDWORDCommon
& operator|=(DWORD d
) { return *this = *this | d
;}
497 CRegDWORDCommon
& operator^=(DWORD d
) { return *this = *this ^ d
;}
500 // implement CRegDWORDCommon<> methods
503 CRegDWORDCommon
<Base
>::CRegDWORDCommon(void)
504 : CRegTypedBase
<DWORD
, Base
>(0)
509 CRegDWORDCommon
<Base
>::CRegDWORDCommon(const typename
Base::StringT
& key
, DWORD def
, bool force
, HKEY base
)
510 : CRegTypedBase
<DWORD
, Base
> (key
, def
, force
, base
)
516 void CRegDWORDCommon
<Base
>::InternalRead (HKEY hKey
, DWORD
& value
)
518 DWORD size
= sizeof(value
);
520 if ((LastError
= RegQueryValueEx(hKey
, GetPlainString (m_key
), NULL
, &type
, (BYTE
*) &value
, &size
))==ERROR_SUCCESS
)
522 ASSERT(type
==REG_DWORD
);
527 void CRegDWORDCommon
<Base
>::InternalWrite (HKEY hKey
, const DWORD
& value
)
529 LastError
= RegSetValueEx (hKey
, GetPlainString (m_key
), 0, REG_DWORD
,(const BYTE
*) &value
, sizeof(value
));
534 * CString value in registry. with this class you can use CString values in registry
535 * almost like normal CString variables in your program.
537 * in your header file, declare your registry CString variable:
539 * CRegString regvalue;
541 * next initialize the variable e.g. in the constructor of your class:
543 * regvalue = CRegString("Software\\Company\\SubKey\\MyValue", "default");
545 * this will set the registry value "MyValue" under HKEY_CURRENT_USER with path
546 * "Software\Company\SubKey" to the variable. If the key does not yet exist or
547 * an error occurred during read from the registry, a default
548 * value of "default" is used when accessing the variable.
549 * now the variable can be used like any other CString variable:
551 * regvalue = "some string"; //stores the value "some string" in the registry
552 * CString temp = regvalue + "!!"; //temp has value "some string!!" now
554 * to use the normal methods of the CString class, just typecast the CRegString to a CString
555 * and do whatever you want with the string:
557 * ((CString)regvalue).GetLength();
558 * ((CString)regvalue).Trim();
560 * please be aware that in the second line the change in the string won't be written
561 * to the registry! To force a write use the write() method. A write() is only needed
562 * if you change the String with Methods not overloaded by CRegString.
563 * to avoid too much access to the registry the value is cached inside the object.
564 * once the value is read, no more read accesses to the registry will be made.
565 * this means the variable will contain a wrong value if the corresponding registry
566 * entry is changed by anything else than this variable! If you think that could happen
571 * to force a refresh of the variable with the registry.
572 * a write to the registry is only made if the new value assigned with the variable
573 * is different than the last assigned value.
574 * to force a write use the method write();
575 * another option to force reads and writes to the registry is to specify TRUE as the
576 * third parameter in the constructor.
579 class CRegStringCommon
: public CRegTypedBase
<typename
Base::StringT
, Base
>
584 * provide type-specific code to extract data from and write data to an open registry key.
587 virtual void InternalRead (HKEY hKey
, typename
Base::StringT
& value
);
588 virtual void InternalWrite (HKEY hKey
, const typename
Base::StringT
& value
);
594 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
595 * \param def the default value used when the key does not exist or a read error occurred
596 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
597 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
599 CRegStringCommon(const typename
Base::StringT
& key
, const typename
Base::StringT
& def
= _T(""), bool force
= false, HKEY base
= HKEY_CURRENT_USER
);
601 CRegStringCommon
& operator=(const typename
Base::StringT
& rhs
) {CRegTypedBase
<StringT
, Base
>::operator =(rhs
); return *this;}
602 CRegStringCommon
& operator+=(const typename
Base::StringT
& s
) { return *this = (typename
Base::StringT
)*this + s
; }
605 // implement CRegDWORD<> methods
608 CRegStringCommon
<Base
>::CRegStringCommon(void)
609 : CRegTypedBase
<typename
Base::StringT
, Base
>(typename
Base::StringT())
614 CRegStringCommon
<Base
>::CRegStringCommon(const typename
Base::StringT
& key
, const typename
Base::StringT
& def
, bool force
, HKEY base
)
615 : CRegTypedBase
<typename
Base::StringT
, Base
> (key
, def
, force
, base
)
621 void CRegStringCommon
<Base
>::InternalRead (HKEY hKey
, typename
Base::StringT
& value
)
625 LastError
= RegQueryValueEx(hKey
, GetPlainString (m_key
), NULL
, &type
, NULL
, &size
);
627 std::auto_ptr
<TCHAR
> pStr (new TCHAR
[size
]);
628 if ((LastError
= RegQueryValueEx(hKey
, GetPlainString (m_key
), NULL
, &type
, (BYTE
*) pStr
.get(), &size
))==ERROR_SUCCESS
)
630 ASSERT(type
==REG_SZ
|| type
==REG_EXPAND_SZ
);
631 value
= StringT (pStr
.get());
636 void CRegStringCommon
<Base
>::InternalWrite (HKEY hKey
, const typename
Base::StringT
& value
)
638 LastError
= RegSetValueEx(hKey
, GetPlainString (m_key
), 0, REG_SZ
, (BYTE
*)GetPlainString (value
), (GetLength(value
)+1)*sizeof (TCHAR
));
643 * CRect value in registry. with this class you can use CRect values in registry
644 * almost like normal CRect variables in your program.
646 * in your header file, declare your registry CString variable:
650 * next initialize the variable e.g. in the constructor of your class:
652 * regvalue = CRegRect("Software\\Company\\SubKey\\MyValue", CRect(100,100,200,200));
654 * this will set the registry value "MyValue" under HKEY_CURRENT_USER with path
655 * "Software\Company\SubKey" to the variable. If the key does not yet exist or
656 * an error occurred during read from the registry, a default
657 * value of 100,100,200,200 is used when accessing the variable.
658 * now the variable can be used like any other CRect variable:
660 * regvalue = CRect(40,20,300,500); //stores the value in the registry
661 * CRect temp = regvalue + CPoint(1,1);
662 * temp |= CSize(5,5);
664 * to use the normal methods of the CRect class, just typecast the CRegRect to a CRect
665 * and do whatever you want with the rect:
667 * ((CRect)regvalue).MoveToX(100);
668 * ((CRect)regvalue).DeflateRect(10,10);
670 * please be aware that in the second line the change in the CRect won't be written
671 * to the registry! To force a write use the write() method. A write() is only needed
672 * if you change the CRect with Methods not overloaded by CRegRect.
673 * to avoid too much access to the registry the value is cached inside the object.
674 * once the value is read, no more read accesses to the registry will be made.
675 * this means the variable will contain a wrong value if the corresponding registry
676 * entry is changed by anything else than this variable! If you think that could happen
681 * to force a refresh of the variable with the registry.
682 * a write to the registry is only made if the new value assigned with the variable
683 * is different than the last assigned value.
684 * to force a write use the method write();
685 * another option to force reads and writes to the registry is to specify TRUE as the
686 * third parameter in the constructor.
689 #ifdef __ATLTYPES_H__ // defines CRect
690 class CRegRect
: public CRegTypedBase
<CRect
, CRegBase
>
695 * provide type-specific code to extract data from and write data to an open registry key.
698 virtual void InternalRead (HKEY hKey
, CRect
& value
);
699 virtual void InternalWrite (HKEY hKey
, const CRect
& value
);
705 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
706 * \param def the default value used when the key does not exist or a read error occurred
707 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
708 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
710 CRegRect(const CString
& key
, const CRect
& def
= CRect(), bool force
= false, HKEY base
= HKEY_CURRENT_USER
);
713 CRegRect
& operator=(const CRect
& rhs
) {CRegTypedBase
<CRect
, CRegBase
>::operator =(rhs
); return *this;}
714 operator LPCRECT() { return (LPCRECT
)(CRect
)*this; }
715 operator LPRECT() { return (LPRECT
)(CRect
)*this; }
716 CRegRect
& operator+=(POINT r
) { return *this = (CRect
)*this + r
;}
717 CRegRect
& operator+=(SIZE r
) { return *this = (CRect
)*this + r
;}
718 CRegRect
& operator+=(LPCRECT r
) { return *this = (CRect
)*this + r
;}
719 CRegRect
& operator-=(POINT r
) { return *this = (CRect
)*this - r
;}
720 CRegRect
& operator-=(SIZE r
) { return *this = (CRect
)*this - r
;}
721 CRegRect
& operator-=(LPCRECT r
) { return *this = (CRect
)*this - r
;}
723 CRegRect
& operator&=(CRect r
) { return *this = r
& *this;}
724 CRegRect
& operator|=(CRect r
) { return *this = r
| *this;}
730 * CPoint value in registry. with this class you can use CPoint values in registry
731 * almost like normal CPoint variables in your program.
733 * in your header file, declare your registry CPoint variable:
735 * CRegPoint regvalue;
737 * next initialize the variable e.g. in the constructor of your class:
739 * regvalue = CRegPoint("Software\\Company\\SubKey\\MyValue", CPoint(100,100));
741 * this will set the registry value "MyValue" under HKEY_CURRENT_USER with path
742 * "Software\Company\SubKey" to the variable. If the key does not yet exist or
743 * an error occurred during read from the registry, a default
744 * value of 100,100 is used when accessing the variable.
745 * now the variable can be used like any other CPoint variable:
747 * regvalue = CPoint(40,20); //stores the value in the registry
748 * CPoint temp = regvalue + CPoint(1,1);
749 * temp += CSize(5,5);
751 * to use the normal methods of the CPoint class, just typecast the CRegPoint to a CPoint
752 * and do whatever you want with the point:
754 * ((CRect)regvalue).Offset(100,10);
756 * please be aware that in the above example the change in the CPoint won't be written
757 * to the registry! To force a write use the write() method. A write() is only needed
758 * if you change the CPoint with Methods not overloaded by CRegPoint.
759 * to avoid too much access to the registry the value is cached inside the object.
760 * once the value is read, no more read accesses to the registry will be made.
761 * this means the variable will contain a wrong value if the corresponding registry
762 * entry is changed by anything else than this variable! If you think that could happen
767 * to force a refresh of the variable with the registry.
768 * a write to the registry is only made if the new value assigned with the variable
769 * is different than the last assigned value.
770 * to force a write use the method write();
771 * another option to force reads and writes to the registry is to specify TRUE as the
772 * third parameter in the constructor.
775 #ifdef __ATLTYPES_H__ // defines CPoint
776 class CRegPoint
: public CRegTypedBase
<CPoint
, CRegBase
>
781 * provide type-specific code to extract data from and write data to an open registry key.
784 virtual void InternalRead (HKEY hKey
, CPoint
& value
);
785 virtual void InternalWrite (HKEY hKey
, const CPoint
& value
);
791 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey\\MyValue"
792 * \param def the default value used when the key does not exist or a read error occurred
793 * \param force set to TRUE if no cache should be used, i.e. always read and write directly from/to registry
794 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
796 CRegPoint(const CString
& key
, const CPoint
& def
= CPoint(), bool force
= false, HKEY base
= HKEY_CURRENT_USER
);
799 CRegPoint
& operator=(const CPoint
& rhs
) {CRegTypedBase
<CPoint
, CRegBase
>::operator =(rhs
); return *this;}
800 CRegPoint
& operator+=(CPoint p
) { return *this = p
+ *this; }
801 CRegPoint
& operator-=(CPoint p
) { return *this = p
- *this; }
807 * Manages a registry key (not a value). Provides methods to create and remove the
808 * key and to query the list of values and sub keys.
811 #ifdef __AFXCOLL_H__ // defines CStringList
817 * \param key the path to the key, including the key. example: "Software\\Company\\SubKey"
818 * \param base a predefined base key like HKEY_LOCAL_MACHINE. see the SDK documentation for more information.
820 CRegistryKey(const CString
& key
, HKEY base
= HKEY_CURRENT_USER
);
824 * Creates the registry key if it does not already exist.
825 * \return ERROR_SUCCESS or an nonzero error code. Use FormatMessage() to get an error description.
829 * Removes the whole registry key including all values. So if you set the registry
830 * entry to be HKCU\Software\Company\Product\key there will only be
831 * HKCU\Software\Company\Product key in the registry.
832 * \return ERROR_SUCCESS or an nonzero error code. Use FormatMessage() to get an error description.
836 bool getValues(CStringList
& values
); ///< returns the list of values
837 bool getSubKeys(CStringList
& subkeys
); ///< returns the list of sub keys
840 HKEY m_base
; ///< handle to the registry base
841 HKEY m_hKey
; ///< handle to the open registry key
842 CString m_path
; ///< the path to the key
847 * Instantiate templates for common (data type, string type) combinations.
850 #ifdef __CSTRINGT_H__
851 CRegDWORDCommon
<CRegBase
>;
852 typedef CRegDWORDCommon
<CRegBase
> CRegDWORD
;
853 CRegStringCommon
<CRegBase
>;
854 typedef CRegStringCommon
<CRegBase
> CRegString
;
857 CRegDWORDCommon
<CRegStdBase
>;
858 typedef CRegDWORDCommon
<CRegStdBase
> CRegStdWORD
;
859 typedef CRegDWORDCommon
<CRegStdBase
> CRegStdDWORD
;
860 CRegStringCommon
<CRegStdBase
>;
861 typedef CRegStringCommon
<CRegStdBase
> CRegStdString
;