home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / listfile / listfile.c < prev    next >
Text File  |  2002-02-28  |  16KB  |  444 lines

  1. //******************************************************************************
  2. //
  3. //  PROGRAM: listfile.c
  4. //
  5. //  PURPOSE: Provides, via DDE, a list of host files to the PC/3270 receive
  6. //           files function.
  7. //
  8. //  1.  Each instance of this application corresponds to one session
  9. //      instance. This allows load button enablement on a session by session
  10. //      basis.
  11. //
  12. //  2.  Invocation:  LISTFILE  /x   where "x" is the alpha session ID. A .. Z
  13. //
  14. //         Copyright (c) 1991, 1996 IBM Corporation. All rights reserved.
  15. //
  16. //         Provided on an "AS IS" basis, no warranty expressed or implied.
  17. //
  18. //******************************************************************************
  19.  
  20. #include <windows.h>                // required for all Windows applications
  21.  
  22. #include <string.h>                 // String functions
  23. #include <ctype.h>                  // toupper function
  24.  
  25. #include "listfile.h"               // specific to this program
  26.  
  27. #define MAIN
  28. #include "listdata.h"               // Global Data
  29.  
  30. //******************************************************************************
  31. //
  32. // Local Function Definitions
  33. //
  34. //******************************************************************************
  35.  
  36. BOOL NEAR GetSessionID( LPSTR );
  37.  
  38. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  39. //
  40. //  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  41. //
  42. //  PURPOSE: calls initialization functions, and processes the application
  43. //           message loop.
  44. //
  45. //  COMMENTS:
  46. //
  47. //      Windows recognizes this function by name as the initial entry point
  48. //      for the program.  This function calls the application initialization
  49. //      routine, if no other instance of the program is running, and always
  50. //      calls the instance initialization routine.  It then executes a message
  51. //      retrieval and dispatch loop that is the top-level control structure
  52. //      for the remainder of execution.  The loop is terminated when a WM_QUIT
  53. //      message is received, at which time this function exits the application
  54. //      instance by returning the value passed by PostQuitMessage().
  55. //
  56. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  57.  
  58. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpzCmdLine, int nCmdShow)
  59. {
  60.   MSG msg;
  61.  
  62.   if ( !GetSessionID(lpzCmdLine) )             // Get Session ID A .. H
  63.   {                                            //
  64.     LoadString(hInstance, LS_COMMAND_LINE_ERROR1, zMsgBuffer, sizeof(zMsgBuffer));
  65.     MessageBox(NULL, (LPSTR) zMsgBuffer, (LPSTR) ListFileClassName, MB_OK | MB_ICONQUESTION );
  66.     return( FALSE );                           //
  67.   }                                            //
  68.                                                //
  69.   if (!hPrevInstance)                          //
  70.   {                                            //
  71.     if (!RegisterApplicationClass(hInstance))  //
  72.     {                                          //
  73.       return( FALSE );                         //
  74.     }                                          //
  75.   }                                            //
  76.                                                //
  77.   if (!InitInstance(hInstance, nCmdShow))      //
  78.   {                                            //
  79.     return( FALSE );                           //
  80.   }                                            //
  81.                                                //
  82.   if ( !InitDDE() )                            //
  83.   {                                            //
  84.     return( FALSE );                           //
  85.   }                                            //
  86.                                                //
  87.   // ** Dispatch messages until a WM_QUIT message is received.
  88.                                                //
  89.   while( GetMessage((LPMSG)&msg, (HWND)NULL, (UINT)NULL, (UINT)NULL) )
  90.   {                                            //
  91.     TranslateMessage(&msg);                    // Translates virtual key codes
  92.     DispatchMessage(&msg);                     // Dispatches message to window
  93.   }                                            //
  94.                                                // Return the PostQuitMessage()
  95.   return (msg.wParam);                         // Value
  96. }                                              //
  97.                                                //
  98.                                                //
  99. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  100. //
  101. //  FUNCTION: RegisterApplicationClass(HANDLE)
  102. //
  103. //  PURPOSE: Initializes window data and registers window class
  104. //
  105. //  This function is called at initialization time only if no other
  106. //  instances of the application are running.  This function performs
  107. //  initialization tasks that can be done once for any number of running
  108. //  instances.
  109. //
  110. //  In this case, we initialize a window class by filling out a data
  111. //  structure of type WNDCLASS and calling the Windows RegisterClass()
  112. //  function.  Since all instances of this application use the same window
  113. //  class, we only need to do this when the first instance is initialized.
  114. //
  115. //
  116. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  117.  
  118. BOOL RegisterApplicationClass( HANDLE hInstance )
  119. {
  120.   WNDCLASS  wc;
  121.  
  122.   // Fill in window class structure with parameters that describe the
  123.   // main window.
  124.  
  125.   wc.hInstance     = hInstance;
  126.   wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(LISTICON));
  127.   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  128.   wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  129.   wc.cbClsExtra    = 0;
  130.   wc.cbWndExtra    = 0;
  131.   wc.style         = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  132.   wc.lpszMenuName  = MAKEINTRESOURCE(LISTMENU);
  133.   wc.lpszClassName = ListFileClassName;
  134.   wc.lpfnWndProc   = ListFileWndProc;
  135.  
  136.   // Register the window class and return FALSE if the call fails
  137.  
  138.   if( !RegisterClass(&wc) )
  139.   {
  140.     return(FALSE);
  141.   }
  142.  
  143.   // Fill in window class structure with parameters that describe the
  144.   // hidden window used to converse with session to obtain the file name
  145.   // list.
  146.  
  147.   wc.hInstance     = hInstance;              // Hidden window
  148.   wc.hIcon         = NULL;                   // does not need much ...
  149.   wc.hCursor       = NULL;
  150.   wc.hbrBackground = NULL;
  151.   wc.cbClsExtra    = 0;
  152.   wc.cbWndExtra    = 0;
  153.   wc.style         = 0;
  154.   wc.lpszMenuName  = NULL;
  155.   wc.lpszClassName = FileListClassName;
  156.   wc.lpfnWndProc   = FileListWndProc;
  157.  
  158.   // Register the window class and return FALSE if the call fails
  159.  
  160.   return( RegisterClass(&wc) );
  161. }
  162.  
  163. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  164. //
  165. //  FUNCTION:  InitInstance(HANDLE, int)
  166. //
  167. //  PURPOSE:  Saves instance handle and creates main window
  168. //
  169. //  This function is called at initialization time for every instance of
  170. //  this application.  This function performs initialization tasks that
  171. //  are unique to this instance.
  172. //
  173. //  In this case, we save the instance handle in a static variable and
  174. //  create and display the main program window.
  175. //
  176. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  177.  
  178. BOOL InitInstance(HANDLE hInstance, int iCmdShow)
  179. {
  180.   HWND hWnd;
  181.   int iX, iY;
  182.  
  183.   // Save the instance handle in static variable, which will be used in
  184.   // many subsequence calls from this application to Windows.
  185.  
  186.   hGlobalInst = hInstance;
  187.  
  188.   // Create a main window for this application instance.
  189.  
  190.   iX = GetSystemMetrics( SM_CXSCREEN );
  191.   iY = GetSystemMetrics( SM_CYSCREEN );
  192.  
  193.   LoadString(hInstance, LS_TITLE_TEXT, zMsgBuffer, sizeof(zMsgBuffer));
  194.  
  195.   strcat(zMsgBuffer, zCmdLineSessionID);
  196.  
  197.   hWnd = CreateWindow(
  198.       ListFileClassName,               // See RegisterClass() call.
  199.       zMsgBuffer,                      // Text for window title bar.
  200.       WS_OVERLAPPEDWINDOW,             // Window style.
  201.       (iX / 4),                        // Horizontal position.
  202.       (iY / 4),                        // Vertical position.
  203.       (iX / 2),                        // Width
  204.       (iY / 2),                        // Height
  205.       NULL,                            // Overlapped windows have no parent.
  206.       NULL,                            // Use the window class menu.
  207.       hInstance,                       // This instance owns this window.
  208.       NULL                             // Pointer not needed.
  209.   );
  210.  
  211.   // If window could not be created, return FALSE
  212.  
  213.   if ( hWnd == NULL )
  214.   {
  215.     return(FALSE);
  216.   }
  217.  
  218.   hGlobalWnd = hWnd;                   // Save Window Handle
  219.  
  220.   // Make the window visible; update its client area; and return "success"
  221.  
  222.   ShowWindow(hWnd, SW_MINIMIZE);       // Show the window
  223.   UpdateWindow(hWnd);                  // Sends WM_PAINT message
  224.                                        //
  225.   // Create the Hidden window          //
  226.                                        //
  227.   hWndHidden = CreateWindow(           //
  228.       FileListClassName,               // See RegisterClass() call.
  229.       "",                              // Text for window title bar.
  230.       WS_OVERLAPPEDWINDOW,             // Window style.
  231.       (iX / 4),                        // Horizontal position.
  232.       (iY / 4),                        // Vertical position.
  233.       (iX / 2),                        // Width
  234.       (iY / 2),                        // Height
  235.       NULL,                            // Overlapped windows have no parent.
  236.       NULL,                            // Use the window class menu.
  237.       hInstance,                       // This instance owns this window.
  238.       NULL                             // Pointer not needed.
  239.   );                                   //
  240.                                        //
  241.   // If window could not be created, return FALSE
  242.                                        //
  243.   if ( hWndHidden == NULL )            //
  244.   {                                    //
  245.     return(FALSE);                     //
  246.   }                                    //
  247.                                        //
  248.   return(TRUE);                        // Return success
  249. }
  250.  
  251. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  252. //
  253. //  FUNCTION: ListFileWndProc(HWND, unsigned, WORD, LONG)
  254. //
  255. //  PURPOSE:  Main Window Procedure for LISTFILE application
  256. //
  257. //  This procedure handles most all of the message traffic for the
  258. //  application. When this procedure receive a WM_QUIT message the application
  259. //  will terminate by exiting the while message loop in the function WinMain.
  260. //
  261. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  262.  
  263. long WINAPI ListFileWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  264. {
  265.   FARPROC      lpProcModalDialog;
  266.   PAINTSTRUCT  ps;
  267.  
  268.   switch (message)
  269.   {
  270.     case WM_COMMAND:
  271.       switch( wParam )
  272.       {
  273.         case ID_ABOUT:
  274.           lpProcModalDialog = MakeProcInstance(About, hGlobalInst);
  275.           DialogBox(hGlobalInst, MAKEINTRESOURCE(ABOUTBOX), hWnd, lpProcModalDialog);
  276.           FreeProcInstance(lpProcModalDialog);
  277.           break;
  278.  
  279.         default:
  280.           return( DefWindowProc(hWnd, message, wParam, lParam) );
  281.           break;
  282.       }
  283.       break;
  284.  
  285.     case WM_PAINT:   // Paint a Message in the client area
  286.       BeginPaint(hWnd, (LPPAINTSTRUCT) &ps );
  287.       strcpy(zMsgBuffer, "ListFile Sample Application");
  288.       TextOut(ps.hdc, 10, 100, (LPSTR) zMsgBuffer, strlen(zMsgBuffer) );
  289.       strcpy(zMsgBuffer, "Copyright (c) 1991, 1996 IBM Corporation");
  290.       TextOut(ps.hdc, 10, 120, (LPSTR) zMsgBuffer, strlen(zMsgBuffer) );
  291.       strcpy(zMsgBuffer, "                    All rights reserved.");
  292.       TextOut(ps.hdc, 10, 140, (LPSTR) zMsgBuffer, strlen(zMsgBuffer) );
  293.       EndPaint(hWnd, (LPPAINTSTRUCT) &ps );
  294.       break;
  295.  
  296.     case WM_DESTROY:                  // Destroy the Window
  297.       Terminate( CONVERSATIONS );     // Terminate DDE conversations
  298.       PostQuitMessage(0);             //
  299.       break;                          //
  300.  
  301.     //** ** ** ** ** ** ** ** ** ** ** ** ** **
  302.     //
  303.     //  DDE Messages .....
  304.     //
  305.     //** ** ** ** ** ** ** ** ** ** ** ** ** **
  306.  
  307.     case WM_DDE_INITIATE:
  308.       ListDDEInitiate(hWnd, message, wParam, lParam);
  309.       break;
  310.  
  311.     case WM_DDE_POKE:
  312.       ListDDEPoke(hWnd, message, wParam, lParam);
  313.       break;
  314.  
  315.     case WM_DDE_REQUEST:
  316.       ListDDERequest(hWnd, message, wParam, lParam);
  317.       break;
  318.  
  319.     case WM_DDE_TERMINATE:
  320.       ListDDETerminate(hWnd, message, wParam, lParam);
  321.       break;
  322.  
  323.     default:                          // Pass on all unprocessed messages
  324.       return( DefWindowProc(hWnd, message, wParam, lParam) );
  325.       break;
  326.   }
  327.   return( FALSE );
  328. }
  329.  
  330. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  331. //
  332. //  FUNCTION: FileListWndProc(HWND, unsigned, WORD, LONG)
  333. //
  334. //  PURPOSE:  Window Procedure for the LISTFILE to Session DDE conversation
  335. //
  336. //  This window is used to manage the DDE conversation between LISTFILE
  337. //  and the PC/3270 session where the CMS LISTFILE command is issued and the
  338. //  resulting host file list is obtained.
  339. //
  340. //**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT**BOX-COMMENT
  341.  
  342. long WINAPI FileListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  343. {
  344.   switch (message)
  345.   {
  346.     // ** ** ** ** ** ** ** ** ** ** **
  347.     //
  348.     //  DDE Messages .....
  349.     //
  350.     // ** ** ** ** ** ** ** ** ** ** **
  351.  
  352.     case WM_DDE_ACK:
  353.       FileDDEAck(hWnd, message, wParam, lParam);
  354.       break;
  355.  
  356.     case WM_DDE_DATA:
  357.       FileDDEData(hWnd, message, wParam, lParam);
  358.       break;
  359.  
  360.     case WM_DDE_TERMINATE:
  361.       FileDDETerminate(hWnd, message, wParam, lParam);
  362.       break;
  363.  
  364.     default:
  365.       return( DefWindowProc(hWnd, message, wParam, lParam) );
  366.       break;
  367.   }
  368.   return( FALSE );
  369. }
  370.  
  371. //******************************************************************************
  372. //
  373. //  FUNCTION: About(HWND, unsigned, WORD, LONG)
  374. //
  375. //  PURPOSE:  Dialog procedure for the "About" dialog box
  376. //
  377. //  COMMENTS:
  378. //
  379. //      No initialization is needed for this particular dialog box, but TRUE
  380. //      must be returned to Windows.
  381. //
  382. //      Wait for user to click on "Ok" button, then close the dialog box.
  383. //
  384. //******************************************************************************
  385.  
  386. BOOL WINAPI About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  387. {
  388.   switch( message )                    // case on the message ID
  389.   {                                    //
  390.     case WM_INITDIALOG:                // Init dialog
  391.       return(TRUE);                    //
  392.       break;                           //
  393.                                        //
  394.     case WM_COMMAND:                   //
  395.       switch( wParam )                 //
  396.       {                                //
  397.         case IDOK:                     //
  398.         case IDCANCEL:                 //
  399.           EndDialog(hDlg, TRUE);       //
  400.           return(TRUE);                //
  401.           break;                       //
  402.                                        //
  403.         default:                       //
  404.           break;                       //
  405.       }                                //
  406.       break;                           //
  407.   }                                    //
  408.   return(FALSE);                       //
  409. }
  410.  
  411. //******************************************************************************
  412. //
  413. //  GetSessionID - Parse the short session name from the incoming command
  414. //                 line
  415. //
  416. //  The command line for a session instance will be
  417. //
  418. //     session  /x         x = session ID
  419. //
  420. //******************************************************************************
  421.  
  422. BOOL NEAR GetSessionID( LPSTR lpzCmdLine )
  423. {
  424.   int i, iLength = lstrlen(lpzCmdLine);
  425.  
  426.   for( i = 0; i < iLength; i++ )
  427.   {
  428.     if( *lpzCmdLine++ == '/' )
  429.     {
  430.       uchar cID = *lpzCmdLine;                      //
  431.  
  432.       cID = toupper( cID );
  433.  
  434.       if( 'A' <= cID && cID <= 'Z' )
  435.       {
  436.         zCmdLineSessionID[0] = (uchar) cID;         // setup string
  437.         zCmdLineSessionID[1] = NULL_CHAR;           // Null Terminator
  438.         return(TRUE);
  439.       }
  440.     }
  441.   }
  442.   return(FALSE);
  443. }
  444.