Enumerate a function of the registry key name and key value:
// QueryKey - ENUMERATES The Subkeys of Key, and the associated
// Values, Then Copies the information about the keys and values
// INTO A Pair of Edit Controls and List Boxes.
// HDLG - Dialog Box That Contains The Edit Controls and List Boxes.
// HKEY - Key Whose Subkeys and values are to be enumerated.
Void QueryKey (HWND HDLG, Handle HKey)
{
Char Achkey [MAX_PATH];
Char Achclass [MAX_PATH] = ""; // Buffer for Class Name
DWORD cchclassname = max_path; // size of class string
DWORD CSUBKEYS; / / NUMBER OF SUBEYS
DWORD CBMAXSUBKKEY; / / LONGEST SUBEY SIZE
DWORD CCHMAXCLASS; // LONGEST CLASS STRING
DWORD CVALUES; // Number of Values for Key
DWORD CCHMAXVALUE; // LONGEST VALUE NAME
DWORD CBMaxValuedata; // LONGEST VALUE DATA
DWORD CBSecurityDescriptor; // size of security descriptor
Filetime ftlastwrittime; // last Write Time
DWORD I, J;
DWORD RETCODE, RETVALUE;
Char achvalue [max_value_name];
DWORD cchvalue = max_value_name;
Char Achbuff [80];
// Get the class name and the value count.
RegQueryInfoKey (HKEY, // Key Handle
Achclass, // buffer for class name
& cchclassname, // size of class string
Null, // reserved
& csubkeys, // Number of Subkeys
& cbmaxsubkey, // longeest Subkey Size
& cchmaxclass, // longest class string
& Cvalues, // Number of Values for this key
& cchmaxvalue, // longest value name
& CBMaxValuedata, // LONGEST VALUE DATA
& CBSecurityDescriptor, // Security Descriptor
& ftlastWrittime); // Last Write TimeSetdlgitemText (HDLG, IDE_CLASS, ACHCLASS);
Setdlgitemint (HDLG, IDE_CVALUES, CVALUES, FALSE);
SendMessage (GetdlgItem (HDLG, Idl_Listbox),
LB_ADDString, 0, (long) "..");
// enumerate the child keys, unsil regenumkeyex fails. Then
// Get the name of each child key and copy it Into the list box.
SetCursor (LoadCursor (NULL, IDC_WAIT);
For (i = 0, retcode = error_success;
Retcode == Error_suCcess; i )
{
Retcode = regenumKeyex (HKEY,
i,
ACHKEY,
MAX_PATH,
NULL,
NULL,
NULL,
& ftlastWrittime);
IF (Retcode == (DWORD) Error_suCcess
{
SendMessage (GetdlgItem (HDLG, Idl_Listbox),
LB_ADDSTRING, 0, (long) ACHKEY
}
}
SetCursor (LoadCursor (NULL, IDC_ARROW);
// Enumerate the key value.
SetCursor (LoadCursor (NULL, IDC_WAIT);
IF (CVALUES)
{
For (j = 0, retvalue = error_success;
J { cchvalue = max_value_name; ACHVALUE [0] = '/ 0'; RetValue = RegenumValue (HKEY, J, ACHVALUE, & cchvalue, NULL, NULL, // & dwtype, Null, // & bdata, NULL); // & bcdata IF (RetValue == (DWORD) Error_suCcess { ACHBUFF [0] = '/ 0'; // Add Each Value to a List Box. IF (! lstrlen (achvalue)) LSTRCPY (Achvalue, " WSPrintf (Achbuff, "% D)% S", J, ACHVALUE; SendMessage (Getdlgitem (HDLG, IDL_ListBox2), LB_ADDString, 0, (long) Achbuff); } } SetCursor (LoadCursor (NULL, IDC_ARROW); }