home *** CD-ROM | disk | FTP | other *** search
/ Mastering Computers 3 / Mastering Computers Vol 3.iso / Win95 / Fun&Utils / STRTMENU.EXE / DELGROUP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-21  |  3.3 KB  |  118 lines

  1. /**************************************************************************
  2.  
  3.    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4.    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5.    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6.    PARTICULAR PURPOSE.
  7.  
  8.    Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  9.  
  10.    File:          DelGroup.cpp
  11.    
  12.    Description:   Provides the functionality for deleting a group.
  13.  
  14. **************************************************************************/
  15.  
  16. #define STRICT
  17.  
  18. /**************************************************************************
  19.    Include Files
  20. **************************************************************************/
  21.  
  22. #include <windows.h>
  23. #include <windowsx.h>
  24. #include <shlobj.h>
  25. #include "globals.h"
  26. #include "resource.h"
  27.  
  28. /**************************************************************************
  29.    Local Function Prototypes
  30. **************************************************************************/
  31.  
  32. BOOL DeleteFolder(HWND, LPSTR);
  33.  
  34. /**************************************************************************
  35.    Global Variables
  36. **************************************************************************/
  37.  
  38. /**************************************************************************
  39.  
  40.    DeleteGroup()
  41.  
  42. **************************************************************************/
  43.  
  44. BOOL DeleteGroup(HWND hWnd)
  45. {
  46. LPITEMIDLIST   pidlPrograms,
  47.                pidlFolder;
  48. char           szPath[MAX_PATH];
  49.  
  50. //get the pidl for the programs group - this will be used to initialize the folder browser
  51. SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &pidlPrograms);
  52.  
  53. //get the group/folder to be deleted
  54. if(!GetFolder(hWnd, &pidlFolder, pidlPrograms, szPath, "Select group to delete"))
  55.    return FALSE;
  56.  
  57. //get the path for the chosen group/folder
  58. SHGetPathFromIDList(pidlFolder, szPath);
  59.  
  60. //delete the group/folder
  61. if(!DeleteFolder(hWnd, szPath))
  62.    return FALSE;
  63.  
  64. return TRUE;
  65. }
  66.  
  67. /**************************************************************************
  68.  
  69.    DeleteFolder()
  70.  
  71. **************************************************************************/
  72.  
  73. BOOL DeleteFolder(HWND hWnd, LPSTR lpszFolder)
  74. {
  75. char              szFile[MAX_PATH];
  76. SHFILEOPSTRUCT    fos;
  77. WIN32_FIND_DATA   FindData;
  78. HANDLE            hFind;
  79. BOOL              bFindFile = TRUE;
  80.  
  81. //we can't remove a directory that is not empty, so we need to empty this one
  82.  
  83. lstrcpy(szFile, lpszFolder);
  84. lstrcat(szFile, "\\*.*");
  85.  
  86. ZeroMemory(&fos, sizeof(fos));
  87. fos.hwnd = hWnd;
  88. fos.wFunc = FO_DELETE;
  89. fos.fFlags = FOF_SILENT | FOF_ALLOWUNDO;   //send to the recycle bin
  90.  
  91. hFind = FindFirstFile(szFile, &FindData);
  92.  
  93. while((INVALID_HANDLE_VALUE != hFind) && bFindFile)
  94.    {
  95.    if(*(FindData.cFileName) != '.')
  96.       {
  97.       //copy the path and file name to our temp buffer
  98.       lstrcpy(szFile, lpszFolder);
  99.       lstrcat(szFile, "\\");
  100.       lstrcat(szFile, FindData.cFileName);
  101.       //add a second NULL because SHFileOperation is looking for this
  102.       lstrcat(szFile, "\0");
  103.  
  104.       //delete the file
  105.       fos.pFrom = szFile;
  106.       SHFileOperation(&fos);
  107.       }
  108.  
  109.    //find the next file
  110.    bFindFile = FindNextFile(hFind, &FindData);
  111.    }
  112.  
  113. FindClose(hFind);   
  114.  
  115. return RemoveDirectory(lpszFolder);
  116. }
  117.  
  118.