home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / Chip_2002-02_cd1.bin / sharewar / apaths / APSOURCE.ZIP / GetPKeys.c < prev    next >
C/C++ Source or Header  |  2001-03-26  |  2KB  |  88 lines

  1. /* GetPKeys - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This function searches the MS Windows 95/NT System Registry,
  6. **      enumerating all AppPath key values it finds.
  7. **
  8. **      Called:     list = Handle to the ListView control to be filled.
  9. **
  10. **      Returns:    TRUE upon success, or FALSE if an error exists.
  11. **
  12. **      Notes:      This routine searchs the following key:
  13. **
  14. **                      HKEY_LOCAL_MACHINE
  15. **                        Software
  16. **                          Microsoft
  17. **                            Windows
  18. **                              CurrentVersion
  19. **                                AppPaths
  20. **                                  PROGRAM.EXE = d:\folder\program.exe
  21. **
  22. */
  23.  
  24.  
  25. #include "AppPaths.h"
  26.  
  27. extern BOOL far GetPKeys (HWND list)
  28. {
  29.     auto HKEY       key     = NULL;
  30.     auto DWORD      inx     = NIL;
  31.     auto LV_ITEM    item    = { NIL };
  32.  
  33.     auto LONG       err;
  34.     auto DWORD      size;
  35.  
  36.     auto char       sub[PSTRING];
  37.     auto char       value[KSTRING];
  38.  
  39.     auto char       folder[PSTRING];
  40.     auto char       path[KSTRING];
  41.  
  42.     lstrcpy (sub,REGSTR_PATH_APPPATHS);
  43.  
  44.     err = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  45.                         sub,
  46.                         NIL,
  47.                         KEY_READ,
  48.                         &key);
  49.  
  50.     if (err != ERROR_SUCCESS)
  51.         return (FALSE);
  52.  
  53.     ListView_DeleteAllItems (list);
  54.  
  55.     do {
  56.  
  57.         size = KSTRING;
  58.  
  59.         if ((err = RegEnumKeyEx (key,inx,value,&size,NULL,NULL,NULL,NULL)) != ERROR_SUCCESS) {
  60.             inx++;
  61.             continue;
  62.             }
  63.  
  64.         item.mask = LVIF_TEXT;
  65.  
  66.         item.iItem = inx;
  67.         item.iSubItem = COLUMN_1;
  68.         item.pszText = value;
  69.         
  70.         ListView_InsertItem (list,&item);
  71.  
  72.         GetPString (value,BLANK_STR,    BLANK_STR,folder,  PSTRING);
  73.         GetPString (value,"Path",       BLANK_STR,path,    KSTRING);
  74.  
  75.         ListView_SetItemText (list,inx,COLUMN_2,folder);
  76.         ListView_SetItemText (list,inx,COLUMN_3,path);
  77.  
  78.         inx++;
  79.  
  80.         } while (err != ERROR_NO_MORE_ITEMS);
  81.  
  82.     if (key) RegCloseKey (key);
  83.  
  84.     return ((inx) ? TRUE : FALSE);
  85. }
  86.  
  87. /* end of GetRKeys.c - written by Gregory Braun */
  88.