Click here to Skip to main content
11,928,985 members (54,546 online)
Click here to Skip to main content
Add your own
alternative version


48 bookmarked

Registry List Control

, 10 Jan 2003
Rate this:
Please Sign up or sign in to vote.
A List Control to Monitor Windows Registry
<!-- Article image -->

Sample Image - RegistryListCtrl.jpg
Figure 1

<!-- Add the rest of your HTML here -->


Every programmer knows about the Registry. Registry is a database to store data related to programs. Some very important information about installed hardware and software, are stored by Windows in registry. Windows has a utility to browse registry and make changes to it called regedit.exe, this is registry editor program. Figure 2 shows it.

Windows Registry Editor
Figure 2

I wrote some utility classes to demonstrate all of Registry capabilities. Using these classes are very easy. Windows Registry Editor (regedit.exe) has these capabilities:

  • A tree to show hierarchy of Registry (Keys and Sub-Keys)
  • A list to show Key's Value (Value name, Type of value and Value Data)

My classes support part two of registry editor capabilities (A list control to show Registry Values).

How to use

First of all add these files to your project

  • HexEditBase.h, HexEditBase.cpp (for editing Binary values). I should thank Ch. Kuendig for his HexEditor that I used to complete my task.
  • RegEditBinaryDialog.h, RegEditBinaryDialog.cpp
  • RegEditDWORDDialog.h, RegEditDWORDDialog.cpp
  • RegEditStringDialog.h, RegEditStringDialog.cpp
  • RegistryListCtrl.h, RegistryListCtrl.cpp (main class)

Also add resources needed by these classes (Menu and Bitmap).

Dialog Based Programs:

Add a List Control to your dialog. Use Class Wizard to add a member variable with variable type CListCtrl. Go to your dialog header file and rename your variable type from CListCtrl to CRegistryListCtrl. Remember to add RegistryListCtrl.h header file at top of your dialog definitioin. Now compile it. If no error occurs, everything goes right.

CRegistryListCtrl in action

When your program is running (like figure 1), and a key is open, CRegistryListCtrl shows you all of value names stored in that key. The list shows items with full detail of them (eg. type of value and also value data). Every value name has at least one of these types:

  • String type known as REG_SZ for storing string values
  • DWORD type known as REG_DWORD for storing integer values
  • Binary type known as REG_BINARY for storing binary values. Generally speaking, structures or other complex data types!

CRegistryListCtrl can change values of all that three types by it's dialogs. Figure 3, 4 and 5 show you these dialogs.

Edit String value
Figure 3 - Edit a string value

Edit DWORD value
Figure 4 - Edit a DWORD value

Edit Binary value
Figure 5 - Edit a Binary value (HEX format)

For complete compatibility with Regedit.exe, I add some another features like adding menu support. These menus should be appear when a user pressed right click of mouse. These two menus are shown in figures 6 and 7. Menu 1 can add new items (and also new keys) and menu 2 shows a way to modify existing values.

Adding new values by this menu
Figure 6 - Adding new items

Modify existing values
Figure 7 - Modify existing values

CRegistryListCtrl has written to monitor changes in values on the fly. In other hand, if any changes occured by another programs or by regedit.exe, CRegistryListCtrl shows it immediately! I use a thread to monitor specified key and report changes to CRegistryListCtrl.

Working with CRegistryListCtrl

CRegistryListCtrl has only one public member function: OpenRegKey():

void OpenRegKey(HKEY hMasterKey, CString SubKey)

hMasterKey is Handle to a currently open key or any of the following predefined reserved handle values:


and SubKey is your desired key.


CRegistryListCtrl m_RegList;
  "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");

All of other things will handle by CRegistryListCtrl automatically.

How does CRegistryListCtrl Monitor Registry?

CRegistryListCtrl has a static member function to monitor specified key of Registry. I used this static member function with a thread after calling OpenRegKey() or when you refresh the list by pressing F5. This member function, named NotifyChangeRegKey() notifies CRegistryListCtrl when any changes occured to Registry.

Body of this static member function is as below:

//static member function used with thread to monitor Registry changes
UINT CRegistryListCtrl::NotifyChangeRegKey(void* pParam)
  //if thread is running, do not run it again.
  if (RunThread==FALSE)
    return 0;     //exit the thread


  CRegistryListCtrl* pThread=(CRegistryListCtrl*) pParam;

  HANDLE hEvent;
  HKEY   hKey;
  LONG   lErrorCode;
  // Open a key.
  lErrorCode = RegOpenKeyEx(pThread->m_hKey, pThread->m_SubKey, 
    0, KEY_NOTIFY, &hKey);
  if (lErrorCode != ERROR_SUCCESS)
    return 0;
  // Create an event.
  hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  if (hEvent == NULL)
    return 0;
  // Watch the registry key for a change of value.
  lErrorCode = RegNotifyChangeKeyValue(hKey, TRUE, 
    dwFilter, hEvent, TRUE);
  if (lErrorCode != ERROR_SUCCESS)
    return 0;
  //Wait for an event to occur. In other hand
  //any changes occured to Registry!
  DWORD Result;
  Result=WaitForSingleObject(hEvent, INFINITE);
  // Close the key.
  lErrorCode = RegCloseKey(hKey);
  if (lErrorCode != ERROR_SUCCESS)
    return 0;
  // Close the handle.
  if (!CloseHandle(hEvent))
    return 0;
  //Thread Finished!
  if (Result == WAIT_FAILED)
    return 0;
    //A change occured in Registry, List must be refreshed!
    return 1;

