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

  1. /* PickPath - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This module displays a folder selection dialog and allows
  6. **      the user to select an exisiting folder from the list.
  7. **
  8. **      Called:     w    = Window handle of the parent.
  9. **                  msg  = Message prompt string to be displayed.
  10. **                  path = Buffer to contain selected folder path.
  11. **
  12. **      Returns:    TRUE upon success, or FALSE if an error exists.
  13. **                  The "path" will contain the folder selected by the
  14. **                  user when the [Open] button is selected.
  15. **
  16. **      Notes:      This routine uses the standard MS Windows 9x/NT
  17. **                  Folder selection dialog box.
  18. **
  19. **                  If the "path" buffer passed as an arguement to
  20. **                  this function contains a valid folder that
  21. **                  directory will be selected and made the starting
  22. **                  point for all subsequent path specifications.
  23. */
  24.  
  25. #include "AppPaths.h"
  26.  
  27. static int CALLBACK     reflect    (HWND w,UINT msg,WPARAM wp,LPARAM lp);
  28.  
  29. extern BOOL far PickPath (HWND w,LPCSTR msg,LPSTR path)
  30. {
  31.     auto BROWSEINFO     info = { NIL };
  32.     auto BOOL           pick = FALSE;
  33.  
  34.     auto LPMALLOC       m;
  35.     auto LPSTR          tmp;
  36.  
  37.     auto LPITEMIDLIST   root;
  38.     auto LPITEMIDLIST   user;
  39.  
  40.     if (SHGetMalloc (&m) == E_FAIL)
  41.         return (FALSE);
  42.  
  43.     if ((tmp = (LPSTR) m->lpVtbl->Alloc (m,KSTRING)) == NULL)
  44.         return (FALSE);
  45.  
  46.     SHGetSpecialFolderLocation (w,CSIDL_DESKTOP,&root);
  47.     
  48.     info.hwndOwner      = w;
  49.     info.pidlRoot       = root;
  50.     info.pszDisplayName = tmp;
  51.  
  52.     info.lpszTitle      = (msg && *msg) ? msg : "Select a folder";
  53.  
  54.     info.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
  55.     info.lParam         = (LPARAM) path;
  56.     info.lpfn           = (BFFCALLBACK) reflect;
  57.  
  58.     if ((user = SHBrowseForFolder (&info)) != NULL) {
  59.  
  60.         SHGetPathFromIDList (user,tmp);
  61.         lstrcpy (path,tmp);
  62.         m->lpVtbl->Free (m,user);
  63.  
  64.         pick = TRUE;
  65.         }
  66.  
  67.     m->lpVtbl->Free (m,root);
  68.     m->lpVtbl->Free (m,tmp);
  69.  
  70.     return (pick);
  71. }
  72.  
  73. static int CALLBACK reflect (HWND w,UINT msg,WPARAM wp,LPARAM lp)
  74. {
  75.     auto LPITEMIDLIST   list;
  76.     auto char           path[KSTRING];
  77.  
  78.     switch (msg) {
  79.  
  80.         case BFFM_INITIALIZED :
  81.              SendMessage (w,BFFM_SETSELECTION,TRUE,lp);
  82.              break;
  83.  
  84.         case BFFM_SELCHANGED :
  85.              list = (LPITEMIDLIST) wp;
  86.              SHGetPathFromIDList (list,path);
  87.              SendMessage (w,BFFM_SETSTATUSTEXT,NIL,(LPARAM) path);
  88.              break;
  89.              }
  90.  
  91.     return (FALSE);
  92. }
  93.  
  94. /* end of PickPath.c - written by Gregory Braun */
  95.