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

  1. /* PickApp - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This function displays the standard MS Windows 95/NT file
  6. **      browser dialog box and allows the user to select a file.
  7. **
  8. **      Called:     w        = window handle to the parent.
  9. **                  filespec = a pointer to the file name buffer
  10. **
  11. **      Returns:    TRUE upon success, or FALSE if an error exists
  12. **                  or the user pressed the [Cancel] button.
  13. **
  14. **                  The "filespec" buffer passed as an arguement to this
  15. **                  routine will contain the user's file selection. This
  16. **                  file name will include the full drive, path and
  17. **                  file specification.
  18. */
  19.  
  20. #include "AppPaths.h"
  21.  
  22. #define CAPTION         "Select an Application"
  23. #define FILTER          "Application Files|*.exe;*.com;*.bat;*.lnk|All Files|*.*|"
  24. #define DELIMITER       '|'
  25.  
  26.  
  27. extern BOOL far PickApp (HWND w,LPSTR filespec)
  28. {
  29.     static DWORD        finx    = 1;
  30.     auto OPENFILENAME   fn      = { sizeof (OPENFILENAME) };   
  31.  
  32.     auto char           filter[PSTRING];
  33.     auto char           filename[PSTRING];
  34.     
  35.     auto int            index;        
  36.     
  37.     auto BOOL           good;
  38.     
  39.     lstrcpy (filename,filespec);
  40.     lstrcpy (filter,FILTER);
  41.         
  42.     for (index = NIL; filter[index]; index++)        
  43.         if (filter[index] == DELIMITER)            
  44.             filter[index] = EOS;    
  45.  
  46.     fn.hInstance            = applet;
  47.     fn.hwndOwner            = w;        
  48.     fn.lpstrFilter          = filter;    
  49.     fn.nFilterIndex         = finx;
  50.         
  51.     fn.lpstrFile            = filename;    
  52.     fn.nMaxFile             = PSTRING;    
  53.     fn.nMaxFileTitle        = PSTRING;  
  54.     
  55.     fn.lpstrTitle           = CAPTION;
  56.     
  57.     fn.Flags                = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST
  58.                             | OFN_EXPLORER | OFN_HIDEREADONLY;
  59.  
  60.  
  61.     good = GetOpenFileName (&fn);
  62.     
  63.     UpdateWindow (w);
  64.  
  65.     if (!good) return (FALSE);        
  66.  
  67.     lstrcpy (filespec,fn.lpstrFile);    
  68.     
  69.     finx = fn.nFilterIndex;
  70.     
  71.     return (TRUE);
  72. }                      
  73.  
  74. /* end of PickApp.c - written by Gregory Braun */
  75.