After opening any key, the tread fired to monitor Registry changes. I used the following statement to fire up the thread:

AfxBeginThread(NotifyChangeRegKey, this);

The first parameter is name of static member function, and second is a pointer to CRegistryListCtrl class. I used this technique for accessing member function and member variables of class within thread!

Future work

My future work is making a control to show hierarchy of Registry in a Tree. I will name it CRegistryTreeCtrl. In addition to showing a tree of Keys and Subkeys, this tree monitor Registry for any changes in it's keys or subkeys and apply this changes on the fly! By using CRegistryListCtrl and CRegistryTreeCtrl together, you can create regedit by yourself in 3 minutes. Enjoy it!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

A. Riazi
CEO Misbah3Com
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acqusition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competetion, my articles are:

You can see list of my articles, by clicking here

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey26-Feb-12 20:46
membermanoj kumar choubey26-Feb-12 20:46 
GeneralTake more and more memory resource!! Pin
knife_wei8-Dec-09 2:11
memberknife_wei8-Dec-09 2:11 
You did a good job, but there is a bug in your program.
If I press the open button many times, this process will create more and more threads suspended in the WaitforSingleObject() and can't move on. From taskmanager, you can see the process take more and more memory after press the open button many times. Can you fix this bug? Thanks a lot.
Generalif i wait 5 minutes at RegNotifykeychangevalue function after i change value i dont get notification to hEvent Pin
Member 37611485-Aug-09 5:17
memberMember 37611485-Aug-09 5:17 
Generalinformation about installed hardware Pin
Tailana16-May-05 22:04
memberTailana16-May-05 22:04 
GeneralRe: information about installed hardware Pin
A. Riazi16-May-05 22:14
memberA. Riazi16-May-05 22:14 
GeneralRe: information about installed hardware Pin
Tailana16-May-05 23:16
memberTailana16-May-05 23:16 
GeneralRe: information about installed hardware Pin
A. Riazi17-May-05 0:38
memberA. Riazi17-May-05 0:38 
GeneralExcellent Job Pin
shotgun24-Jan-05 14:11
membershotgun24-Jan-05 14:11 
GeneralRe: Excellent Job Pin
A. Riazi24-Jan-05 21:21
memberA. Riazi24-Jan-05 21:21 
GeneralPosition of caret incorrect Pin
zrxu10-Jan-05 5:26
memberzrxu10-Jan-05 5:26 
GeneralRegistry Viewer Pin
Mishra Vikas23-Jan-04 3:24
memberMishra Vikas23-Jan-04 3:24 
GeneralMemory leaks Pin
Paulo Rogério12-Jan-04 3:24
memberPaulo Rogério12-Jan-04 3:24 
GeneralGreat Job Pin
Simone Giannecchini2-Jan-04 1:40
memberSimone Giannecchini2-Jan-04 1:40 
GeneralRe: Great Job Pin
A. Riazi2-Jan-04 4:13
memberA. Riazi2-Jan-04 4:13 
QuestionHow to monitor for changes? Pin
conrad Braam20-Aug-03 3:03
memberconrad Braam20-Aug-03 3:03 
AnswerRe: How to monitor for changes? Pin
A. Riazi20-Aug-03 4:08
memberA. Riazi20-Aug-03 4:08 
GeneralNot bad. Good job. Pin
AhMan15-Jan-03 4:00
memberAhMan15-Jan-03 4:00 
GeneralPlease fix this Pin
.S.Rod.11-Jan-03 5:49
member.S.Rod.11-Jan-03 5:49 
GeneralRe: Please fix this Pin
A. Riazi11-Jan-03 18:41
memberA. Riazi11-Jan-03 18:41 
GeneralRe: Please fix this Pin
Anonymous12-Jan-03 6:58
sussAnonymous12-Jan-03 6:58 
GeneralRe: Please fix this Pin
real_ashwin10-Sep-03 2:41
memberreal_ashwin10-Sep-03 2:41 
GeneralRe: Please fix this Pin
DavidCrow30-Oct-03 7:32
memberDavidCrow30-Oct-03 7:32 
GeneralRe: Please fix this Pin
BadMoFu10-Mar-05 11:18
sussBadMoFu10-Mar-05 11:18 
GeneralRe: Please fix this Pin
DavidCrow10-Mar-05 11:29
memberDavidCrow10-Mar-05 11:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 11 Jan 2003
Article Copyright 2003 by A. Riazi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid