use
CregKey
Class Operation The registry is very convenient.
CregKey
Class is not one
MFC
Class, but one
ATL
Class, so don't forget it when you use it.
STDAFX.H
Add to the header file
#include
.
1. Open you need to query the registry key:
The prototype is: long open (HKEY HKEYPARENT, LPCTSTSTSZKEYNAME, Regsam Samdesired = Key_All_Access);
Only when a registry key is opened to operate it.
HKEYPARENT: The handle of the open key.
LPSZKEYNAME: The path to the registry where the key is located.
Samdesired: The security of registry access.
example:
CregKey rk;
LPCTSTR LP = "Software // compupacific // new // address // addbutton";
IF (rk.open (HKEY_CURRENT_USER, LP) == Error_suCcess
{
AfxMessageBox ("Successful!" 0);
}
2. Get the key value of a key in the registry:
Long QueryValue (DWORD & DWVALUE, LPCTSTR LPSZVALUENAME);
Long QueryValue (LPTSTSTSTSTSTSZZVALUENAME, DWORD * PDWCOUNT);
There are two functions, the first is the query integer value, the second is the value of the query string type. They are given examples of them.
// Take an integer value
CregKey rk;
DWORD DVALUE;
LPCTSTR LP = "Software // compupacific // new // address // addbutton";
IF (rk.open (HKEY_CURRENT_USER, LP) == Error_suCcess
{
IF (rk.QueryValue (Dvalue, "Loadbehavior") == Error_Success
{
CSTRING TEMP;
Temp.Format ("% D", DVALUE);
Setdlgitemtext (IDC_EDIT1, TEMP);
}
Else
{
AfxMessageBox ("Query Error");
}
}
Else
{
AFXMessageBox ("Open Error!");
}
RK.Close ();
// Take a string type value
CregKey rk;
HKEY M_HKEY;
DWORD PCOUNT = 1024;
CString KeyValue;
Char szvalue [1024];
LPCTSTR LP = "Software // compupacific // new // address // addbutton";
IF (rk.open (HKEY_CURRENT_USER, LP) == Error_suCcess
{
LPCTSTR LKEYNAME = "description";
IF (rk.queryvalue (szvalue, lkeyname, & pcount) == Error_Success)
{
KeyValue = SzValue;
Setdlgitemtext (IDC_EDIT1, KeyValue);
}
Else
{
Setdlgitemtext (idc_edit1, "query error");
//rk.setValue (LKeyname, "HHH");
}
Else
{
Setdlgitemtext (IDC_EDIT1, "Open Error");
}
RK.Close ();
3. Add a key value:
Long SetValue (DWORD DWVALUE, LPCTSTR LPSZVALUENAME);
Long SetValue (LPCTSTR LPSZVALUE, LPCTSTR LPSZVALUENAME = NULL);
Long SetValue (HKEY HKEYPARENT, LPCTSTSTSZKEYNAME, LPCTSTR LPSZVALUE, LPCTSTR LPSZVALUENAME = NULL);
There are three overload functions, which are different. We are for the second example and to give a non-three:
Long LRESULT = 0;
CregKey REG;
// Open the Required Registry Key
LPCTSTR LPSZKEY = "Software // Microsoft // Internet Explorer // Toolbar";
LRESULT = reg.open (HKEY_CURRENT_USER, LPSZKEY);
// Check if Opened SuccessFully
IF (Error_Success! = LRESULT)
{
Return False;
}
// set the value
LRESULT = reg.setValue (m_szfilepath, "backbitmap");
IF (Error_Success! = LRESULT)
{
Return False;
}
// done, Close and Return Success
Reg.close ();
m_szfilepath is a picture of a picture, through this function, your design of your IE toolbar turns into the picture you specified, so cool.
4. Delete a key value: long deletevalue (LPCTSTR LPSZVALUE);
LpszValue: The name of the key value you want to delete.
example:
Long LRESULT = 0;
CregKey REG;
// Open the Required Registry Key
LPCTSTR LPSZKEY = "Software // Microsoft // Internet Explorer // Toolbar";
LRESULT = reg.open (HKEY_CURRENT_USER, LPSZKEY);
// Check if Opened SuccessFully
IF (Error_Success! = LRESULT)
{
Return False;
}
// delete the value "backbitmap" from Toolbar
LRESULT = Reg.deletevalue ("backbitmap");
// check if deleted successfully
IF (Error_Success! = LRESULT)
{
Return False; // Perhaps Value Not Found, IF SKIN IS Not Set
}
// done, returnis
Reg.close ();
This will drop the background image you set to the IE toolbar, which is the Backbitmap key value of the IE toolbar. Generally, the most important operation is these, is it very simple.