home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / ftp4w26a / samples / c / cw.c next >
Encoding:
C/C++ Source or Header  |  1996-06-10  |  29.3 KB  |  893 lines

  1. /* **************************************************************
  2.  *
  3.  *
  4.  *      C W  
  5.  * 
  6.  *  This program must be compiled with the model 'Large'
  7.  * **************************************************************** */
  8.  
  9.  
  10. /* To be defined if you are using a firewall   */
  11. /* #define FIREWALL_TYPE  FTP4W_FWUSERNOLOGON  */
  12.  
  13.  
  14. #define  STRICT
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <ftp4w.h>
  20. #include "cw.h"
  21.  
  22.  
  23. LPSTR HOST_NAME(void);
  24. LPSTR USER_NAME(void); 
  25. LPSTR PASSWD_NAME(void) ;
  26. LPSTR REM_HOSTNAME(void); 
  27. LPSTR REM_USERNAME(void); 
  28. LPSTR REM_PASSWD(void) ;
  29. LPSTR LOCALFILE_NAME(void) ;
  30. LPSTR REMOTEFILE_NAME(void); 
  31. LPSTR REMOTE_DIR(void) ;
  32. LPSTR NEWREMOTEFILE_NAME(void) ;
  33. LPSTR REMOTE_DIR(void) ;
  34.  
  35.  
  36. #ifdef _WIN32
  37. #  define _export
  38. #endif
  39.  
  40. #define  INIFILE_NAME   "CW.ini" /* name of ini file */
  41. #define  LOG_FILE       "c:\\ftp4w.log"
  42.  
  43.  
  44. /* user's defined messages */
  45. #define  FTP_LOGGED          (WM_USER + 48)
  46. #define  FTP_DIR             (WM_USER + 51)
  47. #define  FTP_DIRLINEPERLINE  (WM_USER + 52)
  48. #define  FTP_FILETRANSFERED  (WM_USER + 54)
  49. #define  CW_VERBOSE          (WM_USER + 57)
  50. #define  CW_BEGIN            (WM_USER + 60)
  51. #define  CW_QUITAPP          (WM_USER + 63)
  52. #define  SHORT_DIR            FALSE       
  53.  
  54. #define  IsOptOn(x) (GetMenuState (GetMenu(hWnd),x,MF_BYCOMMAND)==MF_CHECKED)
  55.  
  56.  
  57.  
  58. #define         szAPPLICATION     "CW_MAIN"
  59.  
  60. HINSTANCE       hInst;             /* hInstance of application     */
  61. HWND            hwnd;              /* hWnd of main window          */
  62. BOOL            FirstEmission;
  63. BOOL            bFileTransfer=FALSE; /* TRUE->data transfer in progress */
  64. char            szQuoteCmd[128];     /* Quote Command */
  65. HFILE           hLogFile=HFILE_ERROR; /* Log File */
  66.  
  67.  
  68. /* in main2 : gauge window */
  69. void SetXmitBytes (LONG lBytes, LONG lTotalBytes);
  70. void DeleteXferWindow (void);
  71. void CreateXferWindow(void);
  72. void SetXferWindowText (LPSTR lpStr);
  73. int nCwRegisterClasses(void);
  74. int nCwUnregisterClasses(void);
  75. /* in main2 : scroller window */
  76. void DoPrintf  (LPSTR szFormat, ...);
  77. void Ecris     (LPSTR szFormat, ...);
  78. void DoAddLine (LPSTR szLine);                           
  79.  
  80. void TpDoWmClose (HWND hWnd);
  81. void TpDoWmPaint (HWND hWnd);
  82. void TpDoWmScroll (HWND hWnd, int nScroll, WPARAM wParam, LPARAM lParam);
  83. void TpDoWmSize (HWND hWnd);
  84. void TpDoWmCreate (HWND hWnd);
  85.  
  86. /* in this file */
  87. BOOL InitApplication (HINSTANCE hInstance);
  88. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow);
  89.  
  90.  
  91. /* different system names */
  92. char *szSyst[] = { "Dos", "Windows", 
  93.                    "Unix", "VMS", "CMS", "OS2", NULL };
  94.  
  95.  
  96.  
  97. long FileSize (LPSTR szFile)
  98. {
  99. HFILE hF;
  100. long FS;
  101.   hF = _lopen (szFile, 0);
  102.   if (hF==HFILE_ERROR)  return 0;
  103.   FS = _llseek (hF, 0, SEEK_END);
  104.   _lclose (hF);
  105. return FS;
  106. } /* FileSize */
  107.  
  108. //*******************************************************************
  109. LRESULT CALLBACK _export CBQuoteDlg (HWND hWndDlg, UINT message,
  110.                                 WPARAM wParam, LPARAM lParam)
  111. {
  112.    if (message==WM_INITDIALOG)
  113.     {  
  114.       SetDlgItemText (hWndDlg, IDC_QUOTECMD, szQuoteCmd);
  115.       SetFocus (GetDlgItem (hWndDlg, IDC_QUOTECMD));
  116.     }
  117.    if (message==WM_COMMAND)
  118.     {
  119.       switch (wParam)
  120.         {
  121.           case IDOK : GetDlgItemText (hWndDlg, IDC_QUOTECMD, 
  122.                                      szQuoteCmd, sizeof szQuoteCmd);
  123.                       EndDialog (hWndDlg, 0);
  124.                       break;
  125.           case IDCANCEL : EndDialog (hWndDlg, -1);
  126.         }
  127.     }
  128. return FALSE;     
  129. } /* CBQuoteDlgf */                    
  130.  
  131.  
  132.  
  133. /* ---------------------- */
  134. /* A function for FtpMGet */
  135. /* ---------------------- */
  136. BOOL CALLBACK MGetShow (LPSTR szRemoteFile, LPSTR szLocalFile, int Rc)
  137. {
  138. char szBuf7 [256];
  139. static int R2;
  140.   if (Rc==FTPERR_ENDOFDATA)
  141.     {
  142.       wsprintf (szBuf7, "Get File <%s> ?", szRemoteFile);
  143.       R2 = MessageBox (NULL, szBuf7, "CW : MGet", MB_YESNOCANCEL);
  144.       return R2==IDYES;
  145.     } 
  146. return R2!=IDCANCEL;
  147. } /* MGetShow */
  148.  
  149.  
  150.  
  151. //*******************************************************************
  152. LRESULT CALLBACK _export MainWndProc (HWND hWnd, UINT message,
  153.                                 WPARAM wParam, LPARAM lParam)
  154. {
  155. static char szBuf[10240];
  156. static char szWinDir[145], szExecCmd [256];
  157. int         Rc;
  158. LPSTR       p, q;
  159. HFILE       hF, hFile;
  160. FARPROC     lpfnQuoteDlg;
  161.  
  162. static HFILE hZ;
  163.  
  164.     switch (message)
  165.     {
  166.        case WM_CREATE :
  167.           hwnd = hWnd;
  168.           TpDoWmCreate (hWnd);
  169.           nCwRegisterClasses();
  170.           PostMessage (hWnd, CW_BEGIN, 0, 0);
  171.           break;  
  172.       case WM_SIZE :
  173.           if (! IsIconic(hWnd))   TpDoWmSize (hWnd);
  174.           break;    
  175.       case WM_VSCROLL:
  176.           TpDoWmScroll (hWnd, SB_VERT, wParam, lParam);
  177.           break;;
  178.        case WM_HSCROLL: 
  179.           TpDoWmScroll (hWnd, SB_HORZ, wParam, lParam);
  180.           break;
  181.       case WM_PAINT :
  182.           if (!IsIconic (hWnd))   TpDoWmPaint (hWnd);
  183.           break;
  184.  
  185.  
  186.           
  187.    /* ---------------------------------------------------------- */
  188.  
  189.        case CW_BEGIN :
  190.  
  191.  DoAddLine ("----------------------------------------------------------------");
  192. #ifdef FRANCAIS
  193.           DoAddLine ("Exemple de Programme utilisant FTP4W.DLL");
  194.           DoAddLine ("Les paramΦtres (nom du distant, nom d'utilisateur,...)");
  195.           DoAddLine ("doivent Ωtre entrΘs dans le fichier CW.INI ");
  196.           DoAddLine ("comme le montre le fichier donnΘ sur la disquette.");
  197.           DoAddLine (" ");
  198.           DoAddLine ("Ce fichier doit Ωtre copiΘ dans le rΘpertoire de Windows");
  199.           DoAddLine ("Pour l'Θditer, utiliser la commande Options/Edit INI");
  200. #else
  201.           DoAddLine ("Sample program For FTP4W.DLL By Ph. Jounin");
  202.           DoAddLine ("Host description and file names must be defined");
  203.           DoAddLine ("in the file CW.INI as shown in the INI file");
  204.           DoAddLine ("provided in the package FTP4W.ZIP.");
  205.           DoAddLine (" ");
  206.           DoAddLine ("Please report bugs and disfonctionments to");
  207.           DoAddLine ("           ark@ifh.sncf.fr");
  208.  #endif /* langues */
  209.  DoAddLine ("----------------------------------------------------------------");
  210.  
  211.           /* add version information */
  212.           Rc = Ftp4wVer (szBuf, sizeof szBuf);
  213.           Ecris ("Version %d.%02X", HIBYTE (Rc), LOBYTE(Rc));
  214.           DoAddLine (szBuf);   
  215.  DoAddLine ("----------------------------------------------------------------");
  216.  
  217.           /* initialize FTP sesson */  
  218.           Rc = FtpInit(hWnd);
  219.           if (Rc!= FTPERR_OK)   
  220.                 Ecris ("FtpInit failed !\nError Code %d", Rc);
  221.           else
  222.              {
  223.                 FtpSetDefaultTimeOut (30);       /* new Timeout : 30 seconds */
  224.                 FtpSetNewDelay(10);
  225.              }
  226.           break;
  227.  
  228.       case WM_CLOSE : 
  229.            DeleteXferWindow ();
  230.            FtpLocalClose ();
  231.            if (FtpRelease()!=FTPERR_OK) 
  232.                { 
  233.                  SetTimer (hWnd, 1, 500l, 0);
  234.                  return FALSE; 
  235.                }
  236.            else
  237.              {  
  238.                 TpDoWmClose(hWnd);
  239.                 DestroyWindow (hWnd);
  240.                 PostQuitMessage (0);
  241.              }
  242.             break;
  243.             
  244.       case WM_TIMER :
  245.            KillTimer (hWnd, 1);
  246.            FtpRelease ();
  247.            TpDoWmClose(hWnd);
  248.            DestroyWindow (hWnd);
  249.            PostQuitMessage (0);
  250.            break; 
  251.  
  252.       case WM_QUERYENDSESSION :
  253.           FtpLocalClose ();
  254.           FtpRelease ();
  255.           TpDoWmClose(hWnd);
  256.           DeleteXferWindow ();
  257.           break;
  258.  
  259.       /* --------------------- */
  260.       /* asynchronous Messages */
  261.       /* --------------------- */
  262.       case CW_VERBOSE :
  263.           Ecris ((LPSTR) lParam);
  264.           break;
  265.  
  266.       case FTP_LOGGED :
  267.           Ecris ("Asynchronous Login returns %d -> <%s>", 
  268.                 (int) lParam, FtpErrorString ((int) lParam) );
  269.           break;
  270.  
  271.           /* Ftp4w sends a message each time an entry has been received */
  272.           /* lParam points on this entry, wParam is FALSE               */
  273.           /* If wParam is TRUE, the directory is finished, one gets the */
  274.           /* the return code of the function.                           */
  275.       case FTP_DIRLINEPERLINE :
  276.           if (! wParam)  DoAddLine ((LPSTR) lParam);
  277.           else  Ecris ("----> FtpDir Returns %d -> <%s>", 
  278.                 (int) lParam, FtpErrorString ((int) lParam) );
  279.           break;
  280.  
  281.           /* Dir asynchrone : The dir file has been received */  
  282.       case FTP_DIR :
  283.           Ecris ("Dir returns %d", (int) lParam);
  284.           Ecris ("-------");
  285.           hF = _lopen ("$$dir$$.tmp", 0);
  286.           _lread (hF, szBuf, sizeof szBuf);
  287.           _lclose (hF);
  288.           for (p=szBuf ; (q=strchr (p,'\r')) !=NULL ; p=q+2 )
  289.               {  *q=0;
  290.                   DoAddLine (p); }
  291.           Ecris ("-------");
  292.           unlink ("$$dir$$.tmp");
  293.           break;
  294.  
  295.  
  296.        case FTP_FILETRANSFERED :
  297.           if (wParam)
  298.             {
  299.                DeleteXferWindow ();
  300.                Ecris ("Asynchronous transfer returns %d ->  <%s>", 
  301.                     (int) lParam, FtpErrorString ((int) lParam) );
  302.                bFileTransfer = FALSE;
  303.             }
  304.           else
  305.             {
  306.                SetXmitBytes (lParam, FtpBytesToBeTransferred ());
  307.             }  
  308.           break;
  309.                 
  310.  
  311.       /* --------------------- */
  312.       /*     M   E   N   U     */
  313.       /* --------------------- */
  314.       case  WM_COMMAND :
  315.         switch (wParam)
  316.          {
  317.  
  318.            case  CW_ABOUT :
  319.                Ftp4wVer (szBuf, sizeof szBuf);
  320.                Ecris (szBuf);
  321.                break;
  322.                        
  323.            case  CW_CONNECT :
  324.                Ecris ("--- Connection on %s  ---", HOST_NAME () );
  325. #              ifdef FIREWALL_TYPE
  326.                Rc = FtpFirewallLogin ( HOST_NAME (), 
  327.                                        USER_NAME (), 
  328.                                        PASSWD_NAME (),
  329.                                        REM_HOSTNAME(),
  330.                                        REM_USERNAME(),
  331.                                        REM_PASSWD (),
  332.                                        FIREWALL_TYPE,
  333.                                        hWnd, FTP_LOGGED);
  334. #              else               
  335.                Rc = FtpLogin ( HOST_NAME (), 
  336.                                USER_NAME (), 
  337.                                PASSWD_NAME (),
  338.                                hWnd, FTP_LOGGED);
  339. #endif                               
  340.                Ecris ("Function returns %d", Rc);                              
  341.                break;
  342.  
  343.  
  344.            case CW_RCVAPPEND :
  345.            case CW_RECV :
  346.                Ecris ("Remote %s -> Local %s",REMOTEFILE_NAME (),LOCALFILE_NAME ());
  347.                bFileTransfer = TRUE;
  348.                if (IsOptOn(CW_GAUGE))
  349.                  {
  350.                     CreateXferWindow ();
  351.                     SetXferWindowText (LOCALFILE_NAME());
  352.                  }
  353.                if (wParam==CW_RCVAPPEND)
  354.                     Rc = FtpAppendToLocalFile ( REMOTEFILE_NAME (),
  355.                                   LOCALFILE_NAME (),
  356.                                   IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  357.                                   IsOptOn(CW_GAUGE),
  358.                                   hWnd, 
  359.                                   FTP_FILETRANSFERED);
  360.                else                                   
  361.                     Rc = FtpRecvFile ( REMOTEFILE_NAME (),
  362.                                   LOCALFILE_NAME (),
  363.                                   IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  364.                                   IsOptOn(CW_GAUGE),
  365.                                   hWnd, 
  366.                                   FTP_FILETRANSFERED);
  367.                if (! IsOptOn (CW_SYNC) )
  368.                  {       
  369.                     Ecris ("Taille %ld", FtpBytesToBeTransferred () );
  370.                     Ecris ("Async Recv returns %d %s", Rc, 
  371.                             Rc==0 ? "-> Cmd in progress" : "-> Cmd terminated");
  372.                     if (Rc!=0) bFileTransfer=FALSE;
  373.                  }
  374.                else  
  375.                 {
  376.                     DeleteXferWindow ();
  377.                     Ecris ("Recv returns %d", Rc);
  378.                     bFileTransfer = FALSE;
  379.                 }
  380.                break;
  381.  
  382.         
  383.  
  384.  
  385.            case CW_APPEND :
  386.            case CW_SEND :
  387.                Ecris ("Local %s -> Remote %s",LOCALFILE_NAME (),REMOTEFILE_NAME ());
  388.                bFileTransfer = TRUE;
  389.                if (IsOptOn(CW_GAUGE))
  390.                  {
  391.                     CreateXferWindow ();
  392.                     SetXferWindowText (LOCALFILE_NAME());
  393.                  }
  394.                if (wParam==CW_APPEND)
  395.                   Rc = FtpAppendToRemoteFile ( LOCALFILE_NAME (),
  396.                                                REMOTEFILE_NAME (),
  397.                                                IsOptOn(CW_BINARY)?TYPE_I:TYPE_A,
  398.                                                IsOptOn(CW_GAUGE),
  399.                                                hWnd, 
  400.                                               (LPARAM) FTP_FILETRANSFERED);
  401.                else  
  402.                   Rc = FtpSendFile ( LOCALFILE_NAME (),
  403.                                      REMOTEFILE_NAME (),
  404.                                      IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  405.                                      IsOptOn(CW_GAUGE),
  406.                                      hWnd, 
  407.                                     (LPARAM) FTP_FILETRANSFERED);
  408.                if (! IsOptOn (CW_SYNC) )
  409.                  {       
  410.                     Ecris ("Taille %ld", FtpBytesToBeTransferred () );
  411.                     Ecris ("Async Send returns %d %s", Rc, 
  412.                             Rc==0 ? "-> Cmd in progress" : "-> Cmd terminated");
  413.                     if (Rc!=0)       bFileTransfer = FALSE;
  414.                  }
  415.                else
  416.                  {
  417.                     DeleteXferWindow ();
  418.                     Ecris ("Send returns %d", Rc);
  419.                     bFileTransfer = FALSE;
  420.                  }
  421.                break;
  422.  
  423.  
  424.            case CW_RCVRESTART :
  425.                Ecris ("Local %s -> Remote %s",LOCALFILE_NAME (),REMOTEFILE_NAME ());
  426.                bFileTransfer = TRUE;
  427.                if (IsOptOn(CW_GAUGE))
  428.                  {
  429.                     CreateXferWindow ();
  430.                     SetXferWindowText (LOCALFILE_NAME());
  431.                  }
  432.                hFile = _lcreat (LOCALFILE_NAME (), 0);
  433.                     Rc = FtpRestartRecvFile ( REMOTEFILE_NAME (),
  434.                                   hFile,
  435.                                   IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  436.                                   IsOptOn(CW_GAUGE),
  437.                                   100l,
  438.                                   hWnd, 
  439.                                   FTP_FILETRANSFERED);
  440.                if (! IsOptOn (CW_SYNC) )
  441.                  {       
  442.                     Ecris ("Taille %ld", FtpBytesToBeTransferred () );
  443.                     Ecris ("Async Recv returns %d %s", Rc, 
  444.                             Rc==0 ? "-> Cmd in progress" : "-> Cmd terminated");
  445.                     if (Rc!=0) bFileTransfer=FALSE;
  446.                  }
  447.                else  
  448.                 {
  449.                     DeleteXferWindow ();
  450.                     Ecris ("Recv returns %d", Rc);
  451.                     bFileTransfer = FALSE;
  452.                 }
  453.                break;
  454.  
  455. #ifdef TEST_FOR_DATACONNECTION
  456.            case CW_RECVTEXT :
  457.                Rc = FtpOpenDataConnection ("/tmp/Z", 
  458.                                     FTP4W_GET_FROM_SERVER, 'A');
  459.                Ecris ("OpenDataconnection returns %d", Rc);
  460.                do 
  461.                  {
  462.                     Ark = sizeof szBuf;
  463.                     memset (szBuf, 0, sizeof szBuf);
  464.                     Rc = FtpRecvThroughDataConnection (szBuf, & Ark);
  465.                     Ecris ("RecvThrough returns %d -> %d bytes", Rc, Ark);
  466.                     if (Rc==FTPERR_OK)  Ecris ("<%s>", szBuf);
  467.                  }
  468.                while (Rc==FTPERR_OK);
  469.                Rc = FtpCloseDataConnection ();
  470.                Ecris ("CloseDataconnection returns %d", Rc);
  471.                break;
  472. #endif /* TEST_FOR_DATACONNECTION */
  473.  
  474.            case CW_RECVDIR :
  475.                Rc = FtpMGet ("*.*", TYPE_I, FALSE, MGetShow);
  476.                Ecris ("FtpMGet returns %d", Rc);
  477.                break;
  478.                                     
  479.                
  480.  
  481.            case CW_SHORTDIR :
  482.            case CW_LONGDIR :
  483.                Rc=FtpDir (NULL, "$$dir$$.tmp",wParam==CW_LONGDIR,hWnd,FTP_DIR);
  484.                if (Rc!=FTPERR_OK || IsOptOn(CW_SYNC))  
  485.                         PostMessage (hWnd, FTP_DIR, TRUE, Rc);
  486.                break;
  487.  
  488.            case CW_SHORTDIR_LL :
  489.            case CW_LONGDIR_LL :
  490.                if (IsOptOn (CW_SYNC))  
  491.                     DoAddLine ("You MUST be in Asynchronous Mode");
  492.                else     
  493.                  {
  494.                    Rc=FtpDir (NULL, NULL,wParam==CW_LONGDIR_LL,hWnd,FTP_DIRLINEPERLINE);
  495.                    Ecris ("FtpDir returns %d", Rc);
  496.                  }
  497.                break;
  498.  
  499.            case CW_CWD :
  500.               Rc = FtpCWD (REMOTE_DIR ());
  501.               Ecris ("CWD returns %d", Rc);
  502.               break;
  503.  
  504.            case CW_CDUP :
  505.               Rc = FtpCDUP ();
  506.               Ecris ("CDUP returns %d", Rc);
  507.               break;
  508.  
  509.            case CW_PWD :
  510.               Rc = FtpPWD (szBuf, sizeof szBuf);
  511.               if (Rc==FTPERR_OK)  Ecris ("Current dir : %s", szBuf);
  512.               else                Ecris ("FtpPWD returns %d", Rc);
  513.               break;
  514.  
  515.            case CW_RMD :
  516.               Rc = FtpRMD (REMOTE_DIR ());
  517.               Ecris ("ftpRMD returns %d", Rc);
  518.               break;
  519.  
  520.            case CW_MKD :
  521.               Rc = FtpMKD (REMOTE_DIR (), szBuf, sizeof szBuf);
  522.               /* szBuf should be the name of the created dir */
  523.               if (Rc==FTPERR_OK  && szBuf[0]!=0)  
  524.                         Ecris ("Dir %s Has been created", szBuf);
  525.               else      Ecris ("FtpMKD returns %d", Rc);
  526.               break;
  527.  
  528.  
  529.            case CW_DELETE :
  530.               Rc = FtpDeleteFile (REMOTEFILE_NAME ());
  531.               Ecris ("FtpDelete returns %d", Rc);
  532.               break;
  533.             
  534.            case CW_SYST :
  535.               Rc = FtpSyst (szSyst);
  536.               Ecris ("System returns %d -> %s", 
  537.                       Rc, Rc>=1000 ? 
  538.                           Rc==FTPERR_SYSTUNKNOWN ? "Unknown" :"Error" : 
  539.                           szSyst[Rc]);
  540.               break;
  541.  
  542.            case CW_RENAME :
  543.               Rc = FtpRenameFile (REMOTEFILE_NAME (), NEWREMOTEFILE_NAME ());
  544.               Ecris ("Rename returns %d", Rc);
  545.               break;
  546.  
  547.            case CW_FLUSH :
  548.               Rc = FtpFlush ();
  549.               Ecris ("Flush returns %d", Rc);
  550.               break;
  551.  
  552.            case CW_QUOTE :
  553.               lpfnQuoteDlg = MakeProcInstance ((FARPROC) CBQuoteDlg, hInst);
  554.               if (DialogBox(hInst, "QuoteDlg", hWnd, (DLGPROC)lpfnQuoteDlg)==0)
  555.                 {
  556.                     Ecris ("QUOTE %s", szQuoteCmd);
  557.                     Rc=FtpQuote (szQuoteCmd, NULL, 0);
  558.                     Ecris ("Quote returns %d", Rc);
  559.                  }
  560.               FreeProcInstance (lpfnQuoteDlg);
  561.               break;
  562.  
  563.  
  564.            case CW_ABORT :
  565.               Ecris ("Abort");
  566.               FtpAbort ();
  567.               break;  
  568.  
  569.  
  570.            case CW_DISCONNECT : 
  571.                if (bFileTransfer)
  572.                   {
  573.                      Ecris ("File transfer in progress, can not close session");
  574.                   }
  575.                else
  576.                   {
  577.                      Rc = FtpCloseConnection ();
  578.                      Ecris ("FtpCloseConnection returns %d", Rc);
  579.                   }
  580.                break;
  581.  
  582.  
  583.            case CW_QUIT : 
  584.                 PostMessage (hWnd, WM_CLOSE, 0, 0l);
  585.                 break;
  586.                                      
  587.            case CW_SYNC : 
  588.                if (bFileTransfer)
  589.                  {
  590.                    MessageBox (NULL, "Can not change now", "CW_MAIN", MB_OK);
  591.                  }
  592.                else
  593.                  {
  594.                    if (! IsOptOn (CW_SYNC))
  595.                       {
  596.                           CheckMenuItem (GetMenu (hWnd), CW_SYNC, 
  597.                                          MF_BYCOMMAND  | MF_CHECKED);
  598.                           FtpSetSynchronousMode ();
  599.                        }
  600.                    else   
  601.                       {
  602.                           CheckMenuItem (GetMenu (hWnd), CW_SYNC, 
  603.                                          MF_BYCOMMAND  | MF_UNCHECKED);
  604.                           FtpSetAsynchronousMode ();
  605.                        }
  606.                  }
  607.                break;      
  608.                      
  609.            case CW_SETVERB :
  610.                if (IsOptOn (CW_SETVERB))
  611.                    
  612.                  {                
  613.                    CheckMenuItem (GetMenu (hWnd), CW_SETVERB, 
  614.                                   MF_BYCOMMAND  | MF_UNCHECKED);
  615.                    FtpSetVerboseMode (FALSE, hWnd, CW_VERBOSE);
  616.                  }
  617.                else
  618.                  {                
  619.                    CheckMenuItem (GetMenu (hWnd), CW_SETVERB, 
  620.                                   MF_BYCOMMAND  | MF_CHECKED);
  621.                    FtpSetVerboseMode (TRUE, hWnd, CW_VERBOSE);
  622.                  }
  623.                break; 
  624.  
  625.  
  626.            case CW_GAUGE :
  627.                CheckMenuItem (GetMenu (hWnd), CW_GAUGE, MF_BYCOMMAND  | 
  628.                               IsOptOn(CW_GAUGE) ? MF_UNCHECKED : MF_CHECKED); 
  629.                /* pause (for display) each 3 frames if gauge is on */
  630.                if IsOptOn(CW_GAUGE)   FtpSetNewSlices(3, 1);
  631.                else                   FtpSetNewSlices(10, 3);
  632.                break; 
  633.  
  634.  
  635.            case CW_LOG :
  636.                CheckMenuItem (GetMenu (hWnd), CW_LOG, MF_BYCOMMAND  | 
  637.                               IsOptOn(CW_LOG) ? MF_UNCHECKED : MF_CHECKED); 
  638.                if IsOptOn(CW_LOG)   hLogFile =  _lcreat (LOG_FILE, 0);
  639.                else                 
  640.                     {
  641.                       _lclose (hLogFile); 
  642.                       hLogFile = HFILE_ERROR;
  643.                     }
  644.                FtpLogTo (hLogFile);
  645.                break; 
  646.                 
  647.                 
  648.            case CW_BINARY :
  649.                CheckMenuItem (GetMenu (hWnd), CW_BINARY, MF_BYCOMMAND  | 
  650.                               IsOptOn(CW_BINARY) ? MF_UNCHECKED : MF_CHECKED);
  651.                break; 
  652.                 
  653.                 
  654.            case CW_PASSIVE :
  655.                CheckMenuItem (GetMenu (hWnd), CW_PASSIVE, MF_BYCOMMAND  | 
  656.                               IsOptOn(CW_PASSIVE) ? MF_UNCHECKED : MF_CHECKED);
  657.                FtpSetPassiveMode (IsOptOn (CW_PASSIVE));
  658.                break; 
  659.                 
  660.           case CW_EDITINI :
  661.                GetWindowsDirectory (szWinDir, sizeof szWinDir);
  662.                wsprintf (szExecCmd, "NotePad %s\\%s", szWinDir, INIFILE_NAME);
  663.                WinExec (szExecCmd, SW_SHOW);
  664.                break;
  665.                 
  666.             } /* WM_COMMAND */
  667.     }
  668. return DefWindowProc(hWnd, message, wParam, lParam);
  669. } /* Boucle Windows */
  670.  
  671.  
  672.  
  673.  
  674. /* ******************************************************************* */
  675. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  676.                         LPSTR lpszCmdLine, int nCmdShow)
  677. {
  678. MSG   msg;
  679.  
  680.     hInst = hInstance;       /* save for use by window procs */
  681.     FirstEmission = (hPrevInstance==NULL);
  682.  
  683.     // Go init this application
  684.     if (    !hPrevInstance  &&  !InitApplication(hInstance) )
  685.         return   FALSE;      /* Exits if unable to initialize */
  686.     if (!InitInstance(hInstance, nCmdShow))   return FALSE;
  687.  
  688.     /* Get and dispatch messages for this applicaton.*/
  689.     while (GetMessage(&msg, NULL, 0, 0))
  690.       {
  691.         TranslateMessage(&msg);
  692.         DispatchMessage(&msg);                  
  693.       }
  694.     UnregisterClass (szAPPLICATION, hInstance);  
  695.     nCwRegisterClasses();
  696.    _lclose (hLogFile); 
  697. return  msg.wParam;
  698. } /* WinMain */
  699.  
  700.  
  701. /* ******************************************************************* */
  702.  
  703. BOOL InitApplication (HINSTANCE hInstance)
  704. {
  705. WNDCLASS wndClass;
  706.  
  707.      wndClass.lpszClassName = szAPPLICATION;
  708.      wndClass.lpszMenuName  = szAPPLICATION;
  709.      wndClass.hInstance     = hInstance;
  710.      wndClass.lpfnWndProc   = MainWndProc;
  711.      wndClass.hCursor       = LoadCursor(hInstance, IDC_ARROW);
  712.      wndClass.hIcon         = LoadIcon  (hInstance, "CW_MAIN");
  713.      wndClass.hbrBackground = (HBRUSH) (1 + COLOR_WINDOW);
  714.      wndClass.style         = CS_VREDRAW | CS_HREDRAW;
  715.      wndClass.cbClsExtra    = 0;
  716.      wndClass.cbWndExtra    = 0;
  717.    // Register the class
  718. return  RegisterClass (&wndClass);
  719. }  /* InitApplication */
  720.       
  721.       
  722.  
  723.  
  724. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
  725. {
  726. HWND       hWnd;
  727.  
  728.     hWnd = CreateWindow(
  729.                     szAPPLICATION,     // window class name
  730.                     szAPPLICATION,     // window title
  731.                     WS_OVERLAPPEDWINDOW | WS_HSCROLL | WM_VSCROLL | WS_VISIBLE,
  732.                     CW_USEDEFAULT,          // x - same as dialog box
  733.                     CW_USEDEFAULT,          // y
  734.                     490,                     // cx
  735.                     250,                     // cy
  736.                     NULL,                    // no parent for this window
  737.                     NULL,                    // use the class menu
  738.                     hInstance,               // who created this window
  739.                     NULL                     // no parms to pass on
  740.           );
  741.     if (hWnd==0)  return FALSE;
  742.     ShowWindow (hWnd, nCmdShow);
  743.     UpdateWindow (hWnd);
  744. return TRUE;
  745. }  /* InitInstance */
  746.  
  747.  
  748.  
  749.  
  750. /* ------------------------------ */
  751. /* Get informations from INI file */
  752. /* ------------------------------ */
  753. LPSTR HOST_NAME(void) 
  754. {
  755. static char szBuf[256];
  756.  GetPrivateProfileString ("Connect", "Host", "", szBuf,256, INIFILE_NAME);
  757.   if (szBuf[0]==0)
  758.     {
  759.       MessageBox ( NULL,
  760.                    "Field Host not defined in Cw.Ini", 
  761.                    "CW_MAIN", MB_OK);
  762.       return NULL;
  763.     }
  764.   return szBuf; }  
  765.                         
  766.  
  767. LPSTR USER_NAME(void) 
  768. {
  769. static char szBuf[256];
  770.  GetPrivateProfileString ("Connect", "User", "", szBuf,256, INIFILE_NAME);
  771.   if (szBuf[0]==0)
  772.     {
  773.       MessageBox ( NULL,
  774.                    "Field User not defined in Cw.Ini", 
  775.                    "CW_MAIN", MB_OK);
  776.       return NULL;
  777.     }
  778.   return szBuf; }  
  779.  
  780.  
  781. LPSTR PASSWD_NAME(void) 
  782. {
  783. static char szBuf[256];
  784.  GetPrivateProfileString ("Connect", "PassWd", "", szBuf,256, INIFILE_NAME);
  785.   if (szBuf[0]==0)
  786.     {
  787.       MessageBox ( NULL,
  788.                    "Field PassWd not defined in Cw.Ini", 
  789.                    "CW_MAIN", MB_OK);
  790.       return NULL;
  791.     }
  792.   return szBuf; }  
  793.                         
  794.  
  795. LPSTR REM_HOSTNAME(void) 
  796. {
  797. static char szBuf[256];
  798.  GetPrivateProfileString ("Connect", "RemHost", "", szBuf,256, INIFILE_NAME);
  799.   if (szBuf[0]==0)
  800.     {
  801.       MessageBox ( NULL,
  802.                    "Field RemHost not defined in Cw.Ini", 
  803.                    "CW_MAIN", MB_OK);
  804.       return NULL;
  805.     }
  806.   return szBuf; }  
  807.                         
  808.  
  809. LPSTR REM_USERNAME(void) 
  810. {
  811. static char szBuf[256];
  812.  GetPrivateProfileString ("Connect", "RemUser", "", szBuf,256, INIFILE_NAME);
  813.   if (szBuf[0]==0)
  814.     {
  815.       MessageBox ( NULL,
  816.                    "Field RemUser not defined in Cw.Ini", 
  817.                    "CW_MAIN", MB_OK);
  818.       return NULL;
  819.     }
  820.   return szBuf; }  
  821.  
  822.  
  823. LPSTR REM_PASSWD(void) 
  824. {
  825. static char szBuf[256];
  826.  GetPrivateProfileString ("Connect", "RemPass", "", szBuf,256, INIFILE_NAME);
  827.   if (szBuf[0]==0)
  828.     {
  829.       MessageBox ( NULL,
  830.                    "Field RemPass not defined in Cw.Ini", 
  831.                    "CW_MAIN", MB_OK);
  832.       return NULL;
  833.     }
  834.   return szBuf; }  
  835.  
  836.  
  837. LPSTR LOCALFILE_NAME(void) 
  838. {
  839. static char szBuf[256];
  840.  GetPrivateProfileString ("Transfer", "LocalFile", "",szBuf,256,INIFILE_NAME);
  841.   if (szBuf[0]==0)
  842.     {
  843.       MessageBox ( NULL,
  844.                    "Field LocalFile not defined in Cw.Ini", 
  845.                    "CW_MAIN", MB_OK);
  846.       return NULL;
  847.     }
  848.   return szBuf; }  
  849.                         
  850.                         
  851. LPSTR REMOTEFILE_NAME(void) 
  852. {
  853. static char szBuf[256];
  854.  GetPrivateProfileString ("Transfer", "RemoteFile", "",szBuf,256,INIFILE_NAME);
  855.   if (szBuf[0]==0)
  856.     {
  857.       MessageBox ( NULL,
  858.                    "Field RemoteFile not defined in Cw.Ini", 
  859.                    "CW_MAIN", MB_OK);
  860.       return NULL;
  861.     }
  862.   return szBuf; }  
  863.  
  864.  
  865. LPSTR NEWREMOTEFILE_NAME(void) 
  866. {
  867. static char szBuf[256];
  868.  GetPrivateProfileString ("Rename", "NewRemoteFile", "",szBuf,256,INIFILE_NAME);
  869.   if (szBuf[0]==0)
  870.     {
  871.       MessageBox ( NULL,
  872.                    "Field NewRemoteFile not defined in Cw.Ini", 
  873.                    "CW_MAIN", MB_OK);
  874.       return NULL;
  875.     }
  876.   return szBuf; }  
  877.  
  878.  
  879. LPSTR REMOTE_DIR(void) 
  880. {
  881. static char szBuf[256];
  882.  GetPrivateProfileString ("Directory", "HostDir", "", szBuf,256, INIFILE_NAME);
  883.   if (szBuf[0]==0)
  884.     {
  885.       MessageBox ( NULL,
  886.                    "Field HostDir not defined in Cw.Ini", 
  887.                    "CW_MAIN", MB_OK);
  888.       return NULL;
  889.     }
  890.   return szBuf; }  
  891.  
  892.  
  893.