home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / pcsmain / pcsmain.c next >
Text File  |  2002-02-28  |  55KB  |  1,284 lines

  1. /******************************************************************************
  2. *                                                                             *
  3. * File Name   : PCSMAIN.C                                                     *
  4. *                                                                             *
  5. * Descriptive name : PCSAPI Sample Program                                    *
  6. *                                                                             *
  7. * Author:  IBM                                                                *
  8. * Date Written:  1996                                                         *
  9. * For use with IBM Personal Communications/3270/5250 for Windows 95           *
  10. *                                                                             *
  11. * Notes:                                                                      *
  12. *        This sample uses PCOM PCSAPI interface. 3270 or 5250 emulator can    *
  13. *        be started/stopped with this program.                                *
  14. *                                                                             *
  15. * Compiler: MicroSoft Visual C++ version 2.2                                  *
  16. *                                                                             *
  17. * Required                                                                    *
  18. *  header : pcsmain.h pcsapi.h pcsapi32.h                                     *
  19. *  lib    : pcscal32.lib                                                      *
  20. *                                                                             *
  21. ******************************************************************************/
  22. /******************************************************************************
  23. * Common header files                                                         *
  24. ******************************************************************************/
  25. #include <windows.h>    // Windows definitions
  26. #include <windowsx.h>   // Windows Macro APIs, window message crackers
  27. #include <stdio.h>      // Standard IO
  28. #include <string.h>     // String
  29.  
  30. /******************************************************************************
  31. * Local header files                                                          *
  32. ******************************************************************************/
  33. #include "pcsapi.h"
  34. #include "pcsmain.h"
  35.  
  36. /*******************************************************************************
  37. *                                                                              *
  38. *   FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)                              *
  39. *                                                                              *
  40. *******************************************************************************/
  41. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  42. HANDLE   hInstance;
  43. HANDLE   hPrevInstance;
  44. LPSTR    lpszCmdLine;
  45. int      nCmdShow;
  46. {
  47.    MSG         msg;
  48.    WNDCLASS    wc;
  49.    RECT        rectMain;
  50.    char        szBuffer1[BUFFER_LENGTH] ;
  51.    char        szBuffer2[BUFFER_LENGTH] ;
  52.  
  53.    if (!hPrevInstance)
  54.    {
  55.       LoadString(hInstance, LS_MENU, (LPSTR)szBuffer1, sizeof(szBuffer1));
  56.       LoadString(hInstance, LS_CLASS, (LPSTR)szBuffer2, sizeof(szBuffer2));
  57.       wc.style         = 0;
  58.       wc.lpfnWndProc   = MainWndProc;
  59.       wc.cbClsExtra    = 0;
  60.       wc.cbWndExtra    = 0;
  61.       wc.hInstance     = hInstance;
  62.       wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(ICONPCSMAIN));
  63.       wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  64.       wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  65.       wc.lpszMenuName  = (LPSTR)szBuffer1;
  66.       wc.lpszClassName = (LPSTR)szBuffer2;
  67.  
  68.       if (!RegisterClass (&wc))
  69.          return FALSE;
  70.    }
  71.  
  72.    LoadString(hInstance, LS_TITLE, (LPSTR)szBuffer1, sizeof(szBuffer1));
  73.    ghMainWnd = CreateWindow((LPSTR)szBuffer2,
  74.                             (LPSTR)szBuffer1,
  75.                             WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
  76.                             WS_MINIMIZEBOX,
  77.                             CW_USEDEFAULT,
  78.                             CW_USEDEFAULT,
  79.                             MAIN_WIDTH,
  80.                             MAIN_HEIGHT,
  81.                             NULL,
  82.                             NULL,
  83.                             hInstance,
  84.                             NULL);
  85.  
  86.    if (!ghMainWnd)
  87.        return FALSE;
  88.  
  89.    GetClientRect(ghMainWnd, &rectMain);
  90.  
  91.    LoadString(hInstance, LS_LISTBOX, (LPSTR)szBuffer1, sizeof(szBuffer1));
  92.    ghListBox = CreateWindow((LPSTR)szBuffer1,
  93.                             NULL,
  94.                             WS_CHILD | WS_VSCROLL | WS_HSCROLL
  95.                             | LBS_NOINTEGRALHEIGHT | WS_VISIBLE | LBS_NOTIFY,
  96.                             0,
  97.                             0,
  98.                             rectMain.right - rectMain.left,
  99.                             rectMain.bottom - rectMain.top,
  100.                             ghMainWnd,
  101.                             (HMENU)IDD_LIST,
  102.                             hInstance,
  103.                             NULL);
  104.  
  105.    if (!ghListBox)
  106.       return FALSE;
  107.  
  108.    ShowWindow(ghMainWnd, nCmdShow);
  109.    UpdateWindow(ghMainWnd);
  110.  
  111.    ghInst = hInstance;
  112.  
  113.    while (GetMessage (&msg, NULL, 0L, 0L))
  114.    {
  115.       TranslateMessage (&msg);
  116.       DispatchMessage (&msg);
  117.    }
  118.    return msg.wParam;
  119. }
  120.  
  121. /*******************************************************************************
  122. *                                                                              *
  123. *   FUNCTION: MainWndProc()                                                    *
  124. *                                                                              *
  125. *   PURPOSE:                                                                   *
  126. *                                                                              *
  127. *   This function handles messages belonging to the main window.               *
  128. *                                                                              *
  129. *******************************************************************************/
  130. LRESULT CALLBACK MainWndProc(hWnd, iMessage, wParam, lParam)
  131. HWND     hWnd;
  132. UINT     iMessage;
  133. WPARAM   wParam;
  134. LPARAM   lParam;
  135. {
  136.    FARPROC  lpDialogProc;
  137.    HANDLE   hMenu;
  138.  
  139.    switch (iMessage)
  140.    {
  141.       case WM_COMMAND:
  142.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  143.          {
  144.             case IDM_FILE_ABOUT:
  145.                lpDialogProc = MakeProcInstance (About, ghInst);
  146.                DialogBox (ghInst,
  147.                           MAKEINTRESOURCE(ABOUTBOX),
  148.                           hWnd,
  149.                           lpDialogProc);
  150.                FreeProcInstance (lpDialogProc);
  151.                break;
  152.  
  153.             case IDM_FILE_TITLE:
  154.                lpDialogProc = MakeProcInstance(TitleDlgProc, ghInst);
  155.                DialogBox(ghInst,
  156.                          MAKEINTRESOURCE(TITLEBOX),
  157.                          hWnd,
  158.                          lpDialogProc);
  159.                FreeProcInstance (lpDialogProc);
  160.                break;
  161.  
  162.             case  IDM_FILE_TOP:
  163.                hMenu = GetMenu(hWnd);
  164.                if (fTopmost)
  165.                {
  166.                   fTopmost = FALSE;
  167.                   CheckMenuItem(hMenu, IDM_FILE_TOP, MF_UNCHECKED) ;
  168.                }
  169.                else
  170.                {
  171.                   fTopmost = TRUE;
  172.                   CheckMenuItem(hMenu, IDM_FILE_TOP, MF_CHECKED) ;
  173.                }
  174.                SetWindowPos(hWnd, (fTopmost ? HWND_TOPMOST : HWND_NOTOPMOST),
  175.                             0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE |
  176.                             SWP_NOMOVE);
  177.                break;
  178.  
  179.             case IDM_FILE_CLEAR:
  180.                SendDlgItemMessage(hWnd, IDD_LIST, LB_RESETCONTENT, 0, 0L);
  181.                break;
  182.  
  183.             case IDM_FILE_EXIT:
  184.                PostMessage(hWnd, WM_CLOSE, 0, 0);
  185.                break;
  186.  
  187.             case IDM_PCSAPI_START:
  188.                lpDialogProc = MakeProcInstance(StartDlgProc, ghInst);
  189.                DialogBox(ghInst,
  190.                          MAKEINTRESOURCE(START_DLG),
  191.                          hWnd,
  192.                          lpDialogProc);
  193.                FreeProcInstance (lpDialogProc);
  194.                break;
  195.  
  196.             case IDM_PCSAPI_STOP:
  197.                lpDialogProc = MakeProcInstance(StopDlgProc, ghInst);
  198.                DialogBox(ghInst,
  199.                          MAKEINTRESOURCE(STOP_DLG),
  200.                          hWnd,
  201.                          lpDialogProc);
  202.                FreeProcInstance (lpDialogProc);
  203.                break;
  204.  
  205.             case IDM_PCSAPI_STATUS:
  206.                lpDialogProc = MakeProcInstance(StatusDlgProc, ghInst);
  207.                DialogBox(ghInst,
  208.                          MAKEINTRESOURCE(STATUS_DLG),
  209.                          hWnd,
  210.                          lpDialogProc);
  211.                FreeProcInstance (lpDialogProc);
  212.                break;
  213.  
  214.             case IDM_PCSAPI_PROFILE:
  215.                lpDialogProc = MakeProcInstance(ProfileDlgProc, ghInst);
  216.                DialogBox(ghInst,
  217.                          MAKEINTRESOURCE(PROF_DLG),
  218.                          hWnd,
  219.                          lpDialogProc);
  220.                FreeProcInstance (lpDialogProc);
  221.                break;
  222.  
  223.             case IDM_PCSAPI_CONN:
  224.                lpDialogProc = MakeProcInstance(ConnectDlgProc, ghInst);
  225.                DialogBox(ghInst,
  226.                          MAKEINTRESOURCE(CONN_DLG),
  227.                          hWnd,
  228.                          lpDialogProc);
  229.                FreeProcInstance (lpDialogProc);
  230.                break;
  231.  
  232.             case IDM_PCSAPI_DISCONN:
  233.                lpDialogProc = MakeProcInstance(DisconnectDlgProc, ghInst);
  234.                DialogBox(ghInst,
  235.                          MAKEINTRESOURCE(DISCONN_DLG),
  236.                          hWnd,
  237.                          lpDialogProc);
  238.                FreeProcInstance (lpDialogProc);
  239.                break;
  240.  
  241.             case IDM_PCSAPI_TIMEOUT:
  242.                lpDialogProc = MakeProcInstance(SetLinkTimeoutDlgProc, ghInst);
  243.                DialogBox(ghInst,
  244.                          MAKEINTRESOURCE(TIMEOUT_DLG),
  245.                          hWnd,
  246.                          lpDialogProc);
  247.                FreeProcInstance (lpDialogProc);
  248.                break;
  249.  
  250.             default:
  251.                return DefWindowProc (hWnd, iMessage, wParam, lParam);
  252.          }
  253.          break;
  254.  
  255.       case WM_DESTROY:
  256.          PostQuitMessage (0);
  257.          break;
  258.  
  259.       case WM_CREATE:
  260.          // Check menu
  261.          hMenu = GetMenu(hWnd) ;
  262.          if (fTopmost)
  263.          {
  264.             CheckMenuItem(hMenu, IDM_FILE_TOP, MF_CHECKED) ;
  265.             SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
  266.                          SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  267.          }
  268.          else
  269.          {
  270.             CheckMenuItem(hMenu, IDM_FILE_TOP, MF_UNCHECKED) ;
  271.             SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
  272.                          SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  273.          }
  274.          break;
  275.  
  276.       default:
  277.          return DefWindowProc (hWnd, iMessage, wParam, lParam);
  278.  
  279.    }
  280.    return 0L;
  281. }
  282.  
  283. /*******************************************************************************
  284. *                                                                              *
  285. *   FUNCTION: About()                                                          *
  286. *                                                                              *
  287. *   PURPOSE:                                                                   *
  288. *                                                                              *
  289. *******************************************************************************/
  290. LRESULT CALLBACK About(hDlg, iMessage, wParam, lParam)
  291. HWND     hDlg;
  292. UINT     iMessage;
  293. WPARAM   wParam;
  294. LPARAM   lParam;
  295. {
  296.    switch (iMessage)
  297.    {
  298.       case WM_INITDIALOG:
  299.          return TRUE;
  300.  
  301.       case WM_COMMAND:
  302.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  303.          {
  304.             case IDOK:
  305.             case IDCANCEL:
  306.                EndDialog (hDlg, TRUE);
  307.                return TRUE;
  308.  
  309.             default:
  310.                break;
  311.          }
  312.    }
  313.    return FALSE;
  314. }
  315.  
  316. /*******************************************************************************
  317. *                                                                              *
  318. *   FUNCTION: TitleDlgProc                                                     *
  319. *                                                                              *
  320. *   PURPOSE:                                                                   *
  321. *                                                                              *
  322. *   This function handles messages belonging to the "Change Title" dialog box. *
  323. *   It displays information of options.                                        *
  324. *                                                                              *
  325. *******************************************************************************/
  326. LRESULT CALLBACK TitleDlgProc(hDlg, iMessage, wParam, lParam)
  327. HWND     hDlg;
  328. UINT     iMessage;
  329. WPARAM   wParam;
  330. LPARAM   lParam;
  331. {
  332.    char  szTitle[TITLE_LEN];
  333.  
  334.    switch (iMessage)
  335.    {
  336.       case WM_INITDIALOG:
  337.          GetWindowText(ghMainWnd, (LPSTR)szTitle, sizeof(szTitle)) ;
  338.          SetDlgItemText(hDlg, IDD_TITLE, (LPSTR)szTitle) ;
  339.          return TRUE;
  340.  
  341.       case WM_COMMAND:
  342.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  343.          {
  344.             case IDOK:
  345.                GetDlgItemText(hDlg, IDD_TITLE, (LPSTR)szTitle,
  346.                               sizeof(szTitle));
  347.                SetWindowText(ghMainWnd, (LPSTR)szTitle);
  348.                EndDialog (hDlg, TRUE);
  349.                return TRUE;
  350.  
  351.             case IDCANCEL:
  352.                EndDialog (hDlg, FALSE);
  353.                return TRUE;
  354.  
  355.             default:
  356.                break;
  357.          }
  358.    }
  359.    return FALSE;
  360. }
  361.  
  362. /*******************************************************************************
  363. *                                                                              *
  364. *  Name       : StartDlgProc                                                   *
  365. *                                                                              *
  366. *  Description: Processes all messages sent to the Start Session dialog.       *
  367. *               This procedure use "pcsStartSession".                          *
  368. *                                                                              *
  369. *  Concepts : Called for each message sent to the Start Session dialog box.    *
  370. *             A switch statement branches to the routines to be                *
  371. *             performed for each message processed.  Any messages              *
  372. *             not specifically process are passed to the default               *
  373. *             window procedure DefDlgProc().                                   *
  374. *                                                                              *
  375. *******************************************************************************/
  376. LRESULT CALLBACK StartDlgProc(hDlg, iMessage, wParam, lParam)
  377. HWND     hDlg;
  378. UINT     iMessage;
  379. WPARAM   wParam;
  380. LPARAM   lParam;
  381. {
  382.    ULONG    rc;                          /* Return code                   */
  383.    SHORT    fuCmdShow;                   /* Session creation control flags*/
  384.    CHAR     cShortSessionID[2];          /* Session ID                    */
  385.    CHAR     message[332];                /* Message buffer                */
  386.    CHAR     message1[80], message2[80];  /* Message buffer                */
  387.    SYSTEMTIME DateTime;                  /* Time area                     */
  388.  
  389.    switch(iMessage)
  390.    {
  391.       case WM_INITDIALOG:
  392.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  393.          SendDlgItemMessage(hDlg, DID_PRONAME, EM_LIMITTEXT, MAXPATHLEN-1, 0L);
  394.          fuCmdShow = DID_SHOW;
  395.          CheckRadioButton(hDlg,DID_VIS_GP, DID_SHOW_NO_ACT, fuCmdShow);
  396.          SetDlgItemText(hDlg, DID_PRONAME, glpProfile);
  397.          return (TRUE);
  398.  
  399.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  400.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  401.          {
  402.             case IDOK:                 /* The 'Start Session' pushbutton*/
  403.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  404.                GetDlgItemText(hDlg, DID_PRONAME, glpProfile, MAXPATHLEN);
  405.  
  406.                if (IsDlgButtonChecked(hDlg, DID_HIDE))
  407.                  fuCmdShow = (SHORT)SW_HIDE;
  408.                else if (IsDlgButtonChecked(hDlg, DID_SHOW_MIN))
  409.                  fuCmdShow = (SHORT)SW_SHOWMINIMIZED;
  410.                else if (IsDlgButtonChecked(hDlg, DID_SHOW_MAX))
  411.                  fuCmdShow = (SHORT)SW_SHOWMAXIMIZED;
  412.                else
  413.                  fuCmdShow = (SHORT)SW_SHOWNORMAL;
  414.  
  415.                if(glpProfile[0] == 0x00)
  416.                {
  417.                   LoadString(ghInst, LS_NO_PROFILENAME, (LPSTR)message1, sizeof(message1));
  418.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  419.                   MessageBox(NULL,
  420.                              message1,
  421.                              message2,
  422.                              MB_OK);
  423.                   return (TRUE);
  424.                   break;
  425.                }
  426.                rc = pcsStartSession((PSZ)glpProfile,   /* Profile name     */
  427.                                     *cShortSessionID, /* Session ID       */
  428.                                          /* Session creation control flags*/
  429.                                     fuCmdShow);
  430.  
  431.                if(rc != PCS_SUCCESSFUL)  /* pcsStartSession is failed.    */
  432.                {
  433.                   switch(rc)
  434.                   {
  435.                      case PCS_INVALID_ID:
  436.                                          /* Invalid Session ID specified  */
  437.                         LoadString(ghInst, LS_INVALID_SESSIONID, (LPSTR)message, sizeof(message));
  438.                         break;
  439.  
  440.                      case PCS_USED_ID:
  441.                                    /* Specified Session ID already active */
  442.                         LoadString(ghInst, LS_ACTIVE_SESSIONID, (LPSTR)message, sizeof(message));
  443.                         break;
  444.  
  445.                      case PCS_INVALID_PROFILE:
  446.                                          /* Error found in Profile        */
  447.                         LoadString(ghInst, LS_PROFILE_ERROR, (LPSTR)message, sizeof(message));
  448.                         break;
  449.  
  450.                      case PCS_SYSTEM_ERROR:
  451.                                          /* System error                  */
  452.                         LoadString(ghInst, LS_SYSTEM_ERROR, (LPSTR)message, sizeof(message));
  453.                         break;
  454.                   }
  455.                }
  456.                else                      /* pcsStartSession is succeed.   */
  457.                {
  458.                   strcpy(message, "Session ");
  459.  
  460.                   strcat(message, cShortSessionID);
  461.  
  462.                   strcat(message, " started");
  463.                }
  464.                /*
  465.                 * Displays a message box containing an error message or
  466.                 * a successful message.
  467.                 */
  468.                LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  469.                MessageBox(NULL,
  470.                           message,
  471.                           message2,
  472.                           MB_OK);
  473.                GetLocalTime(&DateTime);
  474.  
  475.                /*
  476.                 * Log message is edited.
  477.                 */
  478.                sprintf(message,
  479.                        "%02d:%02d : Start Session  Buffer = %s, Session ID = %s, Window option = %d, RC = %d",
  480.                        DateTime.wHour,
  481.                        DateTime.wMinute,
  482.                        glpProfile,
  483.                        cShortSessionID,
  484.                        fuCmdShow,
  485.                        rc );
  486.  
  487.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  488.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  489.                return (TRUE);
  490.                break;
  491.  
  492.             case IDCANCEL:            /* The 'Exit' pushbutton          */
  493.                EndDialog(hDlg, TRUE);
  494.                return (TRUE);
  495.                break;
  496.  
  497.             default:
  498.                break;
  499.          }
  500.          break;
  501.    }
  502.    return (FALSE);
  503. } /* End of StartDlgProc */
  504.  
  505. /*******************************************************************************
  506. *                                                                              *
  507. *  Name       : StopDlgProc                                                    *
  508. *                                                                              *
  509. *  Description: Processes all messages sent to the Stop Session dialog.        *
  510. *               This procedure use "pcsStopSession".                           *
  511. *                                                                              *
  512. *  Concepts : Called for each message sent to the Stop Session dialog box.     *
  513. *             A switch statement branches to the routines to be                *
  514. *             performed for each message processed.  Any messages              *
  515. *             not specifically process are passed to the default               *
  516. *             window procedure DefDlgProc().                                   *
  517. *                                                                              *
  518. *******************************************************************************/
  519. LRESULT CALLBACK StopDlgProc(hDlg, iMessage, wParam, lParam)
  520. HWND     hDlg;
  521. UINT     iMessage;
  522. WPARAM   wParam;
  523. LPARAM   lParam;
  524. {
  525.    CHAR     cShortSessionID[2];          /* Session ID                    */
  526.    SHORT    fuSaveProfile;               /* Saving profile option         */
  527.    BOOL     brc;                         /* Return code                   */
  528.    CHAR     rc[6];                       /* "TRUE" or "FALSE"             */
  529.    CHAR     message[332];                /* Message buffer                */
  530.    CHAR     message1[80], message2[80];  /* Message buffer                */
  531.    SYSTEMTIME DateTime;                  /* Time area                     */
  532.                                          /* Message box creation control  */
  533.    switch(iMessage)
  534.    {
  535.       case WM_INITDIALOG:
  536.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  537.          CheckRadioButton(hDlg,DID_SAVE_AS_PROFILE, DID_NOSAVE_ON_EXIT, DID_SAVE_AS_PROFILE);
  538.          return (TRUE);
  539.  
  540.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  541.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  542.          {
  543.             case IDOK:
  544.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  545.                /*
  546.                 * If cShortSessionID is empty, displays a message box
  547.                 * containing an error message.
  548.                 */
  549.                if(*cShortSessionID == 0x00
  550.                || *cShortSessionID == ' ')
  551.                {
  552.                   LoadString(ghInst, LS_NO_SESSIONID, (LPSTR)message1, sizeof(message1));
  553.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  554.                   MessageBox(NULL,
  555.                              message1,
  556.                              message2,
  557.                              MB_OK);
  558.                   return (TRUE);
  559.                   break;
  560.                }
  561.                /*
  562.                 * Which of radio buttons are checked?
  563.                 */
  564.                if (IsDlgButtonChecked(hDlg, DID_SAVE_AS_PROFILE))
  565.                  fuSaveProfile = (SHORT)PCS_SAVE_AS_PROFILE;
  566.                else if (IsDlgButtonChecked(hDlg, DID_SAVE_ON_EXIT))
  567.                  fuSaveProfile = (SHORT)PCS_SAVE_ON_EXIT;
  568.                else if (IsDlgButtonChecked(hDlg, DID_NOSAVE_ON_EXIT))
  569.                  fuSaveProfile = (SHORT)PCS_NOSAVE_ON_EXIT;
  570.  
  571.                /*
  572.                 * Session is stoped.
  573.                 */
  574.                brc = pcsStopSession(*cShortSessionID,
  575.                                     fuSaveProfile);
  576.                if(brc == FALSE)          /*  pcsStopSession is failed.    */
  577.                {
  578.                   LoadString(ghInst, LS_SESSION_CANNOTSTOP, (LPSTR)message, sizeof(message));
  579.  
  580.                   strcpy(rc, "FALSE");
  581.                }
  582.                else                      /* pcsStopSession is succeed.    */
  583.                {
  584.                   strcpy(message, "Session ");
  585.  
  586.                   strcat(message, cShortSessionID);
  587.  
  588.                   strcat(message, " stopped");
  589.  
  590.                   strcpy(rc, "TRUE");
  591.                }
  592.                /*
  593.                 * Displays a message box containing an error message or
  594.                 * a successful message.
  595.                 */
  596.                LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  597.                MessageBox(NULL,
  598.                           message,
  599.                           message2,
  600.                           MB_OK);
  601.                GetLocalTime(&DateTime);
  602.  
  603.                /*
  604.                 * Log message is edited.
  605.                 */
  606.                sprintf(message,
  607.                        "%02d:%02d : Stop Session  Session ID = %s, Saving profile option = %d, RC = %s",
  608.                        DateTime.wHour,
  609.                        DateTime.wMinute,
  610.                        cShortSessionID,
  611.                        fuSaveProfile,
  612.                        rc );
  613.  
  614.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  615.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  616.                return (TRUE);
  617.                break;
  618.  
  619.             case IDCANCEL:
  620.                EndDialog(hDlg, TRUE);
  621.                return (TRUE);
  622.                break;
  623.  
  624.             default:
  625.                break;
  626.          }
  627.          break;
  628.    }
  629.    return (FALSE);
  630. } /* End of StopDlgProc */
  631.  
  632. /*******************************************************************************
  633. *                                                                              *
  634. *  Name       : StatusDlgProc                                                  *
  635. *                                                                              *
  636. *  Description: Processes all messages sent to the Query Emulater Status       *
  637. *               dialog.                                                        *
  638. *               This procedure use "pcsQueryEmulatorStatus".                   *
  639. *                                                                              *
  640. *  Concepts : Called for each message sent to the Query Emulater Status        *
  641. *             dialog box.                                                      *
  642. *             A switch statement branches to the routines to be                *
  643. *             performed for each message processed.  Any messages              *
  644. *             not specifically process are passed to the default               *
  645. *             window procedure DefDlgProc().                                   *
  646. *                                                                              *
  647. *******************************************************************************/
  648. LRESULT CALLBACK StatusDlgProc(hDlg, iMessage, wParam, lParam)
  649. HWND     hDlg;
  650. UINT     iMessage;
  651. WPARAM   wParam;
  652. LPARAM   lParam;
  653. {
  654.    CHAR     cShortSessionID[2];          /* Session ID                    */
  655.    ULONG    rc;                          /* Return code                   */
  656.    CHAR     message[332];                /* Message buffer                */
  657.    CHAR     message1[80], message2[80];  /* Message buffer                */
  658.    SYSTEMTIME DateTime;                  /* Time area                     */
  659.  
  660.    switch(iMessage)
  661.    {
  662.       case WM_INITDIALOG:
  663.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  664.          return (TRUE);
  665.  
  666.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  667.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  668.          {
  669.             case IDOK:
  670.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  671.  
  672.                if(*cShortSessionID == 0x00
  673.                || *cShortSessionID == ' ')
  674.                {
  675.                   LoadString(ghInst, LS_NO_SESSIONID, (LPSTR)message1, sizeof(message1));
  676.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  677.                   MessageBox(NULL,
  678.                              message1,
  679.                              message2,
  680.                              MB_OK);
  681.                   return (TRUE);
  682.                   break;
  683.                }
  684.                /*
  685.                 * pcsQueryEmulatorStatus queries status of
  686.                 * 'cShortSessionID' session.
  687.                 */
  688.  
  689.                rc = pcsQueryEmulatorStatus(*cShortSessionID);
  690.  
  691.                /*
  692.                 * Displays a status of 'cShortSessionID' session.
  693.                 */
  694.                                          /* Active or Inactive            */
  695.                if((rc & PCS_SESSION_STARTED) != 0)
  696.                {
  697.                                          /* Set text "Active".            */
  698.                   SetDlgItemText(hDlg,
  699.                                  DID_STARTED,
  700.                                  "Active" );
  701.  
  702.                                          /* Connected or Disconnected     */
  703.                   if((rc & PCS_SESSION_ONLINE) != 0)
  704.                                          /* Set text "Connected".         */
  705.                       SetDlgItemText(hDlg,
  706.                                      DID_ONLINE,
  707.                                      "Connected");
  708.                   else
  709.                                          /* Set text "Disconnected".      */
  710.                      SetDlgItemText(hDlg,
  711.                                     DID_ONLINE,
  712.                                     "Disconnected");
  713.  
  714.                                          /* Enabled or Disabled           */
  715.                   if((rc & PCS_SESSION_API_ENABLED) != 0)
  716.                                          /* Set text "Enabled".           */
  717.                      SetDlgItemText(hDlg,
  718.                                     DID_API_ENABLED,
  719.                                     "Enabled");
  720.                   else
  721.                                          /* Set text "Disabled".          */
  722.                      SetDlgItemText(hDlg,
  723.                                     DID_API_ENABLED,
  724.                                     "Disabled");
  725.                }
  726.                else
  727.                {
  728.                                          /* Set text "Inactive".          */
  729.                   SetDlgItemText(hDlg,
  730.                                  DID_STARTED,
  731.                                  "Inactive");
  732.  
  733.                                          /* Clear text field.             */
  734.                   SetDlgItemText(hDlg,
  735.                                  DID_ONLINE,
  736.                                  "");
  737.  
  738.                                          /* Clear text field.             */
  739.                   SetDlgItemText(hDlg,
  740.                                  DID_API_ENABLED,
  741.                                  "");
  742.                }
  743.  
  744.                GetLocalTime(&DateTime);
  745.  
  746.                /*
  747.                 * Log message is edited.
  748.                 */
  749.                sprintf(message,
  750.                        "%02d:%02d : Query Emulator Status  Session ID = %s, RC = %d",
  751.                        DateTime.wHour,
  752.                        DateTime.wMinute,
  753.                        cShortSessionID,
  754.                        rc);
  755.  
  756.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  757.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  758.                return (TRUE);
  759.                break;
  760.  
  761.             case IDCANCEL:
  762.                EndDialog(hDlg, TRUE);
  763.                return (TRUE);
  764.                break;
  765.  
  766.             default:
  767.                break;
  768.          }
  769.          break;
  770.    }
  771.    return (FALSE);
  772. } /* End of cShortSessionID */
  773.  
  774. /*******************************************************************************
  775. *                                                                              *
  776. *  Name       : ProfileDlgProc                                                 *
  777. *                                                                              *
  778. *  Description: Processes all messages sent to the Query Workstation           *
  779. *               Profile dialog.                                                *
  780. *               This procedure use "pcsQueryWorkstationProfile".               *
  781. *                                                                              *
  782. *  Concepts : Called for each message sent to the Query Workstation            *
  783. *             Profile dialog box.                                              *
  784. *             A switch statement branches to the routines to be                *
  785. *             performed for each message processed.  Any messages              *
  786. *             not specifically process are passed to the default               *
  787. *             window procedure DefDlgProc().                                   *
  788. *                                                                              *
  789. *******************************************************************************/
  790. LRESULT CALLBACK ProfileDlgProc(hDlg, iMessage, wParam, lParam)
  791. HWND     hDlg;
  792. UINT     iMessage;
  793. WPARAM   wParam;
  794. LPARAM   lParam;
  795. {
  796.    CHAR     lpProfile[MAXPATHLEN];       /* Profile name                  */
  797.    CHAR     cShortSessionID[2];          /* Session ID                    */
  798.    BOOL     brc;                         /* Return code                   */
  799.    CHAR     rc[6];                       /* "TRUE" or "FALSE"             */
  800.    CHAR     message[332];                /* Message buffer                */
  801.    CHAR     message1[80], message2[80];  /* Message buffer                */
  802.    SYSTEMTIME DateTime;                  /* Time area                     */
  803.  
  804.    switch(iMessage)
  805.    {
  806.       case WM_INITDIALOG:
  807.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  808.          return (TRUE);
  809.  
  810.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  811.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  812.          {
  813.             case IDOK:                 /* The 'Start Session' pushbutton*/
  814.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  815.                /*
  816.                 * If cShortSessionID is empty, displays a message box
  817.                 * containing an error message.
  818.                 */
  819.                if(*cShortSessionID == 0x00
  820.                || *cShortSessionID == ' ')
  821.                {
  822.                   LoadString(ghInst, LS_NO_SESSIONID, (LPSTR)message1, sizeof(message1));
  823.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  824.                   MessageBox(NULL,
  825.                              message1,
  826.                              message2,
  827.                              MB_OK);
  828.                   return (TRUE);
  829.                   break;
  830.                }
  831.  
  832.                /*
  833.                 * pcsQueryWorkstationProfile queries profile
  834.                 * of 'cShortSessionID' session.
  835.                 */
  836.                brc = pcsQueryWorkstationProfile(*cShortSessionID,
  837.                                                 (PSZ)lpProfile);
  838.                if(brc == FALSE)
  839.                {
  840.                   /*
  841.                    * Displays a message box containing an error message.
  842.                    */
  843.                   LoadString(ghInst, LS_SESSION_NOTSTARTED, (LPSTR)message1, sizeof(message1));
  844.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  845.                   MessageBox(NULL,
  846.                              message1,
  847.                              message2,
  848.                              MB_OK);
  849.  
  850.                   strcpy(rc, "FALSE");
  851.  
  852.                                          /* Clear entry field.            */
  853.                   SetDlgItemText(hDlg, DID_PRONAME, "");
  854.  
  855.                }
  856.                else
  857.                {
  858.                   strcpy(rc, "TRUE");
  859.  
  860.                   /*
  861.                    * Displays the profile's name of session 'cShortSessionID'.
  862.                    */
  863.                   SetDlgItemText(hDlg,
  864.                                  DID_PRONAME,
  865.                                  lpProfile);
  866.                }
  867.  
  868.                GetLocalTime(&DateTime);
  869.                /*
  870.                 * Log message is edited.
  871.                 */
  872.                sprintf(message,
  873.                        "%02d:%02d : Query Workstation Profile  Session ID = %s, RC = %s",
  874.                        DateTime.wHour,
  875.                        DateTime.wMinute,
  876.                        cShortSessionID,
  877.                        rc);
  878.  
  879.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  880.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  881.                return (TRUE);
  882.                break;
  883.  
  884.             case IDCANCEL:            /* The 'Exit' pushbutton          */
  885.                EndDialog(hDlg, TRUE);
  886.                return (TRUE);
  887.                break;
  888.  
  889.             default:
  890.                break;
  891.          }
  892.          break;
  893.    }
  894.    return (FALSE);
  895. } /* End of ProfileDlgProc */
  896.  
  897. /*******************************************************************************
  898. *                                                                              *
  899. *  Name       : ConnectDlgProc                                                 *
  900. *                                                                              *
  901. *  Description: Processes all messages sent to the Connect Session dialog.     *
  902. *               This procedure use "pcsConnectSession".                        *
  903. *                                                                              *
  904. *  Concepts : Called for each message sent to the Connect Session dialog box.  *
  905. *             A switch statement branches to the routines to be                *
  906. *             performed for each message processed.  Any messages              *
  907. *             not specifically process are passed to the default               *
  908. *             window procedure DefDlgProc().                                   *
  909. *                                                                              *
  910. *******************************************************************************/
  911. LRESULT CALLBACK ConnectDlgProc(hDlg, iMessage, wParam, lParam)
  912. HWND     hDlg;
  913. UINT     iMessage;
  914. WPARAM   wParam;
  915. LPARAM   lParam;
  916. {
  917.    CHAR     cShortSessionID[2];          /* Session ID                    */
  918.    BOOL     brc;                         /* Return code                   */
  919.    CHAR     rc[6];                       /* "TRUE" or "FALSE"             */
  920.    CHAR     message[332];                /* Message buffer                */
  921.    CHAR     message1[80], message2[80];  /* Message buffer                */
  922.    SYSTEMTIME DateTime;                  /* Time area                     */
  923.  
  924.    switch(iMessage)
  925.    {
  926.       case WM_INITDIALOG:
  927.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  928.          return (TRUE);
  929.  
  930.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  931.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  932.          {
  933.             case IDOK:
  934.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  935.                /*
  936.                 * If cShortSessionID is empty, displays a message box
  937.                 * containing an error message.
  938.                 */
  939.                if(*cShortSessionID == 0x00
  940.                || *cShortSessionID == ' ')
  941.                {
  942.                   LoadString(ghInst, LS_NO_SESSIONID, (LPSTR)message1, sizeof(message1));
  943.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  944.                   MessageBox(NULL,
  945.                              message1,
  946.                              message2,
  947.                              MB_OK);
  948.                   return (TRUE);
  949.                   break;
  950.                }
  951.  
  952.                /*
  953.                 * Session is stoped.
  954.                 */
  955.                brc = pcsConnectSession(*cShortSessionID);
  956.                if(brc == FALSE)          /*  pcsConnectSession is failed. */
  957.                {
  958.                   LoadString(ghInst, LS_SESSION_NOTSTARTED, (LPSTR)message, sizeof(message));
  959.  
  960.                   strcpy(rc, "FALSE");
  961.                }
  962.                else                      /* pcsConnectSession is succeed.    */
  963.                {
  964.                   strcpy(message, "Session ");
  965.  
  966.                   strcat(message, cShortSessionID);
  967.  
  968.                   strcat(message, " connected");
  969.  
  970.                   strcpy(rc, "TRUE");
  971.                }
  972.                /*
  973.                 * Displays a message box containing an error message or
  974.                 * a successful message.
  975.                 */
  976.                LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  977.                MessageBox(NULL,
  978.                           message,
  979.                           message2,
  980.                           MB_OK);
  981.                GetLocalTime(&DateTime);
  982.  
  983.                /*
  984.                 * Log message is edited.
  985.                 */
  986.                sprintf(message,
  987.                        "%02d:%02d : Connect Session  Session ID = %s, RC = %s",
  988.                        DateTime.wHour,
  989.                        DateTime.wMinute,
  990.                        cShortSessionID,
  991.                        rc );
  992.  
  993.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  994.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  995.                return (TRUE);
  996.                break;
  997.  
  998.             case IDCANCEL:
  999.                EndDialog(hDlg, TRUE);
  1000.                return (TRUE);
  1001.                break;
  1002.  
  1003.             default:
  1004.                break;
  1005.          }
  1006.          break;
  1007.    }
  1008.    return (FALSE);
  1009. } /* End of ConnectDlgProc */
  1010.  
  1011. /*******************************************************************************
  1012. *                                                                              *
  1013. *  Name       : DisconnectDlgProc                                              *
  1014. *                                                                              *
  1015. *  Description: Processes all messages sent to the Disconnect Session dialog.  *
  1016. *               This procedure use "pcsConnectSession".                        *
  1017. *                                                                              *
  1018. *  Concepts : Called for each message sent to the Disconnect Session dialog box*
  1019. *             A switch statement branches to the routines to be                *
  1020. *             performed for each message processed.  Any messages              *
  1021. *             not specifically process are passed to the default               *
  1022. *             window procedure DefDlgProc().                                   *
  1023. *                                                                              *
  1024. *******************************************************************************/
  1025. LRESULT CALLBACK DisconnectDlgProc(hDlg, iMessage, wParam, lParam)
  1026. HWND     hDlg;
  1027. UINT     iMessage;
  1028. WPARAM   wParam;
  1029. LPARAM   lParam;
  1030. {
  1031.    CHAR     cShortSessionID[2];          /* Session ID                    */
  1032.    BOOL     brc;                         /* Return code                   */
  1033.    CHAR     rc[6];                       /* "TRUE" or "FALSE"             */
  1034.    CHAR     message[332];                /* Message buffer                */
  1035.    CHAR     message1[80], message2[80];  /* Message buffer                */
  1036.    SYSTEMTIME DateTime;                  /* Time area                     */
  1037.  
  1038.    switch(iMessage)
  1039.    {
  1040.       case WM_INITDIALOG:
  1041.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  1042.          return (TRUE);
  1043.  
  1044.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  1045.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  1046.          {
  1047.             case IDOK:
  1048.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  1049.                /*
  1050.                 * If cShortSessionID is empty, displays a message box
  1051.                 * containing an error message.
  1052.                 */
  1053.                if(*cShortSessionID == 0x00
  1054.                || *cShortSessionID == ' ')
  1055.                {
  1056.                   LoadString(ghInst, LS_NO_SESSIONID, (LPSTR)message1, sizeof(message1));
  1057.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  1058.                   MessageBox(NULL,
  1059.                              message1,
  1060.                              message2,
  1061.                              MB_OK);
  1062.                   return (TRUE);
  1063.                   break;
  1064.                }
  1065.  
  1066.                /*
  1067.                 * Session is stoped.
  1068.                 */
  1069.                brc = pcsDisconnectSession(*cShortSessionID);
  1070.                if(brc == FALSE)          /*  pcsConnectSession is failed. */
  1071.                {
  1072.                   LoadString(ghInst, LS_SESSION_NOTSTARTED, (LPSTR)message, sizeof(message));
  1073.  
  1074.                   strcpy(rc, "FALSE");
  1075.                }
  1076.                else                      /* pcsConnectSession is succeed.    */
  1077.                {
  1078.                   strcpy(message, "Session ");
  1079.  
  1080.                   strcat(message, cShortSessionID);
  1081.  
  1082.                   strcat(message, " disconnected");
  1083.  
  1084.                   strcpy(rc, "TRUE");
  1085.                }
  1086.                /*
  1087.                 * Displays a message box containing an error message or
  1088.                 * a successful message.
  1089.                 */
  1090.                LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  1091.                MessageBox(NULL,
  1092.                           message,
  1093.                           message2,
  1094.                           MB_OK);
  1095.                GetLocalTime(&DateTime);
  1096.  
  1097.                /*
  1098.                 * Log message is edited.
  1099.                 */
  1100.                sprintf(message,
  1101.                        "%02d:%02d : Disconnect Session  Session ID = %s, RC = %s",
  1102.                        DateTime.wHour,
  1103.                        DateTime.wMinute,
  1104.                        cShortSessionID,
  1105.                        rc );
  1106.  
  1107.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  1108.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  1109.                return (TRUE);
  1110.                break;
  1111.  
  1112.             case IDCANCEL:
  1113.                EndDialog(hDlg, TRUE);
  1114.                return (TRUE);
  1115.                break;
  1116.  
  1117.             default:
  1118.                break;
  1119.          }
  1120.          break;
  1121.    }
  1122.    return (FALSE);
  1123. } /* End of DisconnectDlgProc */
  1124.  
  1125. /*******************************************************************************
  1126. *                                                                              *
  1127. *  Name       : SetLinkTimeoutDlgProc                                          *
  1128. *                                                                              *
  1129. *  Description: Processes all messages sent to the Set Link Timeout dialog.    *
  1130. *               This procedure use "pcsSetLinkTimeout".                        *
  1131. *                                                                              *
  1132. *  Concepts : Called for each message sent to the Set Link Timeout             *
  1133. *             dialog box.                                                      *
  1134. *             A switch statement branches to the routines to be                *
  1135. *             performed for each message processed.  Any messages              *
  1136. *             not specifically process are passed to the default               *
  1137. *             window procedure DefDlgProc().                                   *
  1138. *                                                                              *
  1139. *******************************************************************************/
  1140. LRESULT CALLBACK SetLinkTimeoutDlgProc(hDlg, iMessage, wParam, lParam)
  1141. HWND     hDlg;
  1142. UINT     iMessage;
  1143. WPARAM   wParam;
  1144. LPARAM   lParam;
  1145. {
  1146.    CHAR     cTimeoutValue[3];            /* Timeout value                 */
  1147.    CHAR     cShortSessionID[2];          /* Session ID                    */
  1148.    WORD     fuTimeoutValue;              /* Timeout value                 */
  1149.    ULONG    rc;                          /* Return code                   */
  1150.    CHAR     message[332];                /* Message buffer                */
  1151.    CHAR     message1[80], message2[80];  /* Message buffer                */
  1152.    SYSTEMTIME DateTime;                  /* Time area                     */
  1153.  
  1154.    switch(iMessage)
  1155.    {
  1156.       case WM_INITDIALOG:
  1157.          SendDlgItemMessage(hDlg, DID_SESID, EM_LIMITTEXT, 1, 0L);
  1158.          SendDlgItemMessage(hDlg, DID_TIMEOUTVALUE, EM_LIMITTEXT, 2, 0L);
  1159.          return (TRUE);
  1160.  
  1161.       case WM_COMMAND:                   /* Posted by pushbuttons         */
  1162.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  1163.          {
  1164.             case IDOK:                /* The 'Set Link Timeout' pushbutton*/
  1165.                GetDlgItemText(hDlg, DID_SESID, cShortSessionID, sizeof(cShortSessionID));
  1166.                /*
  1167.                 * If cShortSessionID is empty, displays a message box
  1168.                 * containing an error message.
  1169.                 */
  1170.                if(*cShortSessionID == 0x00
  1171.                || *cShortSessionID == ' ')
  1172.                {
  1173.                   LoadString(ghInst, LS_NO_SESSIONID, (LPSTR)message1, sizeof(message1));
  1174.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  1175.                   MessageBox(NULL,
  1176.                              message1,
  1177.                              message2,
  1178.                              MB_OK);
  1179.                   return (TRUE);
  1180.                   break;
  1181.                }
  1182.  
  1183.                GetDlgItemText(hDlg, DID_TIMEOUTVALUE, cTimeoutValue, sizeof(cTimeoutValue));
  1184.  
  1185.                /*
  1186.                 * Strips off leading and trailing blanks in cTimeoutValue
  1187.                 */ 
  1188.                if(cTimeoutValue[0] == ' ')
  1189.                {
  1190.                   cTimeoutValue[0] = cTimeoutValue[1];
  1191.                   cTimeoutValue[1] = 0x00;
  1192.                }
  1193.                if(cTimeoutValue[0] != 0x00
  1194.                && cTimeoutValue[1] == ' ')
  1195.                {
  1196.                   cTimeoutValue[1] = 0x00;
  1197.                } 
  1198.  
  1199.                /*
  1200.                 * If cTimeoutValue is empty, displays a message box
  1201.                 * containing an error message.
  1202.                 */
  1203.                if(*cTimeoutValue == 0x00)
  1204.                {
  1205.                   LoadString(ghInst, LS_NO_TIMEOUTVALUE, (LPSTR)message1, sizeof(message1));
  1206.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  1207.                   MessageBox(NULL,
  1208.                              message1,
  1209.                              message2,
  1210.                              MB_OK);
  1211.                   return (TRUE);
  1212.                   break;
  1213.                }
  1214.  
  1215.                /*
  1216.                 * If cTimeoutValue is invalid, displays a message box
  1217.                 * containing an error message.
  1218.                 */
  1219.                if(strspn(cTimeoutValue, "0123456789") != strlen(cTimeoutValue))
  1220.                {
  1221.                   LoadString(ghInst, LS_INVALID_TIMEOUTVALUE, (LPSTR)message1, sizeof(message1));
  1222.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  1223.                   MessageBox(NULL,
  1224.                              message1,
  1225.                              message2,
  1226.                              MB_OK);
  1227.                   return (TRUE);
  1228.                   break;
  1229.                }
  1230.  
  1231.                /*
  1232.                 * pcsSetLinkTimeout sets the link timeout
  1233.                 * of 'cShortSessionID' session.
  1234.                 */
  1235.                fuTimeoutValue = atoi(cTimeoutValue);
  1236.                rc = pcsSetLinkTimeout(*cShortSessionID,
  1237.                                       fuTimeoutValue);
  1238.                if(rc != 0)
  1239.                {
  1240.                   /*
  1241.                    * Displays a message box containing an error message.
  1242.                    */
  1243.                   LoadString(ghInst, LS_TIMEOUT_ERROR, (LPSTR)message1, sizeof(message1));
  1244.                   LoadString(ghInst, LS_SAMPLE_PROGRAM, (LPSTR)message2, sizeof(message2));
  1245.                   MessageBox(NULL,
  1246.                              message1,
  1247.                              message2,
  1248.                              MB_OK);
  1249.  
  1250.                                          /* Clear entry field.            */
  1251.                   SetDlgItemText(hDlg, DID_TIMEOUTVALUE, "");
  1252.  
  1253.                }
  1254.  
  1255.                GetLocalTime(&DateTime);
  1256.                /*
  1257.                 * Log message is edited.
  1258.                 */
  1259.                sprintf(message,
  1260.                        "%02d:%02d : Set Link Timeout  Session ID = %s, RC = %d",
  1261.                        DateTime.wHour,
  1262.                        DateTime.wMinute,
  1263.                        cShortSessionID,
  1264.                        rc);
  1265.  
  1266.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_SETHORIZONTALEXTENT, (WPARAM)LISTBOX_MAXWIDTH, 0L);
  1267.                SendDlgItemMessage(ghMainWnd, IDD_LIST, LB_ADDSTRING, 0, (LPARAM)message);
  1268.                return (TRUE);
  1269.                break;
  1270.  
  1271.             case IDCANCEL:            /* The 'Exit' pushbutton          */
  1272.                EndDialog(hDlg, TRUE);
  1273.                return (TRUE);
  1274.                break;
  1275.  
  1276.             default:
  1277.                break;
  1278.          }
  1279.          break;
  1280.    }
  1281.    return (FALSE);
  1282. } /* End of SetLinkTimeoutDlgProc */
  1283.  
  1284.