home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 19 Printer / 19-Printer.zip / LAPRINT.ZIP / LAPRINT0.C < prev    next >
C/C++ Source or Header  |  1991-01-23  |  148KB  |  3,004 lines

  1.  
  2. /************************************************************************
  3. *                                                                       *
  4. *  (c) Cray Research, Inc., 1991.  All rights reserved.                 *
  5. *                                                                       *
  6. *     This program and/or module and all modifications made by Cray     *
  7. *  Research, Inc., are the sole property of Cray Research, Inc., and    *
  8. *  shall not be made available to or used by any person or persons      *
  9. *  without the prior written permission of Cray Research, Inc.          *
  10. *                                                                       *
  11. *     Programs and/or modules which are deemed in the public domain or  *
  12. *  whose copyright is held by another legal entity other than Cray      *
  13. *  Research, Inc., shall be deemed excluded from the above named        *
  14. *  restrictions and protections.                                        *
  15. *                                                                       *
  16. *     All changes made by Cray Research Inc which represent original    *
  17. *  work, modifications, descriptions or ideas to the above excluded     *
  18. *  programs and/or modules shall not be made available to or used by    *
  19. *  any person or persons without the prior written permission of        *
  20. *  Cray Research, Inc.                                                  *
  21. *                                                                       *
  22. ************************************************************************/
  23.        
  24. #define  EXTERN extern
  25. #include "LAPRINT.h"
  26.  
  27.  
  28. /***************************************************************************/
  29. /*                                                                         */
  30. /* Dialog Window Procedure                                                 */
  31. /*                                                                         */
  32. /* This procedure is associated with the dialog box that is included in    */
  33. /* the function name of the procedure. It provides the service routines    */
  34. /* for the events (messages) that occur because the end user operates      */
  35. /* one of the dialog box's buttons, entry fields, or controls.             */
  36. /*                                                                         */
  37. /* The SWITCH statement in the function distributes the dialog box         */
  38. /* messages to the respective service routines, which are set apart by     */
  39. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  40. /* procedures must provide an appropriate service routine for their end    */
  41. /* user initiated messages as well as for the general PM messages (like    */
  42. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  43. /* which there is no programmed CASE condition (no service routine),       */
  44. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  45. /* disposed of by PM.                                                      */
  46. /*                                                                         */
  47. /***************************************************************************/
  48.  
  49. MRESULT EXPENTRY CFGOPENMsgProc(hWndDlg, message, mp1, mp2)
  50. HWND hWndDlg;
  51. USHORT message;
  52. MPARAM mp1;
  53. MPARAM mp2;
  54.  
  55.  static CHAR szCRI_Copyright[]="(c) Cray Research, Inc., 1991.";
  56.  
  57.  static SHORT sfValidate = TRUE;
  58.  INT    i;
  59.  static CHAR  szWorkBuf[90];
  60.  static HWND  hWndParent;
  61.  CFGOPENStruct FAR *Cfgopen;
  62.           
  63.  switch(message)
  64.    {
  65.     case WM_INITDLG:
  66.          Cfgopen = (CFGOPENStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_CFGOPEN);
  67.          hWndParent = (HWND)mp2;
  68.          cwCenter(hWndDlg, (HWND)hWndParent);
  69.          /* Initialize entry field control: szConfig_Directory             */
  70.          WinSendDlgItemMsg(hWndDlg, DID_CURRENT_DIR, EM_SETTEXTLIMIT, MPFROMSHORT(100), 0L);
  71.          if(Cfgopen->szConfig_Directory[0])
  72.             WinSetDlgItemText(hWndDlg, DID_CURRENT_DIR, Cfgopen->szConfig_Directory);
  73.          /* Initialize entry field control: szConfig_Filename              */
  74.          WinSendDlgItemMsg(hWndDlg, DID_CONFIG_FN, EM_SETTEXTLIMIT, MPFROMSHORT(100), 0L);
  75.          if(Cfgopen->szConfig_Filename[0])
  76.             WinSetDlgItemText(hWndDlg, DID_CONFIG_FN, Cfgopen->szConfig_Filename);
  77.          /* Initialize list box control:                                   */
  78.          cwFillDirListBox(hWndDlg, DID_DIRECTORY, DID_CURRENT_DIR);
  79.          /* Initialize list box control:                                   */
  80.          cwFillFileListBox(hWndDlg, "*.ini", DID_FILES);
  81.  
  82.          WinEnableWindow((WinWindowFromID(hWndDlg,
  83.                                           DID_CURRENT_DIR)),
  84.                          FALSE);
  85.  
  86.          WinEnableWindow((WinWindowFromID(hWndDlg,
  87.                                           DID_CONFIG_FN)),
  88.                          FALSE);
  89.  
  90.          break; /* End of WM_INITDLG */
  91.    
  92.     case WM_CONTROL:
  93.          switch(SHORT1FROMMP(mp1))
  94.            {
  95.             case DID_CURRENT_DIR: /* Entry field variable: "szConfig_Directory" */
  96.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  97.                    { 
  98.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  99.                          break;
  100.  
  101.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  102.                          break;
  103.  
  104.                     default: /* Default other messages                     */
  105.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  106.                          break;
  107.                    }
  108.                  break;
  109.  
  110.             case DID_CONFIG_FN: /* Entry field variable: "szConfig_Filename" */
  111.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  112.                    { 
  113.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  114.                          break;
  115.  
  116.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  117.                          break;
  118.  
  119.                     default: /* Default other messages                     */
  120.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  121.                          break;
  122.                    }
  123.                  break;
  124.  
  125.             case DID_DIRECTORY: /* List box                                */
  126.                  {
  127.                   USHORT sSelect;       /* index to selected listbox item  */
  128.                   USHORT CurDisk;       /* number of the current disk      */
  129.                   ULONG  DriveMap;      /* logical drive map               */
  130.                   CHAR   szBuffer[100];
  131.  
  132.                   /* If the user has not pressed enter or double clicked   */
  133.                   /* the mouse on an item, then break out of this case     */
  134.                   if(SHORT2FROMMP(mp1) != LN_ENTER)
  135.                      break;
  136.  
  137.                    /* Determine the index to the selected item             */
  138.                    sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
  139.                                                        SHORT1FROMMP(mp1),
  140.                                                        LM_QUERYSELECTION,
  141.                                                        0L, 0L);
  142.  
  143.                    /* Query the text of the selected item                  */
  144.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1),
  145.                                      LM_QUERYITEMTEXT,
  146.                                      MPFROM2SHORT(sSelect, sizeof(szBuffer)),
  147.                                      MPFROMP(szBuffer));
  148.  
  149.                    /* Is the selected item a drive or directory            */
  150.                    if(szBuffer[0] == '[' && 
  151.                       szBuffer[2] == ':' && 
  152.                       szBuffer[3] == ']')
  153.                      {
  154.                       /* Save current drive in case of error               */
  155.                       DosQCurDisk(&CurDisk, &DriveMap);
  156.                       /* Log to new drive, on error restore to previous    */
  157.                       if(DosSelectDisk(szBuffer[1] - '@') != 0)
  158.                          DosSelectDisk(CurDisk);
  159.                       /* Fill the listbox with new directory information   */
  160.                       /* if an error occurs, restore to previous drive     */
  161.                       if(cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_CURRENT_DIR) == -1)
  162.                         {
  163.                          WinLoadString(hAB, 0, IDS_DISK_ERR,
  164.                                        sizeof(szBuffer), szBuffer);
  165.                          WinMessageBox(HWND_DESKTOP, hWndDlg,
  166.                                        szBuffer, szAppName,
  167.                                        0, MB_OK | MB_INFORMATION);
  168.                          DosSelectDisk(CurDisk);
  169.                          cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_CURRENT_DIR);
  170.                         }
  171.                       cwFillFileListBox(hWndDlg, "*.ini", DID_FILES);
  172.                      }
  173.                    else /* A directory was selected                        */
  174.                      {
  175.                       /* Change to new directory                           */
  176.                       DosChDir(szBuffer, 0L);
  177.                       /*  Fill the listbox with new directory information  */
  178.                       cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_CURRENT_DIR);
  179.                       cwFillFileListBox(hWndDlg, "*.ini", DID_FILES);
  180.                      }
  181.                  }
  182.                  break;
  183.  
  184.             case DID_FILES: /* List box                                    */
  185.                  {
  186.                    USHORT sSelectIndex;
  187.                    CHAR   szSelectText[80];   
  188.  
  189.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  190.                        break;
  191.  
  192.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  193.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  194.  
  195.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  196.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  197.                                    MPFROMP(szSelectText));
  198.                    WinSetDlgItemText(hWndDlg, DID_CONFIG_FN, szSelectText);
  199.                  }
  200.                  break;
  201.  
  202.            }
  203.          break; /* End of WM_CONTROL */
  204.    
  205.     case WM_COMMAND:
  206.          switch(SHORT1FROMMP(mp1))
  207.            {
  208.             case DID_OK: /* Button text: "Open"                            */
  209.                   Cfgopen = (CFGOPENStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_CFGOPEN);
  210.                  /* Query the string value in the entry field control and  */
  211.                  /* move the string value to the dialog structure variable */
  212.                  WinQueryDlgItemText(hWndDlg, DID_CURRENT_DIR,
  213.                                      sizeof(Cfgopen->szConfig_Directory),
  214.                                      Cfgopen->szConfig_Directory);
  215.                  if(Cfgopen->szConfig_Directory[0] == 0)
  216.                    {
  217.                     /* If required field is not completed inform user and  */
  218.                     /* query what he wants to do about it by presenting a  */
  219.                     /* message box with the push buttons "Retry" and       */
  220.                     /* "Cancel"                                            */
  221.                     strcpy(szWorkBuf, "Directory field not completed");
  222.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  223.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  224.                     
  225.                     /* If the user presses "Cancel", post a message to the */
  226.                     /* DID_CANCEL case and break out of this case          */
  227.                     if(i == MBID_CANCEL)
  228.                       {
  229.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  230.                        break;
  231.                       }
  232.  
  233.                     /* If the user presses "Retry", set focus to the       */
  234.                     /* control that needs to be completed and break out    */
  235.                     /* of this case                                        */
  236.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_CURRENT_DIR));
  237.                     break;
  238.                    }
  239.                  /* Query the string value in the entry field control and  */
  240.                  /* move the string value to the dialog structure variable */
  241.                  WinQueryDlgItemText(hWndDlg, DID_CONFIG_FN,
  242.                                      sizeof(Cfgopen->szConfig_Filename),
  243.                                      Cfgopen->szConfig_Filename);
  244.                  if(Cfgopen->szConfig_Filename[0] == 0)
  245.                    {
  246.                     /* If required field is not completed inform user and  */
  247.                     /* query what he wants to do about it by presenting a  */
  248.                     /* message box with the push buttons "Retry" and       */
  249.                     /* "Cancel"                                            */
  250.                     strcpy(szWorkBuf, "Configuration filename field not completed");
  251.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  252.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  253.                     
  254.                     /* If the user presses "Cancel", post a message to the */
  255.                     /* DID_CANCEL case and break out of this case          */
  256.                     if(i == MBID_CANCEL)
  257.                       {
  258.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  259.                        break;
  260.                       }
  261.  
  262.                     /* If the user presses "Retry", set focus to the       */
  263.                     /* control that needs to be completed and break out    */
  264.                     /* of this case                                        */
  265.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_CONFIG_FN));
  266.                     break;
  267.                    }
  268.  
  269.                  if(BgmReadConfigFile(hWndDlg) == TRUE)
  270.                  {
  271.                  WinDismissDlg(hWndDlg, TRUE);
  272.                  }
  273.                  break;
  274.  
  275.             case DID_CANCEL: /* Button text: "Cancel"                      */
  276.                  /* Ignore data values entered into the dialog controls    */
  277.                  /* and dismiss the dialog window                          */
  278.                  WinDismissDlg(hWndDlg, FALSE);
  279.                  break;
  280.  
  281.             case DID_HELP: /* Button text: "Help"                          */
  282.                  break;
  283.  
  284.            }
  285.          break; /* End of WM_COMMAND */
  286.                                
  287.     case WM_CLOSE:
  288.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  289.          break; /* End of WM_CLOSE */
  290.            
  291.     case WM_FAILEDVALIDATE:
  292.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  293.          sfValidate = FALSE;
  294.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  295.          sfValidate = TRUE;
  296.          return((MRESULT)TRUE);
  297.          break; /* End of WM_FAILEDVALIDATE */
  298.  
  299.     default:
  300.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  301.          break;
  302.    }
  303.  return FALSE;
  304. } /* End of CFGOPENMsgProc */
  305.  
  306.  
  307. /***************************************************************************/
  308. /*                                                                         */
  309. /* Dialog Window Procedure                                                 */
  310. /*                                                                         */
  311. /* This procedure is associated with the dialog box that is included in    */
  312. /* the function name of the procedure. It provides the service routines    */
  313. /* for the events (messages) that occur because the end user operates      */
  314. /* one of the dialog box's buttons, entry fields, or controls.             */
  315. /*                                                                         */
  316. /* The SWITCH statement in the function distributes the dialog box         */
  317. /* messages to the respective service routines, which are set apart by     */
  318. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  319. /* procedures must provide an appropriate service routine for their end    */
  320. /* user initiated messages as well as for the general PM messages (like    */
  321. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  322. /* which there is no programmed CASE condition (no service routine),       */
  323. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  324. /* disposed of by PM.                                                      */
  325. /*                                                                         */
  326. /***************************************************************************/
  327.  
  328. MRESULT EXPENTRY CFGSAVEMsgProc(hWndDlg, message, mp1, mp2)
  329. HWND hWndDlg;
  330. USHORT message;
  331. MPARAM mp1;
  332. MPARAM mp2;
  333.  static SHORT sfValidate = TRUE;
  334.  INT    i;
  335.  static CHAR  szWorkBuf[90];
  336.  static HWND  hWndParent;
  337.  CFGSAVEStruct FAR *Cfgsave;
  338.           
  339.  switch(message)
  340.    {
  341.     case WM_INITDLG:
  342.          Cfgsave = (CFGSAVEStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_CFGSAVE);
  343.          hWndParent = (HWND)mp2;
  344.          cwCenter(hWndDlg, (HWND)hWndParent);
  345.          /* Initialize entry field control: szConfig_Directory             */
  346.          WinSendDlgItemMsg(hWndDlg, DID_CURRENT_DIR, EM_SETTEXTLIMIT, MPFROMSHORT(100), 0L);
  347.          if(Cfgsave->szConfig_Directory[0])
  348.             WinSetDlgItemText(hWndDlg, DID_CURRENT_DIR, Cfgsave->szConfig_Directory);
  349.          /* Initialize entry field control: szConfig_Filename              */
  350.          WinSendDlgItemMsg(hWndDlg, DID_CONFIG_FN, EM_SETTEXTLIMIT, MPFROMSHORT(100), 0L);
  351.          if(Cfgsave->szConfig_Filename[0])
  352.             WinSetDlgItemText(hWndDlg, DID_CONFIG_FN, Cfgsave->szConfig_Filename);
  353.          /* Initialize list box control:                                   */
  354.          cwFillDirListBox(hWndDlg, DID_DIRECTORY, DID_CURRENT_DIR);
  355.          /* Initialize list box control:                                   */
  356.          cwFillFileListBox(hWndDlg, "*.ini", DID_FILES);
  357.  
  358.          WinEnableWindow((WinWindowFromID(hWndDlg,
  359.                                           DID_CURRENT_DIR)),
  360.                          FALSE);
  361.  
  362.          break; /* End of WM_INITDLG */
  363.    
  364.     case WM_CONTROL:
  365.          switch(SHORT1FROMMP(mp1))
  366.            {
  367.             case DID_CURRENT_DIR: /* Entry field variable: "szConfig_Directory" */
  368.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  369.                    { 
  370.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  371.                          break;
  372.  
  373.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  374.                          break;
  375.  
  376.                     default: /* Default other messages                     */
  377.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  378.                          break;
  379.                    }
  380.                  break;
  381.  
  382.             case DID_CONFIG_FN: /* Entry field variable: "szConfig_Filename" */
  383.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  384.                    { 
  385.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  386.                          break;
  387.  
  388.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  389.                          break;
  390.  
  391.                     default: /* Default other messages                     */
  392.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  393.                          break;
  394.                    }
  395.                  break;
  396.  
  397.             case DID_DIRECTORY: /* List box                                */
  398.                  {
  399.                   USHORT sSelect;       /* index to selected listbox item  */
  400.                   USHORT CurDisk;       /* number of the current disk      */
  401.                   ULONG  DriveMap;      /* logical drive map               */
  402.                   CHAR   szBuffer[100];
  403.  
  404.                   /* If the user has not pressed enter or double clicked   */
  405.                   /* the mouse on an item, then break out of this case     */
  406.                   if(SHORT2FROMMP(mp1) != LN_ENTER)
  407.                      break;
  408.  
  409.                    /* Determine the index to the selected item             */
  410.                    sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
  411.                                                        SHORT1FROMMP(mp1),
  412.                                                        LM_QUERYSELECTION,
  413.                                                        0L, 0L);
  414.  
  415.                    /* Query the text of the selected item                  */
  416.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1),
  417.                                      LM_QUERYITEMTEXT,
  418.                                      MPFROM2SHORT(sSelect, sizeof(szBuffer)),
  419.                                      MPFROMP(szBuffer));
  420.  
  421.                    /* Is the selected item a drive or directory            */
  422.                    if(szBuffer[0] == '[' && 
  423.                       szBuffer[2] == ':' && 
  424.                       szBuffer[3] == ']')
  425.                      {
  426.                       /* Save current drive in case of error               */
  427.                       DosQCurDisk(&CurDisk, &DriveMap);
  428.                       /* Log to new drive, on error restore to previous    */
  429.                       if(DosSelectDisk(szBuffer[1] - '@') != 0)
  430.                          DosSelectDisk(CurDisk);
  431.                       /* Fill the listbox with new directory information   */
  432.                       /* if an error occurs, restore to previous drive     */
  433.                       if(cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_CURRENT_DIR) == -1)
  434.                         {
  435.                          WinLoadString(hAB, 0, IDS_DISK_ERR,
  436.                                        sizeof(szBuffer), szBuffer);
  437.                          WinMessageBox(HWND_DESKTOP, hWndDlg,
  438.                                        szBuffer, szAppName,
  439.                                        0, MB_OK | MB_INFORMATION);
  440.                          DosSelectDisk(CurDisk);
  441.                          cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_CURRENT_DIR);
  442.                         }
  443.                       cwFillFileListBox(hWndDlg, "*.ini", DID_FILES);
  444.                      }
  445.                    else /* A directory was selected                        */
  446.                      {
  447.                       /* Change to new directory                           */
  448.                       DosChDir(szBuffer, 0L);
  449.                       /*  Fill the listbox with new directory information  */
  450.                       cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_CURRENT_DIR);
  451.                       cwFillFileListBox(hWndDlg, "*.ini", DID_FILES);
  452.                      }
  453.                  }
  454.                  break;
  455.  
  456.             case DID_FILES: /* List box                                    */
  457.                  {
  458.                    USHORT sSelectIndex;
  459.                    CHAR   szSelectText[80];   
  460.  
  461.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  462.                        break;
  463.  
  464.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  465.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  466.  
  467.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  468.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  469.                                    MPFROMP(szSelectText));
  470.                    WinSetDlgItemText(hWndDlg, DID_CONFIG_FN, szSelectText);
  471.                  }
  472.                  break;
  473.  
  474.            }
  475.          break; /* End of WM_CONTROL */
  476.    
  477.     case WM_COMMAND:
  478.          switch(SHORT1FROMMP(mp1))
  479.            {
  480.             case DID_OK: /* Button text: "Save"                            */
  481.                   Cfgsave = (CFGSAVEStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_CFGSAVE);
  482.                  /* Query the string value in the entry field control and  */
  483.                  /* move the string value to the dialog structure variable */
  484.                  WinQueryDlgItemText(hWndDlg, DID_CURRENT_DIR,
  485.                                      sizeof(Cfgsave->szConfig_Directory),
  486.                                      Cfgsave->szConfig_Directory);
  487.                  if(Cfgsave->szConfig_Directory[0] == 0)
  488.                    {
  489.                     /* If required field is not completed inform user and  */
  490.                     /* query what he wants to do about it by presenting a  */
  491.                     /* message box with the push buttons "Retry" and       */
  492.                     /* "Cancel"                                            */
  493.                     strcpy(szWorkBuf, "Directory field not completed");
  494.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  495.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  496.                     
  497.                     /* If the user presses "Cancel", post a message to the */
  498.                     /* DID_CANCEL case and break out of this case          */
  499.                     if(i == MBID_CANCEL)
  500.                       {
  501.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  502.                        break;
  503.                       }
  504.  
  505.                     /* If the user presses "Retry", set focus to the       */
  506.                     /* control that needs to be completed and break out    */
  507.                     /* of this case                                        */
  508.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_CURRENT_DIR));
  509.                     break;
  510.                    }
  511.                  /* Query the string value in the entry field control and  */
  512.                  /* move the string value to the dialog structure variable */
  513.                  WinQueryDlgItemText(hWndDlg, DID_CONFIG_FN,
  514.                                      sizeof(Cfgsave->szConfig_Filename),
  515.                                      Cfgsave->szConfig_Filename);
  516.                  if(Cfgsave->szConfig_Filename[0] == 0 ||
  517.                     isspace((int)Cfgsave->szConfig_Filename[0]) != 0)
  518.                    {
  519.                     /* If required field is not completed inform user and  */
  520.                     /* query what he wants to do about it by presenting a  */
  521.                     /* message box with the push buttons "Retry" and       */
  522.                     /* "Cancel"                                            */
  523.                     strcpy(szWorkBuf, "Configuration filename field not completed");
  524.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  525.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  526.                     
  527.                     /* If the user presses "Cancel", post a message to the */
  528.                     /* DID_CANCEL case and break out of this case          */
  529.                     if(i == MBID_CANCEL)
  530.                       {
  531.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  532.                        break;
  533.                       }
  534.  
  535.                     /* If the user presses "Retry", set focus to the       */
  536.                     /* control that needs to be completed and break out    */
  537.                     /* of this case                                        */
  538.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_CONFIG_FN));
  539.                     break;
  540.                    }
  541.  
  542.                  if(BgmWriteConfigFile(hWndDlg,
  543.                                        FALSE)
  544.                   == TRUE)
  545.                  {
  546.                  WinDismissDlg(hWndDlg, TRUE);
  547.                  }
  548.                  break;
  549.  
  550.             case DID_CANCEL: /* Button text: "Cancel"                      */
  551.                  /* Ignore data values entered into the dialog controls    */
  552.                  /* and dismiss the dialog window                          */
  553.                  WinDismissDlg(hWndDlg, FALSE);
  554.                  break;
  555.  
  556.             case DID_HELP: /* Button text: "Help"                          */
  557.                  break;
  558.  
  559.            }
  560.          break; /* End of WM_COMMAND */
  561.                                
  562.     case WM_CLOSE:
  563.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  564.          break; /* End of WM_CLOSE */
  565.            
  566.     case WM_FAILEDVALIDATE:
  567.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  568.          sfValidate = FALSE;
  569.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  570.          sfValidate = TRUE;
  571.          return((MRESULT)TRUE);
  572.          break; /* End of WM_FAILEDVALIDATE */
  573.  
  574.     default:
  575.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  576.          break;
  577.    }
  578.  return FALSE;
  579. } /* End of CFGSAVEMsgProc */
  580.  
  581.  
  582. /***************************************************************************/
  583. /*                                                                         */
  584. /* Dialog Window Procedure                                                 */
  585. /*                                                                         */
  586. /* This procedure is associated with the dialog box that is included in    */
  587. /* the function name of the procedure. It provides the service routines    */
  588. /* for the events (messages) that occur because the end user operates      */
  589. /* one of the dialog box's buttons, entry fields, or controls.             */
  590. /*                                                                         */
  591. /* The SWITCH statement in the function distributes the dialog box         */
  592. /* messages to the respective service routines, which are set apart by     */
  593. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  594. /* procedures must provide an appropriate service routine for their end    */
  595. /* user initiated messages as well as for the general PM messages (like    */
  596. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  597. /* which there is no programmed CASE condition (no service routine),       */
  598. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  599. /* disposed of by PM.                                                      */
  600. /*                                                                         */
  601. /***************************************************************************/
  602.  
  603. MRESULT EXPENTRY FSELECTMsgProc(hWndDlg, message, mp1, mp2)
  604. HWND hWndDlg;
  605. USHORT message;
  606. MPARAM mp1;
  607. MPARAM mp2;
  608.  static SHORT sfValidate = TRUE;
  609.  INT    i;
  610.  static CHAR  szWorkBuf[90];
  611.  static HWND  hWndParent;
  612.  FSELECTStruct FAR *Fselect;
  613.           
  614.  switch(message)
  615.    {
  616.     case WM_INITDLG:
  617.          Fselect = (FSELECTStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_FSELECT);
  618.          hWndParent = (HWND)mp2;
  619.          cwCenter(hWndDlg, (HWND)hWndParent);
  620.          /* Initialize entry field control: szSelected_Directory           */
  621.          WinSendDlgItemMsg(hWndDlg, DID_SELECTED_DIR, EM_SETTEXTLIMIT, MPFROMSHORT(100), 0L);
  622.          if(Fselect->szSelected_Directory[0])
  623.             WinSetDlgItemText(hWndDlg, DID_SELECTED_DIR, Fselect->szSelected_Directory);
  624.          /* Initialize entry field control: szSelected_Filename            */
  625.          WinSendDlgItemMsg(hWndDlg, DID_SELECTED_FN, EM_SETTEXTLIMIT, MPFROMSHORT(100), 0L);
  626.          /* Initialize list box control:                                   */
  627.          cwFillDirListBox(hWndDlg, DID_DIRECTORY, DID_SELECTED_DIR);
  628.          /* Initialize list box control:                                   */
  629.          cwFillFileListBox(hWndDlg, "*.*", DID_FILES);
  630.  
  631.          if(BgmPrintActive == TRUE)
  632.          {
  633.            WinEnableWindow((WinWindowFromID(hWndDlg,
  634.                                             DID_PRINT)),
  635.                            FALSE);
  636.          }
  637.  
  638.          WinEnableWindow((WinWindowFromID(hWndDlg,
  639.                                           DID_SELECTED_DIR)),
  640.                          FALSE);
  641.  
  642.          WinEnableWindow((WinWindowFromID(hWndDlg,
  643.                                           DID_SELECTED_FN)),
  644.                          FALSE);
  645.  
  646.          hWndFSELECT = hWndDlg;
  647.          break; /* End of WM_INITDLG */
  648.    
  649.     case WM_CONTROL:
  650.          switch(SHORT1FROMMP(mp1))
  651.            {
  652.             case DID_SELECTED_DIR: /* Entry field variable: "szSelected_Directory" */
  653.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  654.                    { 
  655.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  656.                          break;
  657.  
  658.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  659.                          break;
  660.  
  661.                     default: /* Default other messages                     */
  662.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  663.                          break;
  664.                    }
  665.                  break;
  666.  
  667.             case DID_SELECTED_FN: /* Entry field variable: "szSelected_Filename" */
  668.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  669.                    { 
  670.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  671.                          break;
  672.  
  673.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  674.                          break;
  675.  
  676.                     default: /* Default other messages                     */
  677.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  678.                          break;
  679.                    }
  680.                  break;
  681.  
  682.             case DID_DIRECTORY: /* List box                                */
  683.                  {
  684.                   USHORT sSelect;       /* index to selected listbox item  */
  685.                   USHORT CurDisk;       /* number of the current disk      */
  686.                   ULONG  DriveMap;      /* logical drive map               */
  687.                   CHAR   szBuffer[100];
  688.  
  689.                   /* If the user has not pressed enter or double clicked   */
  690.                   /* the mouse on an item, then break out of this case     */
  691.                   if(SHORT2FROMMP(mp1) != LN_ENTER)
  692.                      break;
  693.  
  694.                    /* Determine the index to the selected item             */
  695.                    sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
  696.                                                        SHORT1FROMMP(mp1),
  697.                                                        LM_QUERYSELECTION,
  698.                                                        0L, 0L);
  699.  
  700.                    /* Query the text of the selected item                  */
  701.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1),
  702.                                      LM_QUERYITEMTEXT,
  703.                                      MPFROM2SHORT(sSelect, sizeof(szBuffer)),
  704.                                      MPFROMP(szBuffer));
  705.  
  706.                    /* Is the selected item a drive or directory            */
  707.                    if(szBuffer[0] == '[' && 
  708.                       szBuffer[2] == ':' && 
  709.                       szBuffer[3] == ']')
  710.                      {
  711.                       /* Save current drive in case of error               */
  712.                       DosQCurDisk(&CurDisk, &DriveMap);
  713.                       /* Log to new drive, on error restore to previous    */
  714.                       if(DosSelectDisk(szBuffer[1] - '@') != 0)
  715.                          DosSelectDisk(CurDisk);
  716.                       /* Fill the listbox with new directory information   */
  717.                       /* if an error occurs, restore to previous drive     */
  718.                       if(cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_SELECTED_DIR) == -1)
  719.                         {
  720.                          WinLoadString(hAB, 0, IDS_DISK_ERR,
  721.                                        sizeof(szBuffer), szBuffer);
  722.                          WinMessageBox(HWND_DESKTOP, hWndDlg,
  723.                                        szBuffer, szAppName,
  724.                                        0, MB_OK | MB_INFORMATION);
  725.                          DosSelectDisk(CurDisk);
  726.                          cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_SELECTED_DIR);
  727.                         }
  728.                       cwFillFileListBox(hWndDlg, "*.*", DID_FILES);
  729.                      }
  730.                    else /* A directory was selected                        */
  731.                      {
  732.                       /* Change to new directory                           */
  733.                       DosChDir(szBuffer, 0L);
  734.                       /*  Fill the listbox with new directory information  */
  735.                       cwFillDirListBox(hWndDlg, SHORT1FROMMP(mp1), DID_SELECTED_DIR);
  736.                       cwFillFileListBox(hWndDlg, "*.*", DID_FILES);
  737.                      }
  738.                  }
  739.                  break;
  740.  
  741.             case DID_FILES: /* List box                                    */
  742.                  {
  743.                    USHORT sSelectIndex;
  744.                    CHAR   szSelectText[80];   
  745.  
  746.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  747.                        break;
  748.  
  749.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  750.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  751.  
  752.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  753.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  754.                                    MPFROMP(szSelectText));
  755.                    WinSetDlgItemText(hWndDlg, DID_SELECTED_FN, szSelectText);
  756.                  }
  757.                  break;
  758.  
  759.            }
  760.          break; /* End of WM_CONTROL */
  761.    
  762.     case WM_COMMAND:
  763.          switch(SHORT1FROMMP(mp1))
  764.            {
  765.             case DID_OK: /* Button text: "Enter"                           */
  766.                   Fselect = (FSELECTStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_FSELECT);
  767.                  /* Query the string value in the entry field control and  */
  768.                  /* move the string value to the dialog structure variable */
  769.                  WinQueryDlgItemText(hWndDlg, DID_SELECTED_DIR,
  770.                                      sizeof(Fselect->szSelected_Directory),
  771.                                      Fselect->szSelected_Directory);
  772.                  if(Fselect->szSelected_Directory[0] == 0)
  773.                    {
  774.                     /* If required field is not completed inform user and  */
  775.                     /* query what he wants to do about it by presenting a  */
  776.                     /* message box with the push buttons "Retry" and       */
  777.                     /* "Cancel"                                            */
  778.                     strcpy(szWorkBuf, "Directory field not completed");
  779.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  780.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  781.                     
  782.                     /* If the user presses "Cancel", post a message to the */
  783.                     /* DID_CANCEL case and break out of this case          */
  784.                     if(i == MBID_CANCEL)
  785.                       {
  786.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  787.                        break;
  788.                       }
  789.  
  790.                     /* If the user presses "Retry", set focus to the       */
  791.                     /* control that needs to be completed and break out    */
  792.                     /* of this case                                        */
  793.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_SELECTED_DIR));
  794.                     break;
  795.                    }
  796.                  /* Query the string value in the entry field control and  */
  797.                  /* move the string value to the dialog structure variable */
  798.                  WinQueryDlgItemText(hWndDlg, DID_SELECTED_FN,
  799.                                      sizeof(Fselect->szSelected_Filename),
  800.                                      Fselect->szSelected_Filename);
  801.                  if(Fselect->szSelected_Filename[0] == 0)
  802.                    {
  803.                     /* If required field is not completed inform user and  */
  804.                     /* query what he wants to do about it by presenting a  */
  805.                     /* message box with the push buttons "Retry" and       */
  806.                     /* "Cancel"                                            */
  807.                     strcpy(szWorkBuf, "Filename field not completed");
  808.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  809.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  810.                     
  811.                     /* If the user presses "Cancel", post a message to the */
  812.                     /* DID_CANCEL case and break out of this case          */
  813.                     if(i == MBID_CANCEL)
  814.                       {
  815.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  816.                        break;
  817.                       }
  818.  
  819.                     /* If the user presses "Retry", set focus to the       */
  820.                     /* control that needs to be completed and break out    */
  821.                     /* of this case                                        */
  822.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_SELECTED_FN));
  823.                     break;
  824.                    }
  825.  
  826.                  hWndFSELECT = 0;
  827.  
  828.                  WinDismissDlg(hWndDlg, TRUE);
  829.                  break;
  830.  
  831.             case DID_PRINT: /* Button text: "Print"                        */
  832.                   Fselect = (FSELECTStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_FSELECT);
  833.                  /* Query the string value in the entry field control and  */
  834.                  /* move the string value to the dialog structure variable */
  835.                  WinQueryDlgItemText(hWndDlg, DID_SELECTED_DIR,
  836.                                      sizeof(Fselect->szSelected_Directory),
  837.                                      Fselect->szSelected_Directory);
  838.                  if(Fselect->szSelected_Directory[0] == 0)
  839.                    {
  840.                     /* If required field is not completed inform user and  */
  841.                     /* query what he wants to do about it by presenting a  */
  842.                     /* message box with the push buttons "Retry" and       */
  843.                     /* "Cancel"                                            */
  844.                     strcpy(szWorkBuf, "Directory field not completed");
  845.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  846.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  847.  
  848.                     /* If the user presses "Cancel", post a message to the */
  849.                     /* DID_CANCEL case and break out of this case          */
  850.                     if(i == MBID_CANCEL)
  851.                       {
  852.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  853.                        break;
  854.                       }
  855.  
  856.                     /* If the user presses "Retry", set focus to the       */
  857.                     /* control that needs to be completed and break out    */
  858.                     /* of this case                                        */
  859.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_SELECTED_DIR));
  860.                     break;
  861.                    }
  862.                  /* Query the string value in the entry field control and  */
  863.                  /* move the string value to the dialog structure variable */
  864.                  WinQueryDlgItemText(hWndDlg, DID_SELECTED_FN,
  865.                                      sizeof(Fselect->szSelected_Filename),
  866.                                      Fselect->szSelected_Filename);
  867.                  if(Fselect->szSelected_Filename[0] == 0)
  868.                    {
  869.                     /* If required field is not completed inform user and  */
  870.                     /* query what he wants to do about it by presenting a  */
  871.                     /* message box with the push buttons "Retry" and       */
  872.                     /* "Cancel"                                            */
  873.                     strcpy(szWorkBuf, "Filename field not completed");
  874.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  875.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  876.  
  877.                     /* If the user presses "Cancel", post a message to the */
  878.                     /* DID_CANCEL case and break out of this case          */
  879.                     if(i == MBID_CANCEL)
  880.                       {
  881.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  882.                        break;
  883.                       }
  884.  
  885.                     /* If the user presses "Retry", set focus to the       */
  886.                     /* control that needs to be completed and break out    */
  887.                     /* of this case                                        */
  888.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_SELECTED_FN));
  889.                     break;
  890.                    }
  891.  
  892.                   if (!WinIsWindow(hAB, hWndFSELECTDID_PRINTObject))
  893.                     {
  894.                      /* if the window is not a valid window, allocate memory */
  895.                      /* for the thread's stack                               */
  896.                      DosAllocSeg(4096, &FSELECTDID_PRINTObjSel, SEG_NONSHARED);
  897.                      FSELECTDID_PRINTObjStack = (CHAR *)MAKEP(FSELECTDID_PRINTObjSel, 0);  
  898.                      _beginthread((void FAR *)FSELECTDID_PRINTObjFunction, FSELECTDID_PRINTObjStack, 4096, 0);
  899.                     }
  900.                  break;
  901.  
  902.             case DID_CANCEL: /* Button text: "Cancel"                      */
  903.                  /* Ignore data values entered into the dialog controls    */
  904.                  /* and dismiss the dialog window                          */
  905.  
  906.                  hWndFSELECT = 0;
  907.  
  908.                  WinDismissDlg(hWndDlg, FALSE);
  909.                  break;
  910.  
  911.             case DID_HELP: /* Button text: "Help"                          */
  912.                  break;
  913.  
  914.            }
  915.          break; /* End of WM_COMMAND */
  916.                                
  917.     case WM_CLOSE:
  918.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  919.          break; /* End of WM_CLOSE */
  920.            
  921.     case WM_FAILEDVALIDATE:
  922.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  923.          sfValidate = FALSE;
  924.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  925.          sfValidate = TRUE;
  926.          return((MRESULT)TRUE);
  927.          break; /* End of WM_FAILEDVALIDATE */
  928.  
  929.     default:
  930.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  931.          break;
  932.    }
  933.  return FALSE;
  934. } /* End of FSELECTMsgProc */
  935.  
  936.  
  937. /***************************************************************************/
  938. /*                                                                         */
  939. /* Dialog Window Procedure                                                 */
  940. /*                                                                         */
  941. /* This procedure is associated with the dialog box that is included in    */
  942. /* the function name of the procedure. It provides the service routines    */
  943. /* for the events (messages) that occur because the end user operates      */
  944. /* one of the dialog box's buttons, entry fields, or controls.             */
  945. /*                                                                         */
  946. /* The SWITCH statement in the function distributes the dialog box         */
  947. /* messages to the respective service routines, which are set apart by     */
  948. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  949. /* procedures must provide an appropriate service routine for their end    */
  950. /* user initiated messages as well as for the general PM messages (like    */
  951. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  952. /* which there is no programmed CASE condition (no service routine),       */
  953. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  954. /* disposed of by PM.                                                      */
  955. /*                                                                         */
  956. /***************************************************************************/
  957.  
  958. MRESULT EXPENTRY SELPRTERMsgProc(hWndDlg, message, mp1, mp2)
  959. HWND hWndDlg;
  960. USHORT message;
  961. MPARAM mp1;
  962. MPARAM mp2;
  963.  static SHORT sfValidate = TRUE;
  964.  INT    i;
  965.  static CHAR  szWorkBuf[90];
  966.  static HWND  hWndParent;
  967.  SELPRTERStruct FAR *Selprter;
  968.  
  969.  CHAR *result;
  970.           
  971.  switch(message)
  972.    {
  973.     case WM_INITDLG:
  974.          Selprter = (SELPRTERStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_SELPRTER);
  975.          hWndParent = (HWND)mp2;
  976.          cwCenter(hWndDlg, (HWND)hWndParent);
  977.          /* Initialize entry field control: szSelected_Printer_Name        */
  978.          WinSendDlgItemMsg(hWndDlg, DID_SELECTED_PRINTER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  979.          for (i=0; i < 128; i++)
  980.             if (Selprter->szPrinter_List[i][0])
  981.                WinSendDlgItemMsg(hWndDlg, DID_PRINTER_LIST, LM_INSERTITEM,
  982.                          MPFROM2SHORT(LIT_SORTASCENDING, 0),
  983.                          MPFROMP(Selprter->szPrinter_List[i]));
  984.          break; /* End of WM_INITDLG */
  985.    
  986.     case WM_CONTROL:
  987.          switch(SHORT1FROMMP(mp1))
  988.            {
  989.             case DID_SELECTED_PRINTER_NAME: /* Entry field variable: "szSelected_Printer_Name" */
  990.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  991.                    { 
  992.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  993.                          break;
  994.  
  995.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  996.                          {
  997.                           /* Validate the field                            */
  998.                           static char buffer[24];
  999.                           WinQueryDlgItemText(hWndDlg, DID_SELECTED_PRINTER_NAME,
  1000.                                               sizeof(buffer), buffer);
  1001.                           if(buffer[0]==0x00)
  1002.                             break;
  1003.                           if(sfValidate && !cwAlphaValidate(buffer))
  1004.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  1005.                          }
  1006.                          break;
  1007.  
  1008.                     default: /* Default other messages                     */
  1009.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1010.                          break;
  1011.                    }
  1012.                  break;
  1013.  
  1014.             case DID_PRINTER_LIST: /* List box                             */
  1015.                  {
  1016.                    USHORT sSelectIndex;
  1017.                    CHAR   szSelectText[80];   
  1018.  
  1019.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  1020.                        break;
  1021.  
  1022.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  1023.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  1024.  
  1025.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  1026.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  1027.                                    MPFROMP(szSelectText));
  1028.  
  1029.                    /*****************************************************
  1030.                    *                                                    *
  1031.                    *     This section separates the printer name from   *
  1032.                    *     its description and then loads just the name.  *
  1033.                    *                                                    *
  1034.                    *****************************************************/
  1035.                    result = strtok(szSelectText," ");
  1036.                    WinSetDlgItemText(hWndDlg, DID_SELECTED_PRINTER_NAME, szSelectText);
  1037.                  }
  1038.                  break;
  1039.  
  1040.            }
  1041.          break; /* End of WM_CONTROL */
  1042.    
  1043.     case WM_COMMAND:
  1044.          switch(SHORT1FROMMP(mp1))
  1045.            {
  1046.             case DID_OK: /* Button text: "Select"                          */
  1047.                   Selprter = (SELPRTERStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_SELPRTER);
  1048.                  /* Query the string value in the entry field control and  */
  1049.                  /* move the string value to the dialog structure variable */
  1050.                  WinQueryDlgItemText(hWndDlg, DID_SELECTED_PRINTER_NAME,
  1051.                                      sizeof(Selprter->szSelected_Printer_Name),
  1052.                                      Selprter->szSelected_Printer_Name);
  1053.                  if(Selprter->szSelected_Printer_Name[0] == 0)
  1054.                    {
  1055.                     /* If required field is not completed inform user and  */
  1056.                     /* query what he wants to do about it by presenting a  */
  1057.                     /* message box with the push buttons "Retry" and       */
  1058.                     /* "Cancel"                                            */
  1059.                     strcpy(szWorkBuf, "Printer name required.  Push retry to supply one or cancel to abort dialog.");
  1060.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  1061.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  1062.                     
  1063.                     /* If the user presses "Cancel", post a message to the */
  1064.                     /* DID_CANCEL case and break out of this case          */
  1065.                     if(i == MBID_CANCEL)
  1066.                       {
  1067.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1068.                        break;
  1069.                       }
  1070.  
  1071.                     /* If the user presses "Retry", set focus to the       */
  1072.                     /* control that needs to be completed and break out    */
  1073.                     /* of this case                                        */
  1074.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_SELECTED_PRINTER_NAME));
  1075.                     break;
  1076.                    }
  1077.                  WinDismissDlg(hWndDlg, TRUE);
  1078.                  break;
  1079.  
  1080.             case DID_CANCEL: /* Button text: "Cancel"                      */
  1081.                  /* Ignore data values entered into the dialog controls    */
  1082.                  /* and dismiss the dialog window                          */
  1083.                  WinDismissDlg(hWndDlg, FALSE);
  1084.                  break;
  1085.  
  1086.             case DID_HELP: /* Button text: "Help"                          */
  1087.                  break;
  1088.  
  1089.            }
  1090.          break; /* End of WM_COMMAND */
  1091.                                
  1092.     case WM_CLOSE:
  1093.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1094.          break; /* End of WM_CLOSE */
  1095.            
  1096.     case WM_FAILEDVALIDATE:
  1097.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  1098.          sfValidate = FALSE;
  1099.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  1100.          sfValidate = TRUE;
  1101.          return((MRESULT)TRUE);
  1102.          break; /* End of WM_FAILEDVALIDATE */
  1103.  
  1104.     default:
  1105.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1106.          break;
  1107.    }
  1108.  return FALSE;
  1109. } /* End of SELPRTERMsgProc */
  1110.  
  1111.  
  1112. /***************************************************************************/
  1113. /*                                                                         */
  1114. /* Dialog Window Procedure                                                 */
  1115. /*                                                                         */
  1116. /* This procedure is associated with the dialog box that is included in    */
  1117. /* the function name of the procedure. It provides the service routines    */
  1118. /* for the events (messages) that occur because the end user operates      */
  1119. /* one of the dialog box's buttons, entry fields, or controls.             */
  1120. /*                                                                         */
  1121. /* The SWITCH statement in the function distributes the dialog box         */
  1122. /* messages to the respective service routines, which are set apart by     */
  1123. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  1124. /* procedures must provide an appropriate service routine for their end    */
  1125. /* user initiated messages as well as for the general PM messages (like    */
  1126. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  1127. /* which there is no programmed CASE condition (no service routine),       */
  1128. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  1129. /* disposed of by PM.                                                      */
  1130. /*                                                                         */
  1131. /***************************************************************************/
  1132.  
  1133. MRESULT EXPENTRY PRTERADDMsgProc(hWndDlg, message, mp1, mp2)
  1134. HWND hWndDlg;
  1135. USHORT message;
  1136. MPARAM mp1;
  1137. MPARAM mp2;
  1138.  static SHORT sfValidate = TRUE;
  1139.  INT    i;
  1140.  static CHAR  szWorkBuf[90];
  1141.  static HWND  hWndParent;
  1142.  PRTERADDStruct FAR *Prteradd;
  1143.  
  1144.  static INT free_entry;      /* Number of first free entry in the printer table. */
  1145.  SELPRTERStruct FAR *Selprter;
  1146.  CHAR *result;
  1147.  LOADRETURNStruct FAR *Return_Values;
  1148.  
  1149.  Selprter = (SELPRTERStruct FAR *)WinQueryWindowULong(hWndClient,
  1150.                                                       OFFSET_SELPRTER);
  1151.           
  1152.  switch(message)
  1153.    {
  1154.     case WM_INITDLG:
  1155.          Prteradd = (PRTERADDStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_PRTERADD);
  1156.          hWndParent = (HWND)mp2;
  1157.          cwCenter(hWndDlg, (HWND)hWndParent);
  1158.  
  1159.          Return_Values = (LOADRETURNStruct FAR *)
  1160.                          BgmLoadListBox(hWndDlg,
  1161.                                         DID_PRINTER_LIST,
  1162.                                         Selprter->szPrinter_List,
  1163.                                         "Printer list is full.  You will need to remove a printer in order to add one.",
  1164.                                         TRUE);
  1165.  
  1166.          if((free_entry = Return_Values->free_entry) == -1)
  1167.          {
  1168.            break;
  1169.          }
  1170.  
  1171.          /* Initialize entry field control: szAdd_Printer_Name             */
  1172.          WinSendDlgItemMsg(hWndDlg, DID_ADD_PRINTER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  1173.          /* Initialize entry field control: szAdd_Printer_Desc             */
  1174.          WinSendDlgItemMsg(hWndDlg, DID_ADD_PRINTER_DESC, EM_SETTEXTLIMIT, MPFROMSHORT(103), 0L);
  1175.          break; /* End of WM_INITDLG */
  1176.    
  1177.     case WM_CONTROL:
  1178.          switch(SHORT1FROMMP(mp1))
  1179.            {
  1180.             case DID_ADD_PRINTER_NAME: /* Entry field variable: "szAdd_Printer_Name" */
  1181.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  1182.                    { 
  1183.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  1184.                          break;
  1185.  
  1186.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  1187.                          {
  1188.                           /* Validate the field                            */
  1189.                           static char buffer[24];
  1190.                           WinQueryDlgItemText(hWndDlg, DID_ADD_PRINTER_NAME,
  1191.                                               sizeof(buffer), buffer);
  1192.                           if(buffer[0]==0x00)
  1193.                             break;
  1194.                           if(sfValidate && !cwAlphaValidate(buffer))
  1195.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  1196.                          }
  1197.                          break;
  1198.  
  1199.                     default: /* Default other messages                     */
  1200.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1201.                          break;
  1202.                    }
  1203.                  break;
  1204.  
  1205.             case DID_ADD_PRINTER_DESC: /* Entry field variable: "szAdd_Printer_Desc" */
  1206.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  1207.                    { 
  1208.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  1209.                          break;
  1210.  
  1211.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  1212.                          break;
  1213.  
  1214.                     default: /* Default other messages                     */
  1215.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1216.                          break;
  1217.                    }
  1218.                  break;
  1219.  
  1220.             case DID_PRINTER_LIST: /* List box                             */
  1221.                  {
  1222.  
  1223.                    /*****************************************************
  1224.                    *                                                    *
  1225.                    *     This section obtains from the printer list the *
  1226.                    *     entry pointed to by the end-user.  We break it *
  1227.                    *     into its two components (name and description).*
  1228.                    *     We then load these components into their       *
  1229.                    *     respective fields.                             *
  1230.                    *                                                    *
  1231.                    *     One example of when an user might point to an  *
  1232.                    *     entry is when he want to save some typing.     *
  1233.                    *                                                    *
  1234.                    *****************************************************/
  1235.                    USHORT sSelectIndex;
  1236.                    CHAR   szSelectText[129];
  1237.  
  1238.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  1239.                        break;
  1240.  
  1241.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  1242.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  1243.  
  1244.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  1245.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  1246.                                    MPFROMP(szSelectText));
  1247.  
  1248.                    result = strtok(szSelectText," ");
  1249.                    WinSetDlgItemText(hWndDlg,
  1250.                                      DID_ADD_PRINTER_NAME,
  1251.                                      (PSZ) result);
  1252.  
  1253.                    result = strchr(szSelectText,'\0');
  1254.                    *result++;
  1255.  
  1256.                    WinSetDlgItemText(hWndDlg,
  1257.                                      DID_ADD_PRINTER_DESC,
  1258.                                      result);
  1259.                  }
  1260.                  break;
  1261.  
  1262.            }
  1263.          break; /* End of WM_CONTROL */
  1264.    
  1265.     case WM_COMMAND:
  1266.          switch(SHORT1FROMMP(mp1))
  1267.            {
  1268.             case DID_OK: /* Button text: "Add"                             */
  1269.                   Prteradd = (PRTERADDStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_PRTERADD);
  1270.                  /* Query the string value in the entry field control and  */
  1271.                  /* move the string value to the dialog structure variable */
  1272.                  WinQueryDlgItemText(hWndDlg, DID_ADD_PRINTER_NAME,
  1273.                                      sizeof(Prteradd->szAdd_Printer_Name),
  1274.                                      Prteradd->szAdd_Printer_Name);
  1275.                  if(Prteradd->szAdd_Printer_Name[0] == 0)
  1276.                    {
  1277.                     /* If required field is not completed inform user and  */
  1278.                     /* query what he wants to do about it by presenting a  */
  1279.                     /* message box with the push buttons "Retry" and       */
  1280.                     /* "Cancel"                                            */
  1281.                     strcpy(szWorkBuf, "Printer name required.  Push retry to supply one or cancel to abort dialog.");
  1282.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  1283.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  1284.                     
  1285.                     /* If the user presses "Cancel", post a message to the */
  1286.                     /* DID_CANCEL case and break out of this case          */
  1287.                     if(i == MBID_CANCEL)
  1288.                       {
  1289.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1290.                        break;
  1291.                       }
  1292.  
  1293.                     /* If the user presses "Retry", set focus to the       */
  1294.                     /* control that needs to be completed and break out    */
  1295.                     /* of this case                                        */
  1296.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_ADD_PRINTER_NAME));
  1297.                     break;
  1298.                    }
  1299.                  /* Query the string value in the entry field control and  */
  1300.                  /* move the string value to the dialog structure variable */
  1301.                  WinQueryDlgItemText(hWndDlg, DID_ADD_PRINTER_DESC,
  1302.                                      sizeof(Prteradd->szAdd_Printer_Desc),
  1303.                                      Prteradd->szAdd_Printer_Desc);
  1304.  
  1305.                  if(BgmAddPrtSrv(hWndDlg,
  1306.                                  DID_ADD_PRINTER_NAME,
  1307.                                  free_entry,
  1308.                                  Selprter->szPrinter_List,
  1309.                                  Prteradd->szAdd_Printer_Name,
  1310.                                  Prteradd->szAdd_Printer_Desc,
  1311.                                  "Printer name duplication.  Push retry to change printer name or push cancel to abort.")
  1312.                     == TRUE)
  1313.                  {
  1314.                  WinDismissDlg(hWndDlg, TRUE);
  1315.                  }
  1316.                  break;
  1317.  
  1318.             case DID_CANCEL: /* Button text: "Cancel"                      */
  1319.                  /* Ignore data values entered into the dialog controls    */
  1320.                  /* and dismiss the dialog window                          */
  1321.                  WinDismissDlg(hWndDlg, FALSE);
  1322.                  break;
  1323.  
  1324.             case DID_HELP: /* Button text: "Help"                          */
  1325.                  break;
  1326.  
  1327.            }
  1328.          break; /* End of WM_COMMAND */
  1329.                                
  1330.     case WM_CLOSE:
  1331.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1332.          break; /* End of WM_CLOSE */
  1333.            
  1334.     case WM_FAILEDVALIDATE:
  1335.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  1336.          sfValidate = FALSE;
  1337.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  1338.          sfValidate = TRUE;
  1339.          return((MRESULT)TRUE);
  1340.          break; /* End of WM_FAILEDVALIDATE */
  1341.  
  1342.     default:
  1343.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1344.          break;
  1345.    }
  1346.  return FALSE;
  1347. } /* End of PRTERADDMsgProc */
  1348.  
  1349.  
  1350. /***************************************************************************/
  1351. /*                                                                         */
  1352. /* Dialog Window Procedure                                                 */
  1353. /*                                                                         */
  1354. /* This procedure is associated with the dialog box that is included in    */
  1355. /* the function name of the procedure. It provides the service routines    */
  1356. /* for the events (messages) that occur because the end user operates      */
  1357. /* one of the dialog box's buttons, entry fields, or controls.             */
  1358. /*                                                                         */
  1359. /* The SWITCH statement in the function distributes the dialog box         */
  1360. /* messages to the respective service routines, which are set apart by     */
  1361. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  1362. /* procedures must provide an appropriate service routine for their end    */
  1363. /* user initiated messages as well as for the general PM messages (like    */
  1364. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  1365. /* which there is no programmed CASE condition (no service routine),       */
  1366. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  1367. /* disposed of by PM.                                                      */
  1368. /*                                                                         */
  1369. /***************************************************************************/
  1370.  
  1371. MRESULT EXPENTRY PRTERDELMsgProc(hWndDlg, message, mp1, mp2)
  1372. HWND hWndDlg;
  1373. USHORT message;
  1374. MPARAM mp1;
  1375. MPARAM mp2;
  1376.  static SHORT sfValidate = TRUE;
  1377.  INT    i;
  1378.  static CHAR  szWorkBuf[90];
  1379.  static HWND  hWndParent;
  1380.  PRTERDELStruct FAR *Prterdel;
  1381.           
  1382.  static INT last_entry;      /* Number of last acrive entry in the printer table. */
  1383.  SELPRTERStruct FAR *Selprter;
  1384.  CHAR *result;
  1385.  LOADRETURNStruct FAR *Return_Values;
  1386.  
  1387.  Selprter = (SELPRTERStruct FAR *)WinQueryWindowULong(hWndClient,
  1388.                                                       OFFSET_SELPRTER);
  1389.  switch(message)
  1390.    {
  1391.     case WM_INITDLG:
  1392.          Prterdel = (PRTERDELStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_PRTERDEL);
  1393.          hWndParent = (HWND)mp2;
  1394.          cwCenter(hWndDlg, (HWND)hWndParent);
  1395.  
  1396.          Return_Values = (LOADRETURNStruct FAR *)
  1397.                          BgmLoadListBox(hWndDlg,
  1398.                                         DID_PRINTER_LIST,
  1399.                                         Selprter->szPrinter_List,
  1400.                                         "A printer does not exist to delete.  The printer list is empty.",
  1401.                                         FALSE);
  1402.  
  1403.          if((last_entry = Return_Values->last_entry) == -1)
  1404.          {
  1405.            break;
  1406.          }
  1407.  
  1408.          /* Initialize entry field control: szDelete_Printer_Name          */
  1409.          WinSendDlgItemMsg(hWndDlg, DID_DELETE_PRINTER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  1410.          break; /* End of WM_INITDLG */
  1411.    
  1412.     case WM_CONTROL:
  1413.          switch(SHORT1FROMMP(mp1))
  1414.            {
  1415.             case DID_DELETE_PRINTER_NAME: /* Entry field variable: "szDelete_Printer_Name" */
  1416.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  1417.                    { 
  1418.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  1419.                          break;
  1420.  
  1421.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  1422.                          {
  1423.                           /* Validate the field                            */
  1424.                           static char buffer[24];
  1425.                           WinQueryDlgItemText(hWndDlg, DID_DELETE_PRINTER_NAME,
  1426.                                               sizeof(buffer), buffer);
  1427.                           if(buffer[0]==0x00)
  1428.                             break;
  1429.                           if(sfValidate && !cwAlphaValidate(buffer))
  1430.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  1431.                          }
  1432.                          break;
  1433.  
  1434.                     default: /* Default other messages                     */
  1435.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1436.                          break;
  1437.                    }
  1438.                  break;
  1439.  
  1440.             case DID_PRINTER_LIST: /* List box                             */
  1441.                  {
  1442.  
  1443.                    /*****************************************************
  1444.                    *                                                    *
  1445.                    *     This section obtains from the printer list the *
  1446.                    *     entry pointed to by the end-user.  We breakout *
  1447.                    *     of its the name component and then load the    *
  1448.                    *     name into its field.                           *
  1449.                    *                                                    *
  1450.                    *     One example of when an user might point to an  *
  1451.                    *     entry is when he want to save some typing.     *
  1452.                    *                                                    *
  1453.                    *****************************************************/
  1454.                    USHORT sSelectIndex;
  1455.                    CHAR   szSelectText[25];
  1456.  
  1457.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  1458.                        break;
  1459.  
  1460.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  1461.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  1462.  
  1463.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  1464.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  1465.                                    MPFROMP(szSelectText));
  1466.  
  1467.                    result = strtok(szSelectText," ");
  1468.                    WinSetDlgItemText(hWndDlg,
  1469.                                      DID_DELETE_PRINTER_NAME,
  1470.                                      (PSZ) result);
  1471.                  }
  1472.                  break;
  1473.  
  1474.            }
  1475.          break; /* End of WM_CONTROL */
  1476.    
  1477.     case WM_COMMAND:
  1478.          switch(SHORT1FROMMP(mp1))
  1479.            {
  1480.             case DID_OK: /* Button text: "Delete"                          */
  1481.                   Prterdel = (PRTERDELStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_PRTERDEL);
  1482.                  /* Query the string value in the entry field control and  */
  1483.                  /* move the string value to the dialog structure variable */
  1484.                  WinQueryDlgItemText(hWndDlg, DID_DELETE_PRINTER_NAME,
  1485.                                      sizeof(Prterdel->szDelete_Printer_Name),
  1486.                                      Prterdel->szDelete_Printer_Name);
  1487.                  if(Prterdel->szDelete_Printer_Name[0] == 0)
  1488.                    {
  1489.                     /* If required field is not completed inform user and  */
  1490.                     /* query what he wants to do about it by presenting a  */
  1491.                     /* message box with the push buttons "Retry" and       */
  1492.                     /* "Cancel"                                            */
  1493.                     strcpy(szWorkBuf, "Printer name required.  Push retry to supply one or cancel to abort dialog.");
  1494.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  1495.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  1496.                     
  1497.                     /* If the user presses "Cancel", post a message to the */
  1498.                     /* DID_CANCEL case and break out of this case          */
  1499.                     if(i == MBID_CANCEL)
  1500.                       {
  1501.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1502.                        break;
  1503.                       }
  1504.  
  1505.                     /* If the user presses "Retry", set focus to the       */
  1506.                     /* control that needs to be completed and break out    */
  1507.                     /* of this case                                        */
  1508.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_DELETE_PRINTER_NAME));
  1509.                     break;
  1510.                    }
  1511.  
  1512.                  if(BgmDeletePrtSrv(hWndDlg,
  1513.                                     DID_DELETE_PRINTER_NAME,
  1514.                                     last_entry,
  1515.                                     Selprter->szPrinter_List,
  1516.                                     Prterdel->szDelete_Printer_Name,
  1517.                                     "Printer name not found.  Push retry to change printer name or push cancel to abort.")
  1518.                     == TRUE)
  1519.                  {
  1520.                  WinDismissDlg(hWndDlg, TRUE);
  1521.                  }
  1522.                  break;
  1523.  
  1524.             case DID_CANCEL: /* Button text: "Cancel"                      */
  1525.                  /* Ignore data values entered into the dialog controls    */
  1526.                  /* and dismiss the dialog window                          */
  1527.                  WinDismissDlg(hWndDlg, FALSE);
  1528.                  break;
  1529.  
  1530.             case DID_HELP: /* Button text: "Help"                          */
  1531.                  break;
  1532.  
  1533.            }
  1534.          break; /* End of WM_COMMAND */
  1535.                                
  1536.     case WM_CLOSE:
  1537.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1538.          break; /* End of WM_CLOSE */
  1539.            
  1540.     case WM_FAILEDVALIDATE:
  1541.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  1542.          sfValidate = FALSE;
  1543.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  1544.          sfValidate = TRUE;
  1545.          return((MRESULT)TRUE);
  1546.          break; /* End of WM_FAILEDVALIDATE */
  1547.  
  1548.     default:
  1549.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1550.          break;
  1551.    }
  1552.  return FALSE;
  1553. } /* End of PRTERDELMsgProc */
  1554.  
  1555.  
  1556. /***************************************************************************/
  1557. /*                                                                         */
  1558. /* Dialog Window Procedure                                                 */
  1559. /*                                                                         */
  1560. /* This procedure is associated with the dialog box that is included in    */
  1561. /* the function name of the procedure. It provides the service routines    */
  1562. /* for the events (messages) that occur because the end user operates      */
  1563. /* one of the dialog box's buttons, entry fields, or controls.             */
  1564. /*                                                                         */
  1565. /* The SWITCH statement in the function distributes the dialog box         */
  1566. /* messages to the respective service routines, which are set apart by     */
  1567. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  1568. /* procedures must provide an appropriate service routine for their end    */
  1569. /* user initiated messages as well as for the general PM messages (like    */
  1570. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  1571. /* which there is no programmed CASE condition (no service routine),       */
  1572. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  1573. /* disposed of by PM.                                                      */
  1574. /*                                                                         */
  1575. /***************************************************************************/
  1576.  
  1577. MRESULT EXPENTRY PRTCHANGMsgProc(hWndDlg, message, mp1, mp2)
  1578. HWND hWndDlg;
  1579. USHORT message;
  1580. MPARAM mp1;
  1581. MPARAM mp2;
  1582.  static SHORT sfValidate = TRUE;
  1583.  INT    i;
  1584.  static CHAR  szWorkBuf[90];
  1585.  static HWND  hWndParent;
  1586.  PRTCHANGStruct FAR *Prtchang;
  1587.           
  1588.  
  1589.  static INT Selected_Entry_Number;
  1590.  SELPRTERStruct FAR *Selprter;
  1591.  CHAR *result;
  1592.  LOADRETURNStruct FAR *Return_Values;
  1593.  
  1594.  Selprter = (SELPRTERStruct FAR *)WinQueryWindowULong(hWndClient,
  1595.                                                       OFFSET_SELPRTER);
  1596.  switch(message)
  1597.    {
  1598.     case WM_INITDLG:
  1599.          Prtchang = (PRTCHANGStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_PRTCHANG);
  1600.          hWndParent = (HWND)mp2;
  1601.          cwCenter(hWndDlg, (HWND)hWndParent);
  1602.          Selected_Entry_Number = -1;
  1603.  
  1604.          Return_Values = (LOADRETURNStruct FAR *)
  1605.                          BgmLoadListBox(hWndDlg,
  1606.                                         DID_PRINTER_LIST,
  1607.                                         Selprter->szPrinter_List,
  1608.                                         "A printer does not exist to change.  The printer list is empty.",
  1609.                                         FALSE);
  1610.  
  1611.          if (Return_Values->last_entry == -1)
  1612.          {
  1613.            break;
  1614.          }
  1615.  
  1616.          /* Initialize entry field control: szChange_Printer_Name          */
  1617.          WinSendDlgItemMsg(hWndDlg, DID_CHANGE_PRINTER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  1618.          /* Initialize entry field control: szChange_Printer_Desc          */
  1619.          WinSendDlgItemMsg(hWndDlg, DID_CHANGE_PRINTER_DESC, EM_SETTEXTLIMIT, MPFROMSHORT(103), 0L);
  1620.          break; /* End of WM_INITDLG */
  1621.    
  1622.     case WM_CONTROL:
  1623.          switch(SHORT1FROMMP(mp1))
  1624.            {
  1625.             case DID_CHANGE_PRINTER_NAME: /* Entry field variable: "szChange_Printer_Name" */
  1626.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  1627.                    { 
  1628.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  1629.                          break;
  1630.  
  1631.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  1632.                          {
  1633.                           /* Validate the field                            */
  1634.                           static char buffer[24];
  1635.                           WinQueryDlgItemText(hWndDlg, DID_CHANGE_PRINTER_NAME,
  1636.                                               sizeof(buffer), buffer);
  1637.                           if(buffer[0]==0x00)
  1638.                             break;
  1639.                           if(sfValidate && !cwAlphaValidate(buffer))
  1640.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  1641.                          }
  1642.                          break;
  1643.  
  1644.                     default: /* Default other messages                     */
  1645.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1646.                          break;
  1647.                    }
  1648.                  break;
  1649.  
  1650.             case DID_CHANGE_PRINTER_DESC: /* Entry field variable: "szChange_Printer_Desc" */
  1651.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  1652.                    { 
  1653.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  1654.                          break;
  1655.  
  1656.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  1657.                          break;
  1658.  
  1659.                     default: /* Default other messages                     */
  1660.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1661.                          break;
  1662.                    }
  1663.                  break;
  1664.  
  1665.             case DID_PRINTER_LIST: /* List box                             */
  1666.                  {
  1667.  
  1668.                    /*****************************************************
  1669.                    *                                                    *
  1670.                    *     This section obtains from the printer list the *
  1671.                    *     entry pointed to by the end-user.  We break it *
  1672.                    *     into its two components (name and description).*
  1673.                    *     We then load these components into their       *
  1674.                    *     respective fields.                             *
  1675.                    *                                                    *
  1676.                    *     One example of when an user might point to an  *
  1677.                    *     entry is when he want to save some typing.     *
  1678.                    *                                                    *
  1679.                    *****************************************************/
  1680.                    USHORT sSelectIndex;
  1681.                    CHAR   szSelectText[129];
  1682.  
  1683.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  1684.                        break;
  1685.  
  1686.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  1687.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  1688.  
  1689.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  1690.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  1691.                                    MPFROMP(szSelectText));
  1692.  
  1693.                    /*****************************************************
  1694.                    *                                                    *
  1695.                    *     This section finds the printer entry the user  *
  1696.                    *     just selected.  The change key (DID_OK) code   *
  1697.                    *     uses this number to indicate which entry the   *
  1698.                    *     user is changing.  This approach permits the   *
  1699.                    *     end-user to change both the name and           *
  1700.                    *     description instead of just the name.          *
  1701.                    *                                                    *
  1702.                    *****************************************************/
  1703.                    for(i=0; i < 128; i++)
  1704.                    {
  1705.                      if (Selprter->szPrinter_List[i][0])
  1706.                      {
  1707.                        if(strnicmp(Selprter->szPrinter_List[i],
  1708.                                    szSelectText,
  1709.                                    strlen(szSelectText)) == 0)
  1710.                        {
  1711.                          Selected_Entry_Number = i;
  1712.                          break;
  1713.                        }
  1714.                      }
  1715.                    }
  1716.  
  1717.                    result = strtok(szSelectText," ");
  1718.                    WinSetDlgItemText(hWndDlg,
  1719.                                      DID_CHANGE_PRINTER_NAME,
  1720.                                      (PSZ) result);
  1721.  
  1722.                    result = strchr(szSelectText,'\0');
  1723.                    *result++;
  1724.  
  1725.                    WinSetDlgItemText(hWndDlg,
  1726.                                      DID_CHANGE_PRINTER_DESC,
  1727.                                      result);
  1728.                  }
  1729.                  break;
  1730.  
  1731.            }
  1732.          break; /* End of WM_CONTROL */
  1733.    
  1734.     case WM_COMMAND:
  1735.          switch(SHORT1FROMMP(mp1))
  1736.            {
  1737.             case DID_OK: /* Button text: "Change"                          */
  1738.                   Prtchang = (PRTCHANGStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_PRTCHANG);
  1739.                  /* Query the string value in the entry field control and  */
  1740.                  /* move the string value to the dialog structure variable */
  1741.                  WinQueryDlgItemText(hWndDlg, DID_CHANGE_PRINTER_NAME,
  1742.                                      sizeof(Prtchang->szChange_Printer_Name),
  1743.                                      Prtchang->szChange_Printer_Name);
  1744.                  if(Prtchang->szChange_Printer_Name[0] == 0)
  1745.                    {
  1746.                     /* If required field is not completed inform user and  */
  1747.                     /* query what he wants to do about it by presenting a  */
  1748.                     /* message box with the push buttons "Retry" and       */
  1749.                     /* "Cancel"                                            */
  1750.                     strcpy(szWorkBuf, "Printer name required.  Push retry to supply one or cancel to abort dialog.");
  1751.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  1752.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  1753.                     
  1754.                     /* If the user presses "Cancel", post a message to the */
  1755.                     /* DID_CANCEL case and break out of this case          */
  1756.                     if(i == MBID_CANCEL)
  1757.                       {
  1758.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1759.                        break;
  1760.                       }
  1761.  
  1762.                     /* If the user presses "Retry", set focus to the       */
  1763.                     /* control that needs to be completed and break out    */
  1764.                     /* of this case                                        */
  1765.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_CHANGE_PRINTER_NAME));
  1766.                     break;
  1767.                    }
  1768.                  /* Query the string value in the entry field control and  */
  1769.                  /* move the string value to the dialog structure variable */
  1770.                  WinQueryDlgItemText(hWndDlg, DID_CHANGE_PRINTER_DESC,
  1771.                                      sizeof(Prtchang->szChange_Printer_Desc),
  1772.                                      Prtchang->szChange_Printer_Desc);
  1773.  
  1774.                  if(BgmChangePrtSrv(hWndDlg,
  1775.                                     DID_CHANGE_PRINTER_NAME,
  1776.                                     Selected_Entry_Number,
  1777.                                     Selprter->szPrinter_List,
  1778.                                     Prtchang->szChange_Printer_Name,
  1779.                                     Prtchang->szChange_Printer_Desc,
  1780.                                     "Printer name not found.  Push retry to change printer name or push cancel to abort.")
  1781.                     != -1)
  1782.                  {
  1783.                  WinDismissDlg(hWndDlg, TRUE);
  1784.                  }
  1785.                  break;
  1786.  
  1787.             case DID_CANCEL: /* Button text: "Cancel"                      */
  1788.                  /* Ignore data values entered into the dialog controls    */
  1789.                  /* and dismiss the dialog window                          */
  1790.                  WinDismissDlg(hWndDlg, FALSE);
  1791.                  break;
  1792.  
  1793.             case DID_HELP: /* Button text: "Help"                          */
  1794.                  break;
  1795.  
  1796.            }
  1797.          break; /* End of WM_COMMAND */
  1798.                                
  1799.     case WM_CLOSE:
  1800.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  1801.          break; /* End of WM_CLOSE */
  1802.            
  1803.     case WM_FAILEDVALIDATE:
  1804.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  1805.          sfValidate = FALSE;
  1806.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  1807.          sfValidate = TRUE;
  1808.          return((MRESULT)TRUE);
  1809.          break; /* End of WM_FAILEDVALIDATE */
  1810.  
  1811.     default:
  1812.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1813.          break;
  1814.    }
  1815.  return FALSE;
  1816. } /* End of PRTCHANGMsgProc */
  1817.  
  1818.  
  1819. /***************************************************************************/
  1820. /*                                                                         */
  1821. /* Dialog Window Procedure                                                 */
  1822. /*                                                                         */
  1823. /* This procedure is associated with the dialog box that is included in    */
  1824. /* the function name of the procedure. It provides the service routines    */
  1825. /* for the events (messages) that occur because the end user operates      */
  1826. /* one of the dialog box's buttons, entry fields, or controls.             */
  1827. /*                                                                         */
  1828. /* The SWITCH statement in the function distributes the dialog box         */
  1829. /* messages to the respective service routines, which are set apart by     */
  1830. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  1831. /* procedures must provide an appropriate service routine for their end    */
  1832. /* user initiated messages as well as for the general PM messages (like    */
  1833. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  1834. /* which there is no programmed CASE condition (no service routine),       */
  1835. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  1836. /* disposed of by PM.                                                      */
  1837. /*                                                                         */
  1838. /***************************************************************************/
  1839.  
  1840. MRESULT EXPENTRY SELSERVMsgProc(hWndDlg, message, mp1, mp2)
  1841. HWND hWndDlg;
  1842. USHORT message;
  1843. MPARAM mp1;
  1844. MPARAM mp2;
  1845.  static SHORT sfValidate = TRUE;
  1846.  INT    i;
  1847.  static CHAR  szWorkBuf[90];
  1848.  static HWND  hWndParent;
  1849.  SELSERVStruct FAR *Selserv;
  1850.  
  1851.  CHAR *result;
  1852.           
  1853.  switch(message)
  1854.    {
  1855.     case WM_INITDLG:
  1856.          Selserv = (SELSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_SELSERV);
  1857.          hWndParent = (HWND)mp2;
  1858.          cwCenter(hWndDlg, (HWND)hWndParent);
  1859.          /* Initialize entry field control: szSelected_Server_Name         */
  1860.          WinSendDlgItemMsg(hWndDlg, DID_SELECTED_SERVER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  1861.          for (i=0; i < 128; i++)
  1862.             if (Selserv->szServer_List[i][0])
  1863.                WinSendDlgItemMsg(hWndDlg, DID_SERVER_LIST, LM_INSERTITEM,
  1864.                          MPFROM2SHORT(LIT_SORTASCENDING, 0),
  1865.                          MPFROMP(Selserv->szServer_List[i]));
  1866.          /* Initialize check box control: ckSelected_UNIX_Format           */
  1867.          WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT, BM_SETCHECK,
  1868.              MPFROMSHORT(Selserv->ckSelected_UNIX_Format), 0L);
  1869.  
  1870.          /***************************************************************
  1871.          *                                                              *
  1872.          *     This section insures the UNIX format checks are the      *
  1873.          *     same both in this dialog and on the pulldown.  The       *
  1874.          *     pulldown is the master control except when processing    *
  1875.          *     this dialog's DID_OK (Select button) message.            *
  1876.          *                                                              *
  1877.          ***************************************************************/
  1878.          if ((SHORT) WinSendMsg(WinWindowFromID(hWndFrame, FID_MENU),
  1879.                                 MM_QUERYITEMATTR,
  1880.                                 MPFROM2SHORT(IDM_O_UNIXFORMAT, TRUE),
  1881.                                 MPFROMSHORT(MIA_CHECKED))
  1882.              == MIA_CHECKED)
  1883.          {
  1884.            Selserv->ckSelected_UNIX_Format = TRUE;
  1885.          }
  1886.          else
  1887.          {
  1888.            Selserv->ckSelected_UNIX_Format = FALSE;
  1889.          }
  1890.          WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT, BM_SETCHECK,
  1891.              MPFROMSHORT(Selserv->ckSelected_UNIX_Format), 0L);
  1892.  
  1893.          break; /* End of WM_INITDLG */
  1894.    
  1895.     case WM_CONTROL:
  1896.          switch(SHORT1FROMMP(mp1))
  1897.            {
  1898.             case DID_UNIX_FORMAT: /* Checkbox text: "Use UNIX format"      */
  1899.                  {
  1900.                   USHORT checked;
  1901.  
  1902.                   /* Query check box control for current state             */
  1903.                   /* on return checked is set to:                          */
  1904.                   /*           1 if check box is in unchecked state        */
  1905.                   /*           0 if check box is in checked state          */
  1906.                   checked = !WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT,
  1907.                                                BM_QUERYCHECK, 0L, 0L );
  1908.                   /* Set checkbox control state                            */
  1909.                   WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT,
  1910.                                     BM_SETCHECK, MPFROMSHORT(checked), 0L);
  1911.                  }  
  1912.                  break;
  1913.  
  1914.             case DID_SELECTED_SERVER_NAME: /* Entry field variable: "szSelected_Server_Name" */
  1915.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  1916.                    { 
  1917.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  1918.                          break;
  1919.  
  1920.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  1921.                          {
  1922.                           /* Validate the field                            */
  1923.                           static char buffer[24];
  1924.                           WinQueryDlgItemText(hWndDlg, DID_SELECTED_SERVER_NAME,
  1925.                                               sizeof(buffer), buffer);
  1926.                           if(buffer[0]==0x00)
  1927.                             break;
  1928.                           if(sfValidate && !cwAlphaValidate(buffer))
  1929.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  1930.                          }
  1931.                          break;
  1932.  
  1933.                     default: /* Default other messages                     */
  1934.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  1935.                          break;
  1936.                    }
  1937.                  break;
  1938.  
  1939.             case DID_SERVER_LIST: /* List box                              */
  1940.                  {
  1941.                    USHORT sSelectIndex;
  1942.                    CHAR   szSelectText[80];   
  1943.                    USHORT checked;
  1944.  
  1945.                    Selserv = (SELSERVStruct FAR *)WinQueryWindowULong(hWndClient,
  1946.                                                                       OFFSET_SELSERV);
  1947.  
  1948.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  1949.                        break;
  1950.  
  1951.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  1952.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  1953.  
  1954.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  1955.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  1956.                                    MPFROMP(szSelectText));
  1957.  
  1958.                    /*****************************************************
  1959.                    *                                                    *
  1960.                    *     This section sets the UNIX format check box    *
  1961.                    *     based upon the entry selected by the end-user. *
  1962.                    *     We need to scan through the server list to     *
  1963.                    *     find the selected entry and then use the       *
  1964.                    *     server UNIX format array to set the box.       *
  1965.                    *                                                    *
  1966.                    *****************************************************/
  1967.                    for(i=0; i < 128; i++)
  1968.                    {
  1969.                      if (Selserv->szServer_List[i][0])
  1970.                      {
  1971.                        if(strnicmp(Selserv->szServer_List[i],
  1972.                                    szSelectText,
  1973.                                    strlen(szSelectText)) == 0)
  1974.                        {
  1975.                          checked = (USHORT) Selserv->ckServer_UNIX_Format[i];
  1976.                          WinSendDlgItemMsg(hWndDlg,
  1977.                                            DID_UNIX_FORMAT,
  1978.                                            BM_SETCHECK,
  1979.                                            MPFROMSHORT(checked),
  1980.                                            0L);
  1981.                          break;
  1982.                        }
  1983.                      }
  1984.                    }
  1985.  
  1986.                    /*****************************************************
  1987.                    *                                                    *
  1988.                    *     This section separates the server name from    *
  1989.                    *     its description and then loads just the name.  *
  1990.                    *                                                    *
  1991.                    *****************************************************/
  1992.                    result = strtok(szSelectText," ");
  1993.                    WinSetDlgItemText(hWndDlg, DID_SELECTED_SERVER_NAME, szSelectText);
  1994.                  }
  1995.                  break;
  1996.  
  1997.            }
  1998.          break; /* End of WM_CONTROL */
  1999.    
  2000.     case WM_COMMAND:
  2001.          switch(SHORT1FROMMP(mp1))
  2002.            {
  2003.             case DID_OK: /* Button text: "Select"                          */
  2004.                   Selserv = (SELSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_SELSERV);
  2005.                  /* Query the check box control for its current state,     */
  2006.                  /* and set the dialog structure variable                  */
  2007.                  Selserv->ckSelected_UNIX_Format = 
  2008.                     (INT)(WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT,
  2009.                                             BM_QUERYCHECK, 0L, 0L));
  2010.                  /* Query the string value in the entry field control and  */
  2011.                  /* move the string value to the dialog structure variable */
  2012.                  WinQueryDlgItemText(hWndDlg, DID_SELECTED_SERVER_NAME,
  2013.                                      sizeof(Selserv->szSelected_Server_Name),
  2014.                                      Selserv->szSelected_Server_Name);
  2015.                  if(Selserv->szSelected_Server_Name[0] == 0)
  2016.                    {
  2017.                     /* If required field is not completed inform user and  */
  2018.                     /* query what he wants to do about it by presenting a  */
  2019.                     /* message box with the push buttons "Retry" and       */
  2020.                     /* "Cancel"                                            */
  2021.                     strcpy(szWorkBuf, "Server name required.  Push retry to supply one or cancel to abort dialog.");
  2022.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  2023.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  2024.                     
  2025.                     /* If the user presses "Cancel", post a message to the */
  2026.                     /* DID_CANCEL case and break out of this case          */
  2027.                     if(i == MBID_CANCEL)
  2028.                       {
  2029.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2030.                        break;
  2031.                       }
  2032.  
  2033.                     /* If the user presses "Retry", set focus to the       */
  2034.                     /* control that needs to be completed and break out    */
  2035.                     /* of this case                                        */
  2036.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_SELECTED_SERVER_NAME));
  2037.                     break;
  2038.                    }
  2039.  
  2040.                  /*******************************************************
  2041.                  *                                                      *
  2042.                  *     This section sets the UNIX format pulldown check *
  2043.                  *     value based upon the selected server's value.    *
  2044.                  *                                                      *
  2045.                  *******************************************************/
  2046.                  if(Selserv->ckSelected_UNIX_Format == TRUE)
  2047.                  {
  2048.                    i = MIA_CHECKED;
  2049.                  }
  2050.                  else
  2051.                  {
  2052.                    i = FALSE;
  2053.                  }
  2054.                  WinSendMsg(WinWindowFromID(hWndFrame, FID_MENU),
  2055.                             MM_SETITEMATTR,
  2056.                             MPFROM2SHORT(IDM_O_UNIXFORMAT, TRUE),
  2057.                             MPFROM2SHORT(MIA_CHECKED, i));
  2058.  
  2059.                  WinDismissDlg(hWndDlg, TRUE);
  2060.                  break;
  2061.  
  2062.             case DID_CANCEL: /* Button text: "Cancel"                      */
  2063.                  /* Ignore data values entered into the dialog controls    */
  2064.                  /* and dismiss the dialog window                          */
  2065.                  WinDismissDlg(hWndDlg, FALSE);
  2066.                  break;
  2067.  
  2068.             case DID_HELP: /* Button text: "Help"                          */
  2069.                  break;
  2070.  
  2071.            }
  2072.          break; /* End of WM_COMMAND */
  2073.                                
  2074.     case WM_CLOSE:
  2075.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2076.          break; /* End of WM_CLOSE */
  2077.            
  2078.     case WM_FAILEDVALIDATE:
  2079.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  2080.          sfValidate = FALSE;
  2081.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  2082.          sfValidate = TRUE;
  2083.          return((MRESULT)TRUE);
  2084.          break; /* End of WM_FAILEDVALIDATE */
  2085.  
  2086.     default:
  2087.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2088.          break;
  2089.    }
  2090.  return FALSE;
  2091. } /* End of SELSERVMsgProc */
  2092.  
  2093.  
  2094. /***************************************************************************/
  2095. /*                                                                         */
  2096. /* Dialog Window Procedure                                                 */
  2097. /*                                                                         */
  2098. /* This procedure is associated with the dialog box that is included in    */
  2099. /* the function name of the procedure. It provides the service routines    */
  2100. /* for the events (messages) that occur because the end user operates      */
  2101. /* one of the dialog box's buttons, entry fields, or controls.             */
  2102. /*                                                                         */
  2103. /* The SWITCH statement in the function distributes the dialog box         */
  2104. /* messages to the respective service routines, which are set apart by     */
  2105. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  2106. /* procedures must provide an appropriate service routine for their end    */
  2107. /* user initiated messages as well as for the general PM messages (like    */
  2108. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  2109. /* which there is no programmed CASE condition (no service routine),       */
  2110. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  2111. /* disposed of by PM.                                                      */
  2112. /*                                                                         */
  2113. /***************************************************************************/
  2114.  
  2115. MRESULT EXPENTRY ADDSERVMsgProc(hWndDlg, message, mp1, mp2)
  2116. HWND hWndDlg;
  2117. USHORT message;
  2118. MPARAM mp1;
  2119. MPARAM mp2;
  2120.  static SHORT sfValidate = TRUE;
  2121.  INT    i;
  2122.  static CHAR  szWorkBuf[90];
  2123.  static HWND  hWndParent;
  2124.  ADDSERVStruct FAR *Addserv;
  2125.           
  2126.  
  2127.  static INT free_entry;      /* Number of first free entry in the server table. */
  2128.  SELSERVStruct FAR *Selserv;
  2129.  CHAR *result;
  2130.  LOADRETURNStruct FAR *Return_Values;
  2131.  
  2132.  Selserv = (SELSERVStruct FAR *)WinQueryWindowULong(hWndClient,
  2133.                                                     OFFSET_SELSERV);
  2134.  switch(message)
  2135.    {
  2136.     case WM_INITDLG:
  2137.          Addserv = (ADDSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_ADDSERV);
  2138.          hWndParent = (HWND)mp2;
  2139.          cwCenter(hWndDlg, (HWND)hWndParent);
  2140.  
  2141.          Return_Values = (LOADRETURNStruct FAR *)
  2142.                          BgmLoadListBox(hWndDlg,
  2143.                                         DID_SERVER_LIST,
  2144.                                         Selserv->szServer_List,
  2145.                                         "Server list is full.  You will need to remove a server in order to add one.",
  2146.                                         TRUE);
  2147.  
  2148.          if((free_entry = Return_Values->free_entry) == -1)
  2149.          {
  2150.            break;
  2151.          }
  2152.  
  2153.          /* Initialize entry field control: szAdd_Server_Name              */
  2154.          WinSendDlgItemMsg(hWndDlg, DID_ADD_SERVER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  2155.          /* Initialize entry field control: szAdd_Server_Desc              */
  2156.          WinSendDlgItemMsg(hWndDlg, DID_ADD_SERVER_DESC, EM_SETTEXTLIMIT, MPFROMSHORT(103), 0L);
  2157.          break; /* End of WM_INITDLG */
  2158.    
  2159.     case WM_CONTROL:
  2160.          switch(SHORT1FROMMP(mp1))
  2161.            {
  2162.             case DID_UNIX_FORMAT: /* Checkbox text: "Use UNIX format"      */
  2163.                  {
  2164.                   USHORT checked;
  2165.  
  2166.                   /* Query check box control for current state             */
  2167.                   /* on return checked is set to:                          */
  2168.                   /*           1 if check box is in unchecked state        */
  2169.                   /*           0 if check box is in checked state          */
  2170.                   checked = !WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT,
  2171.                                                BM_QUERYCHECK, 0L, 0L );
  2172.                   /* Set checkbox control state                            */
  2173.                   WinSendDlgItemMsg(hWndDlg, DID_UNIX_FORMAT,
  2174.                                     BM_SETCHECK, MPFROMSHORT(checked), 0L);
  2175.                  }  
  2176.                  break;
  2177.  
  2178.             case DID_ADD_SERVER_NAME: /* Entry field variable: "szAdd_Server_Name" */
  2179.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  2180.                    { 
  2181.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  2182.                          break;
  2183.  
  2184.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  2185.                          {
  2186.                           /* Validate the field                            */
  2187.                           static char buffer[24];
  2188.                           WinQueryDlgItemText(hWndDlg, DID_ADD_SERVER_NAME,
  2189.                                               sizeof(buffer), buffer);
  2190.                           if(buffer[0]==0x00)
  2191.                             break;
  2192.                           if(sfValidate && !cwAlphaValidate(buffer))
  2193.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  2194.                          }
  2195.                          break;
  2196.  
  2197.                     default: /* Default other messages                     */
  2198.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2199.                          break;
  2200.                    }
  2201.                  break;
  2202.  
  2203.             case DID_ADD_SERVER_DESC: /* Entry field variable: "szAdd_Server_Desc" */
  2204.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  2205.                    { 
  2206.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  2207.                          break;
  2208.  
  2209.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  2210.                          break;
  2211.  
  2212.                     default: /* Default other messages                     */
  2213.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2214.                          break;
  2215.                    }
  2216.                  break;
  2217.  
  2218.             case DID_SERVER_LIST: /* List box                              */
  2219.                  {
  2220.  
  2221.                    /*****************************************************
  2222.                    *                                                    *
  2223.                    *     This section obtains from the server list the  *
  2224.                    *     entry pointed to by the end-user.  We break it *
  2225.                    *     into its two components (name and description).*
  2226.                    *     We then load these components into their       *
  2227.                    *     respective fields.                             *
  2228.                    *                                                    *
  2229.                    *     One example of when an user might point to an  *
  2230.                    *     entry is when he want to save some typing.     *
  2231.                    *                                                    *
  2232.                    *****************************************************/
  2233.                    USHORT checked;
  2234.                    USHORT sSelectIndex;
  2235.                    CHAR   szSelectText[129];
  2236.  
  2237.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  2238.                        break;
  2239.  
  2240.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  2241.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  2242.  
  2243.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  2244.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  2245.                                    MPFROMP(szSelectText));
  2246.  
  2247.                    /*****************************************************
  2248.                    *                                                    *
  2249.                    *     This section sets the UNIX format check box    *
  2250.                    *     based upon the entry selected by the end-user. *
  2251.                    *     We need to scan through the server list to     *
  2252.                    *     find the selected entry and then use the       *
  2253.                    *     server UNIX format array to set the box.       *
  2254.                    *                                                    *
  2255.                    *****************************************************/
  2256.                    for(i=0; i < 128; i++)
  2257.                    {
  2258.                      if (Selserv->szServer_List[i][0])
  2259.                      {
  2260.                        if(strnicmp(Selserv->szServer_List[i],
  2261.                                    szSelectText,
  2262.                                    strlen(szSelectText)) == 0)
  2263.                        {
  2264.                          checked = (USHORT) Selserv->ckServer_UNIX_Format[i];
  2265.                          WinSendDlgItemMsg(hWndDlg,
  2266.                                            DID_UNIX_FORMAT,
  2267.                                            BM_SETCHECK,
  2268.                                            MPFROMSHORT(checked),
  2269.                                            0L);
  2270.                          break;
  2271.                        }
  2272.                      }
  2273.                    }
  2274.  
  2275.                    result = strtok(szSelectText," ");
  2276.                    WinSetDlgItemText(hWndDlg,
  2277.                                      DID_ADD_SERVER_NAME,
  2278.                                      (PSZ) result);
  2279.  
  2280.                    result = strchr(szSelectText,'\0');
  2281.                    *result++;
  2282.  
  2283.                    WinSetDlgItemText(hWndDlg,
  2284.                                      DID_ADD_SERVER_DESC,
  2285.                                      result);
  2286.                  }
  2287.                  break;
  2288.  
  2289.            }
  2290.          break; /* End of WM_CONTROL */
  2291.    
  2292.     case WM_COMMAND:
  2293.          switch(SHORT1FROMMP(mp1))
  2294.            {
  2295.             case DID_OK: /* Button text: "Add"                             */
  2296.                   Addserv = (ADDSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_ADDSERV);
  2297.                  /* Query the string value in the entry field control and  */
  2298.                  /* move the string value to the dialog structure variable */
  2299.                  WinQueryDlgItemText(hWndDlg, DID_ADD_SERVER_NAME,
  2300.                                      sizeof(Addserv->szAdd_Server_Name),
  2301.                                      Addserv->szAdd_Server_Name);
  2302.                  if(Addserv->szAdd_Server_Name[0] == 0)
  2303.                    {
  2304.                     /* If required field is not completed inform user and  */
  2305.                     /* query what he wants to do about it by presenting a  */
  2306.                     /* message box with the push buttons "Retry" and       */
  2307.                     /* "Cancel"                                            */
  2308.                     strcpy(szWorkBuf, "Server name required.  Push retry to supply one or cancel to abort dialog.");
  2309.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  2310.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  2311.                     
  2312.                     /* If the user presses "Cancel", post a message to the */
  2313.                     /* DID_CANCEL case and break out of this case          */
  2314.                     if(i == MBID_CANCEL)
  2315.                       {
  2316.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2317.                        break;
  2318.                       }
  2319.  
  2320.                     /* If the user presses "Retry", set focus to the       */
  2321.                     /* control that needs to be completed and break out    */
  2322.                     /* of this case                                        */
  2323.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_ADD_SERVER_NAME));
  2324.                     break;
  2325.                    }
  2326.                  /* Query the string value in the entry field control and  */
  2327.                  /* move the string value to the dialog structure variable */
  2328.                  WinQueryDlgItemText(hWndDlg, DID_ADD_SERVER_DESC,
  2329.                                      sizeof(Addserv->szAdd_Server_Desc),
  2330.                                      Addserv->szAdd_Server_Desc);
  2331.  
  2332.                  if(BgmAddPrtSrv(hWndDlg,
  2333.                                  DID_ADD_SERVER_NAME,
  2334.                                  free_entry,
  2335.                                  Selserv->szServer_List,
  2336.                                  Addserv->szAdd_Server_Name,
  2337.                                  Addserv->szAdd_Server_Desc,
  2338.                                  "Server name duplication.  Push retry to change server name or push cancel to abort.")
  2339.                     == TRUE)
  2340.                  {
  2341.                    Selserv->ckServer_UNIX_Format[free_entry] =
  2342.                       (INT)(WinSendDlgItemMsg(hWndDlg,
  2343.                                               DID_UNIX_FORMAT,
  2344.                                               BM_QUERYCHECK,
  2345.                                               0L,
  2346.                                               0L));
  2347.  
  2348.                  WinDismissDlg(hWndDlg, TRUE);
  2349.                  }
  2350.                  break;
  2351.  
  2352.             case DID_CANCEL: /* Button text: "Cancel"                      */
  2353.                  /* Ignore data values entered into the dialog controls    */
  2354.                  /* and dismiss the dialog window                          */
  2355.                  WinDismissDlg(hWndDlg, FALSE);
  2356.                  break;
  2357.  
  2358.             case DID_HELP: /* Button text: "Help"                          */
  2359.                  break;
  2360.  
  2361.            }
  2362.          break; /* End of WM_COMMAND */
  2363.                                
  2364.     case WM_CLOSE:
  2365.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2366.          break; /* End of WM_CLOSE */
  2367.            
  2368.     case WM_FAILEDVALIDATE:
  2369.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  2370.          sfValidate = FALSE;
  2371.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  2372.          sfValidate = TRUE;
  2373.          return((MRESULT)TRUE);
  2374.          break; /* End of WM_FAILEDVALIDATE */
  2375.  
  2376.     default:
  2377.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2378.          break;
  2379.    }
  2380.  return FALSE;
  2381. } /* End of ADDSERVMsgProc */
  2382.  
  2383.  
  2384. /***************************************************************************/
  2385. /*                                                                         */
  2386. /* Dialog Window Procedure                                                 */
  2387. /*                                                                         */
  2388. /* This procedure is associated with the dialog box that is included in    */
  2389. /* the function name of the procedure. It provides the service routines    */
  2390. /* for the events (messages) that occur because the end user operates      */
  2391. /* one of the dialog box's buttons, entry fields, or controls.             */
  2392. /*                                                                         */
  2393. /* The SWITCH statement in the function distributes the dialog box         */
  2394. /* messages to the respective service routines, which are set apart by     */
  2395. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  2396. /* procedures must provide an appropriate service routine for their end    */
  2397. /* user initiated messages as well as for the general PM messages (like    */
  2398. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  2399. /* which there is no programmed CASE condition (no service routine),       */
  2400. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  2401. /* disposed of by PM.                                                      */
  2402. /*                                                                         */
  2403. /***************************************************************************/
  2404.  
  2405. MRESULT EXPENTRY DELSERVMsgProc(hWndDlg, message, mp1, mp2)
  2406. HWND hWndDlg;
  2407. USHORT message;
  2408. MPARAM mp1;
  2409. MPARAM mp2;
  2410.  static SHORT sfValidate = TRUE;
  2411.  INT    i;
  2412.  static CHAR  szWorkBuf[90];
  2413.  static HWND  hWndParent;
  2414.  DELSERVStruct FAR *Delserv;
  2415.           
  2416.  
  2417.  static INT last_entry;      /* Number of first free entry in the server table. */
  2418.  SELSERVStruct FAR *Selserv;
  2419.  CHAR *result;
  2420.  LOADRETURNStruct FAR *Return_Values;
  2421.  
  2422.  Selserv = (SELSERVStruct FAR *)WinQueryWindowULong(hWndClient,
  2423.                                                     OFFSET_SELSERV);
  2424.  switch(message)
  2425.    {
  2426.     case WM_INITDLG:
  2427.          Delserv = (DELSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_DELSERV);
  2428.          hWndParent = (HWND)mp2;
  2429.          cwCenter(hWndDlg, (HWND)hWndParent);
  2430.  
  2431.          Return_Values = (LOADRETURNStruct FAR *)
  2432.                          BgmLoadListBox(hWndDlg,
  2433.                                         DID_SERVER_LIST,
  2434.                                         Selserv->szServer_List,
  2435.                                         "A server does not exist to delete.  The server list is empty.",
  2436.                                         FALSE);
  2437.  
  2438.          if((last_entry = Return_Values->last_entry) == -1)
  2439.          {
  2440.            break;
  2441.          }
  2442.  
  2443.          /* Initialize entry field control: szDelete_Server_Name           */
  2444.          WinSendDlgItemMsg(hWndDlg, DID_DELETE_SERVER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  2445.          break; /* End of WM_INITDLG */
  2446.    
  2447.     case WM_CONTROL:
  2448.          switch(SHORT1FROMMP(mp1))
  2449.            {
  2450.             case DID_DELETE_SERVER_NAME: /* Entry field variable: "szDelete_Server_Name" */
  2451.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  2452.                    { 
  2453.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  2454.                          break;
  2455.  
  2456.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  2457.                          {
  2458.                           /* Validate the field                            */
  2459.                           static char buffer[24];
  2460.                           WinQueryDlgItemText(hWndDlg, DID_DELETE_SERVER_NAME,
  2461.                                               sizeof(buffer), buffer);
  2462.                           if(buffer[0]==0x00)
  2463.                             break;
  2464.                           if(sfValidate && !cwAlphaValidate(buffer))
  2465.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  2466.                          }
  2467.                          break;
  2468.  
  2469.                     default: /* Default other messages                     */
  2470.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2471.                          break;
  2472.                    }
  2473.                  break;
  2474.  
  2475.             case DID_SERVER_LIST: /* List box                              */
  2476.                  {
  2477.  
  2478.                    /*****************************************************
  2479.                    *                                                    *
  2480.                    *     This section obtains from the server list the  *
  2481.                    *     entry pointed to by the end-user.  We break it *
  2482.                    *     into its two components (name and description).*
  2483.                    *     We then load these components into their       *
  2484.                    *     respective fields.                             *
  2485.                    *                                                    *
  2486.                    *     One example of when an user might point to an  *
  2487.                    *     entry is when he want to save some typing.     *
  2488.                    *                                                    *
  2489.                    *****************************************************/
  2490.                    USHORT sSelectIndex;
  2491.                    CHAR   szSelectText[129];
  2492.  
  2493.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  2494.                        break;
  2495.  
  2496.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  2497.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  2498.  
  2499.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  2500.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  2501.                                    MPFROMP(szSelectText));
  2502.  
  2503.                    result = strtok(szSelectText," ");
  2504.                    WinSetDlgItemText(hWndDlg,
  2505.                                      DID_DELETE_SERVER_NAME,
  2506.                                      (PSZ) result);
  2507.                  }
  2508.                  break;
  2509.  
  2510.            }
  2511.          break; /* End of WM_CONTROL */
  2512.    
  2513.     case WM_COMMAND:
  2514.          switch(SHORT1FROMMP(mp1))
  2515.            {
  2516.             case DID_OK: /* Button text: "Delete"                          */
  2517.                   Delserv = (DELSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_DELSERV);
  2518.                  /* Query the string value in the entry field control and  */
  2519.                  /* move the string value to the dialog structure variable */
  2520.                  WinQueryDlgItemText(hWndDlg, DID_DELETE_SERVER_NAME,
  2521.                                      sizeof(Delserv->szDelete_Server_Name),
  2522.                                      Delserv->szDelete_Server_Name);
  2523.                  if(Delserv->szDelete_Server_Name[0] == 0)
  2524.                    {
  2525.                     /* If required field is not completed inform user and  */
  2526.                     /* query what he wants to do about it by presenting a  */
  2527.                     /* message box with the push buttons "Retry" and       */
  2528.                     /* "Cancel"                                            */
  2529.                     strcpy(szWorkBuf, "Server name required.  Push retry to supply one or cancel to abort dialog.");
  2530.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  2531.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  2532.                     
  2533.                     /* If the user presses "Cancel", post a message to the */
  2534.                     /* DID_CANCEL case and break out of this case          */
  2535.                     if(i == MBID_CANCEL)
  2536.                       {
  2537.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2538.                        break;
  2539.                       }
  2540.  
  2541.                     /* If the user presses "Retry", set focus to the       */
  2542.                     /* control that needs to be completed and break out    */
  2543.                     /* of this case                                        */
  2544.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_DELETE_SERVER_NAME));
  2545.                     break;
  2546.                    }
  2547.  
  2548.                  if(BgmDeletePrtSrv(hWndDlg,
  2549.                                     DID_DELETE_SERVER_NAME,
  2550.                                     last_entry,
  2551.                                     Selserv->szServer_List,
  2552.                                     Delserv->szDelete_Server_Name,
  2553.                                     "Server name not found.  Push retry to change server name or push cancel to abort.")
  2554.                     == TRUE)
  2555.                  {
  2556.                  WinDismissDlg(hWndDlg, TRUE);
  2557.                  }
  2558.                  break;
  2559.  
  2560.             case DID_CANCEL: /* Button text: "Cancel"                      */
  2561.                  /* Ignore data values entered into the dialog controls    */
  2562.                  /* and dismiss the dialog window                          */
  2563.                  WinDismissDlg(hWndDlg, FALSE);
  2564.                  break;
  2565.  
  2566.             case DID_HELP: /* Button text: "Help"                          */
  2567.                  break;
  2568.  
  2569.            }
  2570.          break; /* End of WM_COMMAND */
  2571.                                
  2572.     case WM_CLOSE:
  2573.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2574.          break; /* End of WM_CLOSE */
  2575.            
  2576.     case WM_FAILEDVALIDATE:
  2577.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  2578.          sfValidate = FALSE;
  2579.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  2580.          sfValidate = TRUE;
  2581.          return((MRESULT)TRUE);
  2582.          break; /* End of WM_FAILEDVALIDATE */
  2583.  
  2584.     default:
  2585.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2586.          break;
  2587.    }
  2588.  return FALSE;
  2589. } /* End of DELSERVMsgProc */
  2590.  
  2591.  
  2592. /***************************************************************************/
  2593. /*                                                                         */
  2594. /* Dialog Window Procedure                                                 */
  2595. /*                                                                         */
  2596. /* This procedure is associated with the dialog box that is included in    */
  2597. /* the function name of the procedure. It provides the service routines    */
  2598. /* for the events (messages) that occur because the end user operates      */
  2599. /* one of the dialog box's buttons, entry fields, or controls.             */
  2600. /*                                                                         */
  2601. /* The SWITCH statement in the function distributes the dialog box         */
  2602. /* messages to the respective service routines, which are set apart by     */
  2603. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  2604. /* procedures must provide an appropriate service routine for their end    */
  2605. /* user initiated messages as well as for the general PM messages (like    */
  2606. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  2607. /* which there is no programmed CASE condition (no service routine),       */
  2608. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  2609. /* disposed of by PM.                                                      */
  2610. /*                                                                         */
  2611. /***************************************************************************/
  2612.  
  2613. MRESULT EXPENTRY CHNGSERVMsgProc(hWndDlg, message, mp1, mp2)
  2614. HWND hWndDlg;
  2615. USHORT message;
  2616. MPARAM mp1;
  2617. MPARAM mp2;
  2618.  static SHORT sfValidate = TRUE;
  2619.  INT    i;
  2620.  static CHAR  szWorkBuf[90];
  2621.  static HWND  hWndParent;
  2622.  CHNGSERVStruct FAR *Chngserv;
  2623.           
  2624.  
  2625.  static INT Selected_Entry_Number;
  2626.  SELSERVStruct FAR *Selserv;
  2627.  CHAR *result;
  2628.  LOADRETURNStruct FAR *Return_Values;
  2629.  
  2630.  Selserv = (SELSERVStruct FAR *)WinQueryWindowULong(hWndClient,
  2631.                                                     OFFSET_SELSERV);
  2632.  switch(message)
  2633.    {
  2634.     case WM_INITDLG:
  2635.          Chngserv = (CHNGSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_CHNGSERV);
  2636.          hWndParent = (HWND)mp2;
  2637.          cwCenter(hWndDlg, (HWND)hWndParent);
  2638.  
  2639.          Selected_Entry_Number = -1;
  2640.  
  2641.          Return_Values = (LOADRETURNStruct FAR *)
  2642.                          BgmLoadListBox(hWndDlg,
  2643.                                         DID_SERVER_LIST,
  2644.                                         Selserv->szServer_List,
  2645.                                         "A server does not exist to change.  The server list is empty.",
  2646.                                         FALSE);
  2647.  
  2648.          if (Return_Values->last_entry == -1)
  2649.          {
  2650.            break;
  2651.          }
  2652.  
  2653.          /* Initialize entry field control: szChange_Server_Name           */
  2654.          WinSendDlgItemMsg(hWndDlg, DID_CHANGE_SERVER_NAME, EM_SETTEXTLIMIT, MPFROMSHORT(24), 0L);
  2655.          /* Initialize entry field control: szChange_Server_Desc           */
  2656.          WinSendDlgItemMsg(hWndDlg, DID_CHANGE_SERVER_DESC, EM_SETTEXTLIMIT, MPFROMSHORT(103), 0L);
  2657.          break; /* End of WM_INITDLG */
  2658.    
  2659.     case WM_CONTROL:
  2660.          switch(SHORT1FROMMP(mp1))
  2661.            {
  2662.             case DID_CHANGE_UNIX_FORMAT: /* Checkbox text: "Use UNIX format" */
  2663.                  {
  2664.                   USHORT checked;
  2665.  
  2666.                   /* Query check box control for current state             */
  2667.                   /* on return checked is set to:                          */
  2668.                   /*           1 if check box is in unchecked state        */
  2669.                   /*           0 if check box is in checked state          */
  2670.                   checked = !WinSendDlgItemMsg(hWndDlg, DID_CHANGE_UNIX_FORMAT,
  2671.                                                BM_QUERYCHECK, 0L, 0L );
  2672.                   /* Set checkbox control state                            */
  2673.                   WinSendDlgItemMsg(hWndDlg, DID_CHANGE_UNIX_FORMAT,
  2674.                                     BM_SETCHECK, MPFROMSHORT(checked), 0L);
  2675.                  }  
  2676.                  break;
  2677.  
  2678.             case DID_CHANGE_SERVER_NAME: /* Entry field variable: "szChange_Server_Name" */
  2679.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  2680.                    { 
  2681.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  2682.                          break;
  2683.  
  2684.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  2685.                          {
  2686.                           /* Validate the field                            */
  2687.                           static char buffer[24];
  2688.                           WinQueryDlgItemText(hWndDlg, DID_CHANGE_SERVER_NAME,
  2689.                                               sizeof(buffer), buffer);
  2690.                           if(buffer[0]==0x00)
  2691.                             break;
  2692.                           if(sfValidate && !cwAlphaValidate(buffer))
  2693.                             WinPostMsg(hWndDlg, WM_FAILEDVALIDATE, mp1, 0);
  2694.                          }
  2695.                          break;
  2696.  
  2697.                     default: /* Default other messages                     */
  2698.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2699.                          break;
  2700.                    }
  2701.                  break;
  2702.  
  2703.             case DID_CHANGE_SERVER_DESC: /* Entry field variable: "szChange_Server_Desc" */
  2704.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  2705.                    { 
  2706.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  2707.                          break;
  2708.  
  2709.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  2710.                          break;
  2711.  
  2712.                     default: /* Default other messages                     */
  2713.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2714.                          break;
  2715.                    }
  2716.                  break;
  2717.  
  2718.             case DID_SERVER_LIST: /* List box                              */
  2719.                  {
  2720.  
  2721.                    /*****************************************************
  2722.                    *                                                    *
  2723.                    *     This section obtains from the server list the  *
  2724.                    *     entry pointed to by the end-user.  We break it *
  2725.                    *     into its two components (name and description).*
  2726.                    *     We then load these components into their       *
  2727.                    *     respective fields.                             *
  2728.                    *                                                    *
  2729.                    *     One example of when an user might point to an  *
  2730.                    *     entry is when he want to save some typing.     *
  2731.                    *                                                    *
  2732.                    *****************************************************/
  2733.                    USHORT checked;
  2734.                    USHORT sSelectIndex;
  2735.                    CHAR   szSelectText[129];
  2736.  
  2737.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  2738.                        break;
  2739.  
  2740.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  2741.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  2742.  
  2743.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  2744.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  2745.                                    MPFROMP(szSelectText));
  2746.  
  2747.                    /*****************************************************
  2748.                    *                                                    *
  2749.                    *     This section performs two functions:           *
  2750.                    *                                                    *
  2751.                    *     1)  Sets the UNIX format check box based upon  *
  2752.                    *         the entry selected by the end-user.        *
  2753.                    *         We need to scan through the server list to *
  2754.                    *         find the selected entry and then use the   *
  2755.                    *         server UNIX format array to set the box.   *
  2756.                    *                                                    *
  2757.                    *     2)  Finds the server entry the user just       *
  2758.                    *         selected.  The change key (DID_OK) code    *
  2759.                    *         uses this number to indicate which entry   *
  2760.                    *         the user is changing.  This approach       *
  2761.                    *         permits the end-user to change both the    *
  2762.                    *         name and description instead of just the   *
  2763.                    *         name.                                      *
  2764.                    *                                                    *
  2765.                    *****************************************************/
  2766.                    for(i=0; i < 128; i++)
  2767.                    {
  2768.                      if (Selserv->szServer_List[i][0])
  2769.                      {
  2770.                        if(strnicmp(Selserv->szServer_List[i],
  2771.                                    szSelectText,
  2772.                                    strlen(szSelectText)) == 0)
  2773.                        {
  2774.                          Selected_Entry_Number = i;
  2775.                          checked = (USHORT) Selserv->ckServer_UNIX_Format[i];
  2776.                          WinSendDlgItemMsg(hWndDlg,
  2777.                                            DID_UNIX_FORMAT,
  2778.                                            BM_SETCHECK,
  2779.                                            MPFROMSHORT(checked),
  2780.                                            0L);
  2781.                          break;
  2782.                        }
  2783.                      }
  2784.                    }
  2785.  
  2786.                    result = strtok(szSelectText," ");
  2787.                    WinSetDlgItemText(hWndDlg,
  2788.                                      DID_CHANGE_SERVER_NAME,
  2789.                                      (PSZ) result);
  2790.  
  2791.                    result = strchr(szSelectText,'\0');
  2792.                    *result++;
  2793.  
  2794.                    WinSetDlgItemText(hWndDlg,
  2795.                                      DID_CHANGE_SERVER_DESC,
  2796.                                      result);
  2797.                  }
  2798.                  break;
  2799.  
  2800.            }
  2801.          break; /* End of WM_CONTROL */
  2802.    
  2803.     case WM_COMMAND:
  2804.          switch(SHORT1FROMMP(mp1))
  2805.            {
  2806.             case DID_OK: /* Button text: "Change"                          */
  2807.                   Chngserv = (CHNGSERVStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_CHNGSERV);
  2808.                  /* Query the string value in the entry field control and  */
  2809.                  /* move the string value to the dialog structure variable */
  2810.                  WinQueryDlgItemText(hWndDlg, DID_CHANGE_SERVER_NAME,
  2811.                                      sizeof(Chngserv->szChange_Server_Name),
  2812.                                      Chngserv->szChange_Server_Name);
  2813.                  if(Chngserv->szChange_Server_Name[0] == 0)
  2814.                    {
  2815.                     /* If required field is not completed inform user and  */
  2816.                     /* query what he wants to do about it by presenting a  */
  2817.                     /* message box with the push buttons "Retry" and       */
  2818.                     /* "Cancel"                                            */
  2819.                     strcpy(szWorkBuf, "Server name required.  Push retry to supply one or cancel to abort dialog.");
  2820.                     i = WinMessageBox(HWND_DESKTOP, hWndDlg, szWorkBuf,
  2821.                                       szAppName, 0, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
  2822.                     
  2823.                     /* If the user presses "Cancel", post a message to the */
  2824.                     /* DID_CANCEL case and break out of this case          */
  2825.                     if(i == MBID_CANCEL)
  2826.                       {
  2827.                        WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2828.                        break;
  2829.                       }
  2830.  
  2831.                     /* If the user presses "Retry", set focus to the       */
  2832.                     /* control that needs to be completed and break out    */
  2833.                     /* of this case                                        */
  2834.                     WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, DID_CHANGE_SERVER_NAME));
  2835.                     break;
  2836.                    }
  2837.                  /* Query the string value in the entry field control and  */
  2838.                  /* move the string value to the dialog structure variable */
  2839.                  WinQueryDlgItemText(hWndDlg, DID_CHANGE_SERVER_DESC,
  2840.                                      sizeof(Chngserv->szChange_Server_Desc),
  2841.                                      Chngserv->szChange_Server_Desc);
  2842.  
  2843.                  if((i = BgmChangePrtSrv(hWndDlg,
  2844.                                          DID_CHANGE_SERVER_NAME,
  2845.                                          Selected_Entry_Number,
  2846.                                          Selserv->szServer_List,
  2847.                                          Chngserv->szChange_Server_Name,
  2848.                                          Chngserv->szChange_Server_Desc,
  2849.                                          "Server name not found.  Push retry to change server name or push cancel to abort."))
  2850.                     != -1)
  2851.                  {
  2852.                    Selserv->ckServer_UNIX_Format[i] =
  2853.                       (INT)(WinSendDlgItemMsg(hWndDlg,
  2854.                                               DID_UNIX_FORMAT,
  2855.                                               BM_QUERYCHECK,
  2856.                                               0L,
  2857.                                               0L));
  2858.                  WinDismissDlg(hWndDlg, TRUE);
  2859.                  }
  2860.                  break;
  2861.  
  2862.             case DID_CANCEL: /* Button text: "Cancel"                      */
  2863.                  /* Ignore data values entered into the dialog controls    */
  2864.                  /* and dismiss the dialog window                          */
  2865.                  WinDismissDlg(hWndDlg, FALSE);
  2866.                  break;
  2867.  
  2868.             case DID_HELP: /* Button text: "Help"                          */
  2869.                  break;
  2870.  
  2871.            }
  2872.          break; /* End of WM_COMMAND */
  2873.                                
  2874.     case WM_CLOSE:
  2875.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  2876.          break; /* End of WM_CLOSE */
  2877.            
  2878.     case WM_FAILEDVALIDATE:
  2879.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  2880.          sfValidate = FALSE;
  2881.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  2882.          sfValidate = TRUE;
  2883.          return((MRESULT)TRUE);
  2884.          break; /* End of WM_FAILEDVALIDATE */
  2885.  
  2886.     default:
  2887.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2888.          break;
  2889.    }
  2890.  return FALSE;
  2891. } /* End of CHNGSERVMsgProc */
  2892.  
  2893.  
  2894. /***************************************************************************/
  2895. /*                                                                         */
  2896. /* Dialog Window Procedure                                                 */
  2897. /*                                                                         */
  2898. /* This procedure is associated with the dialog box that is included in    */
  2899. /* the function name of the procedure. It provides the service routines    */
  2900. /* for the events (messages) that occur because the end user operates      */
  2901. /* one of the dialog box's buttons, entry fields, or controls.             */
  2902. /*                                                                         */
  2903. /* The SWITCH statement in the function distributes the dialog box         */
  2904. /* messages to the respective service routines, which are set apart by     */
  2905. /* the CASE clauses. Like any other PM window, the Dialog Window           */
  2906. /* procedures must provide an appropriate service routine for their end    */
  2907. /* user initiated messages as well as for the general PM messages (like    */
  2908. /* the WM_CLOSE message). If a message is sent to this procedure for       */
  2909. /* which there is no programmed CASE condition (no service routine),       */
  2910. /* the message is defaulted to the WinDefDlgProc function, where it is     */
  2911. /* disposed of by PM.                                                      */
  2912. /*                                                                         */
  2913. /***************************************************************************/
  2914.  
  2915. MRESULT EXPENTRY QUERYPRTMsgProc(hWndDlg, message, mp1, mp2)
  2916. HWND hWndDlg;
  2917. USHORT message;
  2918. MPARAM mp1;
  2919. MPARAM mp2;
  2920.  static SHORT sfValidate = TRUE;
  2921.  INT    i;
  2922.  static HWND  hWndParent;
  2923.  QUERYPRTStruct FAR *Queryprt;
  2924.           
  2925.  switch(message)
  2926.    {
  2927.     case WM_INITDLG:
  2928.          Queryprt = (QUERYPRTStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_QUERYPRT);
  2929.          hWndParent = (HWND)mp2;
  2930.          cwCenter(hWndDlg, (HWND)hWndParent);
  2931.          for (i=0; i < 128; i++)
  2932.             if (Queryprt->szQuery_Remote_Printer_List[i][0])
  2933.                WinSendDlgItemMsg(hWndDlg, DID_Q_R_P_LIST_BOX, LM_INSERTITEM,
  2934.                          MPFROM2SHORT(LIT_SORTASCENDING, 0),
  2935.                          MPFROMP(Queryprt->szQuery_Remote_Printer_List[i]));
  2936.          break; /* End of WM_INITDLG */
  2937.    
  2938.     case WM_CONTROL:
  2939.          switch(SHORT1FROMMP(mp1))
  2940.            {
  2941.             case DID_Q_R_P_LIST_BOX: /* List box                           */
  2942.                  {
  2943.                    USHORT sSelectIndex;
  2944.                    CHAR   szSelectText[80];   
  2945.  
  2946.                    if (SHORT2FROMMP(mp1) != LN_SELECT)
  2947.                        break;
  2948.  
  2949.                    sSelectIndex = (USHORT)WinSendDlgItemMsg(hWndDlg,
  2950.                           SHORT1FROMMP(mp1), LM_QUERYSELECTION, 0L, 0L);
  2951.  
  2952.                    WinSendDlgItemMsg(hWndDlg, SHORT1FROMMP(mp1), LM_QUERYITEMTEXT,
  2953.                                    MPFROM2SHORT(sSelectIndex, sizeof(szSelectText)),
  2954.                                    MPFROMP(szSelectText));
  2955.                  }
  2956.                  break;
  2957.  
  2958.            }
  2959.          break; /* End of WM_CONTROL */
  2960.    
  2961.     case WM_COMMAND:
  2962.          switch(SHORT1FROMMP(mp1))
  2963.            {
  2964.             case DID_OK: /* Button text: "Continue"                        */
  2965.                   Queryprt = (QUERYPRTStruct FAR *)WinQueryWindowULong(hWndClient, OFFSET_QUERYPRT);
  2966.                  WinDestroyWindow(hWndDlg);
  2967.                  hWndQUERYPRT = 0;
  2968.                  break;
  2969.  
  2970.            }
  2971.          break; /* End of WM_COMMAND */
  2972.                                
  2973.     case WM_CLOSE:
  2974.          WinDismissDlg(hWndDlg, FALSE);
  2975.          break; /* End of WM_CLOSE */
  2976.            
  2977.     case WM_FAILEDVALIDATE:
  2978.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  2979.          sfValidate = FALSE;
  2980.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  2981.          sfValidate = TRUE;
  2982.          return((MRESULT)TRUE);
  2983.          break; /* End of WM_FAILEDVALIDATE */
  2984.  
  2985.     default:
  2986.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  2987.          break;
  2988.    }
  2989.  return FALSE;
  2990. } /* End of QUERYPRTMsgProc */
  2991.  
  2992.