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

  1. /* EditRun - March 26th, 2001
  2. **
  3. **      Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
  4. **
  5. **      This function opens and displays a dialog box allowing the user
  6. **      to edit a specific Run registry entry.
  7. **
  8. **      Called:     w   = window handle of the parent.
  9. **                  run = a pointer to the RUN data structure.
  10. **
  11. **      Returns:    TRUE upon success, or FALSE if an error exists,
  12. **                  or the user pressed the [Cancel] key.
  13. */
  14.  
  15. #include "AppPaths.h"
  16.  
  17.  
  18. #define MISSING_NAME        "Startup title missing.\r\r" \
  19.                             "Startup registry values require a startup title.\r" \
  20.                             "Please specify a title for this registry entry."
  21.  
  22. #define MISSING_PATH        "Program command missing.\r\r" \
  23.                             "Startup registry values require a program command.\r" \
  24.                             "Please specify a program for this registry entry."
  25.  
  26.  
  27. static RUN                  tmp;        // just in case the user cancels.
  28.  
  29.  
  30. static BOOL CALLBACK        dialog      (HWND dlg,UINT msg,WPARAM wp,LPARAM lp);
  31.  
  32. static BOOL                 initiate    (HWND dlg,LPRUN tmp);
  33. static BOOL                 verify      (HWND dlg,LPRUN tmp);
  34.  
  35. static BOOL                 path        (HWND dlg,LPRUN tmp);
  36.  
  37. extern BOOL far EditRun (HWND w,LPRUN run)
  38. {
  39.     tmp = *run;
  40.  
  41.     if (!DialogBoxParam (applet,(LPCSTR) RUN_DLG,w,(DLGPROC) dialog,(LPARAM) &tmp))
  42.         return (FALSE);
  43.  
  44.     *run = tmp;
  45.  
  46.     return (TRUE);
  47. }
  48.  
  49. static BOOL CALLBACK dialog (HWND dlg,UINT msg,WPARAM wp,LPARAM lp)
  50. {
  51.     auto int    item    = LOWORD (wp);
  52.  
  53.     switch (msg) {
  54.  
  55.         case WM_INITDIALOG :
  56.              return (initiate (dlg,(LPRUN) lp));
  57.              break;
  58.  
  59.         case WM_HELP :
  60.              HelpTip (dlg,((LPHELPINFO) lp)->iCtrlId);
  61.              break;
  62.  
  63.         case WM_COMMAND :
  64.  
  65.              switch (item) {
  66.  
  67.                 case RUN_PATH_BTN :
  68.                      path (dlg,&tmp);
  69.                      break;
  70.  
  71.                 case RUN_HELP_BTN :
  72.                      HelpTopic (dlg,RUN_DLG);
  73.                      break;
  74.  
  75.                 case IDOK :
  76.                      if (verify (dlg,&tmp))
  77.                          EndDialog (dlg,TRUE);
  78.                      return (TRUE);
  79.                      break;
  80.  
  81.                 case IDCANCEL :
  82.                      EndDialog (dlg,FALSE);
  83.                      return (TRUE);
  84.                      break;
  85.                      }
  86.  
  87.              break;
  88.              }
  89.  
  90.  
  91.      return (FALSE);
  92. }
  93.  
  94. static BOOL initiate (HWND dlg,LPRUN tmp)
  95. {
  96.     auto HWND   ctl = GetDlgItem (dlg,RUN_ICON_PIC);
  97.     auto HICON  ico = ExtractIcon (applet,tmp->path,NIL);
  98.  
  99.     if ((DWORD) ico < 33)
  100.         ico = LoadIcon (applet,(LPCSTR) WINDOWS_ICON);
  101.  
  102.     SetDlgIcon (dlg,APPLICATION_ICON);
  103.  
  104.     Static_SetIcon (ctl,ico);
  105.  
  106.     SetDlgItemSize (dlg,RUN_NAME_TXT,PSTRING);
  107.     SetDlgItemText (dlg,RUN_NAME_TXT,tmp->name);
  108.  
  109.     SetDlgItemSize (dlg,RUN_PATH_TXT,RUN_MAX);
  110.     SetDlgItemText (dlg,RUN_PATH_TXT,tmp->path);
  111.  
  112.     return (TRUE);
  113. }
  114.  
  115. static BOOL verify (HWND dlg,LPRUN tmp)
  116. {
  117.     GetDlgItemText (dlg,RUN_NAME_TXT,tmp->name,PSTRING);
  118.     GetDlgItemText (dlg,RUN_PATH_TXT,tmp->path,RUN_MAX);
  119.  
  120.     if (!*tmp->name) {
  121.         Message (dlg,NULL,MISSING_NAME);
  122.         return (SetDFocus (dlg,RUN_NAME_TXT));
  123.         }
  124.  
  125.     if (!*tmp->path) {
  126.         Message (dlg,NULL,MISSING_PATH);
  127.         return (SetDFocus (dlg,RUN_PATH_TXT));
  128.         }
  129.  
  130.     return (TRUE);
  131. }
  132.  
  133. static BOOL path (HWND dlg,LPRUN tmp)
  134. {
  135.     auto HWND   ctl = GetDlgItem (dlg,RUN_ICON_PIC);
  136.     auto HICON  ico = ExtractIcon (applet,tmp->path,NIL);
  137.  
  138.     GetDlgItemText (dlg,RUN_PATH_TXT,tmp->path,PSTRING);
  139.  
  140.     if (!PickApp (dlg,tmp->path))
  141.         return (FALSE);
  142.  
  143.     if (lstrlen (tmp->path) >= RUN_MAX)
  144.         tmp->path[RUN_MAX] = EOS;
  145.  
  146.     SetDlgItemText (dlg,RUN_PATH_TXT,tmp->path);
  147.  
  148.     ico = ExtractIcon (applet,tmp->path,NIL);
  149.  
  150.     if ((DWORD) ico < 33)
  151.         ico = LoadIcon (applet,(LPCSTR) WINDOWS_ICON);
  152.  
  153.     Static_SetIcon (ctl,ico);
  154.  
  155.     return (TRUE);
  156. }
  157.  
  158. /* end of EditRun.c - written by Gregory Braun */
  159.