May 24, 2019
Hot Topics:

Walking The Registry Tree

  • September 28, 2004
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

Initialization of the Walk Registry Tree Dialog

Well, it took a long darn time to get here, but we finally understand all the constituent parts of the Walk Registry Tree page, and it's time to initialize it. First, we initialize the RAPI subsystem with a call to RapiInit(). We call the balancing RapiUninit() in the destructor for the CWalkReg() class.

BOOL CWalkReg::OnInitDialog()
   CImageList      *pImageList;
   CBitmap         bitmap;
   CRapiDemoApp    *pApp;
   HKEY            hKey;
   LONG            rc;

   HRESULT hr = CeRapiInit();
   if ( hr != ERROR_SUCCESS )
      { return FALSE; }

The next few lines are commented, but included here for the following reason. As you've noticed if you've built and run the RapiDemo program over a serial link, it takes a long time to initialize the tree control that displays the registry. For this reason, we only show one of the root Registry hierarchies in RapiDemo's tree control. However, in any practical application, you'd probably want to see the whole Registry, not just the shortest tree, and most likely you'd have an Ethernet link, so the performance issue would be moot. The following commented lines show the HKEY constants you'd use if you wanted to open and traverse all of the Registry hierarchy, along with properly formatted tree control captions.


   CString             szBaseKeys[4];
   HKEY                hRootKeys[4];

   szBaseKeys[0]= _T("HKEY_CLASSES_ROOT");
   szBaseKeys[1]= _T("HKEY_CURRENT_USER");
   szBaseKeys[2]= _T("HKEY_LOCAL_MACHINE");
   szBaseKeys[3]= _T("HKEY_USERS");

   hRootKeys[0]= HKEY_CLASSES_ROOT;
   hRootKeys[1]= HKEY_CURRENT_USER;
   hRootKeys[2]= HKEY_LOCAL_MACHINE;
   hRootKeys[3]= HKEY_USERS;

To show icons next to the tree control items, we must create and initialize an image list control. The parameters to Create() are the x and y dimensions of the bitmaps we'll add to the image list, the mask that is used to display the images, the number of bitmaps the image list will initially hold, and the number of bitmaps by which the image list can grow.

CPropertyPage::OnInitDialog();    // let the base class do the
                                  // default work
pImageList = new CImageList();
pImageList->Create(16, 16, ILC_COLOR, 2, 0);

Next, we load a single bitmap resource, which contains both image bitmaps. We add the bitmaps to the image list, and delete the bitmap object. Because we allocated the image list on the heap with new, we use delete to dispose of it in the destructor for this class.

pImageList->Add(&bitmap, (CBitmap * )NULL);

Next, we set the image list in the tree control. The parameters to SetImageList() are a pointer to the initialized image list object and a flag that means that these images are to be used as tree item icons.

m_RegTree.SetImageList(pImageList, TVSIL_NORMAL);

Now, we open one of the four root Registry keys, HKEY_CURRENT_USER.

                    0, KEY_ALL_ACCESS, &hKey );
if( rc != ERROR_SUCCESS )
{ return FALSE; }

We get a count of the children for this key, calling CeRegQueryInfoKey().

// query for count of children
DWORD dwNumChildren;
                   NULL, NULL, 0, &dwNumChildren,
                   NULL, NULL, NULL,
                   NULL, NULL, NULL, NULL);

Now, we insert the root key in the tree view, calling the CWalkReg member InsertTreeItem(), and capture the handle to the tree item it returns.

m_rghItem = InsertTreeItem( NULL, "HKEY_CURRENT_USER", 0,
                            dwNumChildren, hKey );

If the key has children, we call WalkRegTree(), which will recursively walk out the Registry tree, adding and initializing tree control items as it goes.

   if( dwNumChildren > 0 )
      WalkRegTree( hKey, m_rghItem );

   return FALSE;

Looking Ahead

In the next article, we'll use RAPI to find databases on the remote machine. In particular, you'll see how to find and manipulate the native databases for CE integrated applications.

About the Author

Nancy Nicolaisen is a software engineer who has designed and implemented highly modular Windows CE products that include features such as full remote diagnostics, CE-side data compression, dynamically constructed user interface, automatic screen size detection, and entry time data validation.

In addition to writing for Developer.com, she has written several books, including Making Win 32 Applications Mobile.

# # #

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date