home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / wininet / asyncftp / cdlgopt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-01  |  5.4 KB  |  203 lines

  1. #include <windows.h>
  2. #include <windowsx.h>
  3.  
  4. #include <commctrl.h>
  5. #include <wininet.h>
  6. #include "comctlhd.h"
  7. #include "cdlgopt.h"
  8. #include "clist.h"
  9. #include "cdlg.h"
  10. #include "capp.h"
  11. #include "resource.h"
  12.  
  13. extern CApp *lpCApp;
  14.  
  15. //**********************************************************************
  16. // CDlgOpt::CDlgOpt
  17. //
  18. // Purpose: Constructor for CDlgOpt class
  19. // Parameters: None
  20. //
  21. //********************************************************************
  22.  
  23. CDlgOpt::CDlgOpt() 
  24. {
  25.     return;
  26. }
  27.  
  28.  
  29. //**********************************************************************
  30. // CDlgOpt::~CDlgOpt
  31. //
  32. // Purpose: Destructor for CDlgOpt class
  33. //********************************************************************
  34.  
  35. CDlgOpt::~CDlgOpt()
  36. {
  37.     return;
  38. }
  39.  
  40. //**********************************************************************
  41. // CDlgOpt::Init
  42. //
  43. // Purpose: Create and show modal dialog
  44. //
  45. // Parameters: None
  46. //
  47. // Return Value:  
  48. //    BOOL - TRUE if initialization succeeded, FALSE otherwise.
  49. //
  50. //********************************************************************
  51.  
  52. BOOL CDlgOpt::Init(HINSTANCE hInst, HWND hWnd, DLGDATA *pdata)
  53. {
  54.     return DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hWnd, (int (__stdcall *)(void))DialogProc, (LPARAM)pdata);
  55.  
  56.     
  57. }
  58.  
  59.  
  60. //**********************************************************************
  61. // CDlgOpt::DialogProc
  62. //
  63. // Purpose: Dialog procedure for connect options dialog
  64. //
  65. //
  66. //********************************************************************
  67.  
  68.  
  69. BOOL CALLBACK CDlgOpt::DialogProc(HWND hWnd, UINT message,  WPARAM wParam, LPARAM lParam)
  70. {
  71.     DLGDATA *pdata;
  72.     DWORD  idc;
  73.     CDlgOpt *lpCDlgOpt = lpCApp->m_pCDlgOpt;
  74.     switch (message)
  75.     {
  76.         case WM_INITDIALOG:
  77.             //initialization data is passed in via lParam
  78.             pdata = (DLGDATA *)lParam;
  79.  
  80.             Edit_Enable(GetDlgItem(hWnd,IDC_EDITPROXY),FALSE);
  81.  
  82.             //check the current setting of access type
  83.             switch (pdata->dwAccessType)
  84.             {
  85.             case INTERNET_OPEN_TYPE_PRECONFIG:
  86.                 idc = IDC_OPTPRE;
  87.                 break;
  88.             case INTERNET_OPEN_TYPE_DIRECT:
  89.                 idc = IDC_OPTLOCAL;
  90.                 break;
  91.             case INTERNET_OPEN_TYPE_PROXY:
  92.                 idc = IDC_OPTCERN;
  93.                 Edit_Enable(GetDlgItem(hWnd,IDC_EDITPROXY),TRUE);
  94.                 break;
  95.             default:
  96.                 idc = IDC_OPTLOCAL;
  97.                 break;
  98.  
  99.             }
  100.             Button_SetCheck(GetDlgItem(hWnd,idc), 1);
  101.             //is this going to be anonymous logon
  102.             if (pdata->anonymous)
  103.             {
  104.                 Button_SetCheck(GetDlgItem(hWnd,IDC_CHECK1), 1);
  105.                 SetWindowText(GetDlgItem(hWnd, IDC_EDITUSER), pdata->pszUser);
  106.                 SetWindowText(GetDlgItem(hWnd, IDC_EDITPWD), pdata->pszPwd);
  107.                 Edit_Enable(GetDlgItem(hWnd, IDC_EDITUSER), FALSE);
  108.             }
  109.             else
  110.             {
  111.                 Edit_Enable(GetDlgItem(hWnd, IDC_EDITUSER), FALSE);
  112.                 Edit_Enable(GetDlgItem(hWnd, IDC_EDITPWD), FALSE);
  113.             }
  114.             SetFocus(GetDlgItem(hWnd, IDC_EDITPWD));
  115.  
  116.             return FALSE;
  117.  
  118.         case WM_COMMAND:  // message: command from application menu
  119.             switch (LOWORD(wParam)) 
  120.             {
  121.                 case IDC_CHECK1:
  122.                     if (Button_GetCheck(GetDlgItem(hWnd,IDC_CHECK1)))
  123.                     {
  124.                         Edit_SetText(GetDlgItem(hWnd,IDC_EDITUSER),"anonymous");
  125.                         Edit_SetText(GetDlgItem(hWnd,IDC_EDITPWD),"anonymous");
  126.                         Edit_Enable(GetDlgItem(hWnd,IDC_EDITUSER),FALSE);
  127.                         Edit_Enable(GetDlgItem(hWnd,IDC_EDITPWD),TRUE);
  128.                     }
  129.                     else
  130.                     {
  131.                         Edit_Enable(GetDlgItem(hWnd,IDC_EDITUSER),TRUE);
  132.                         Edit_Enable(GetDlgItem(hWnd,IDC_EDITPWD),TRUE);
  133.                     }
  134.  
  135.                     break;
  136.                 case IDC_OPTPRE:
  137.                 case IDC_OPTLOCAL:
  138.                     Edit_SetText(GetDlgItem(hWnd,IDC_EDITPROXY), "");
  139.                     Edit_Enable(GetDlgItem(hWnd,IDC_EDITPROXY),FALSE);
  140.                     break;
  141.  
  142.                 case IDC_OPTCERN:
  143.                     Edit_Enable(GetDlgItem(hWnd,IDC_EDITPROXY),TRUE);
  144.                     break; 
  145.                 case ID_SET:
  146.                     //committ the changes and copy the dialog box values
  147.                     //to the CDlgOpt class member variables
  148.                     lpCDlgOpt->m_anonymous = Button_GetCheck(GetDlgItem(hWnd,IDC_CHECK1));
  149.                     GetWindowText(GetDlgItem(hWnd,IDC_EDITUSER),lpCDlgOpt->m_pszUser,20);
  150.                     GetWindowText(GetDlgItem(hWnd,IDC_EDITPWD),lpCDlgOpt->m_pszPwd,20);
  151.  
  152.                     if (0 == lstrlen(lpCDlgOpt->m_pszPwd))
  153.                     {
  154.                         MessageBox(hWnd, "Please enter a password", "Error", MB_ICONEXCLAMATION | MB_OK) ;
  155.                         return FALSE;
  156.                     }
  157.                     if ( 0 == lstrlen(lpCDlgOpt->m_pszUser))
  158.                     {
  159.                         if (!lpCDlgOpt->m_anonymous)
  160.                         {
  161.                         MessageBox(hWnd, "Please enter a user name", "Error", MB_ICONEXCLAMATION | MB_OK) ;
  162.                         return FALSE;
  163.  
  164.                         }
  165.                         else {
  166.                             lstrcpy(lpCDlgOpt->m_pszUser, "anonymous"); }
  167.                     }
  168.  
  169.  
  170.                     if (Button_GetCheck(GetDlgItem(hWnd,IDC_OPTPRE)))
  171.                         lpCDlgOpt->m_dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG;
  172.                     if (Button_GetCheck(GetDlgItem(hWnd,IDC_OPTLOCAL)))
  173.                         lpCDlgOpt->m_dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
  174.                     if (Button_GetCheck(GetDlgItem(hWnd,IDC_OPTCERN)))
  175.                     {
  176.                         lpCDlgOpt->m_dwAccessType = INTERNET_OPEN_TYPE_PROXY;
  177.                         GetWindowText(GetDlgItem(hWnd,IDC_EDITPROXY),lpCDlgOpt->m_pszProxy,20);
  178.                     }
  179.                     else {
  180.                         //make sure the proxy string is initialized since it gets
  181.                         //copied over after the dialog is dismissed
  182.                         lstrcpy(lpCDlgOpt->m_pszProxy, "");
  183.                     }
  184.  
  185.  
  186.                     EndDialog(hWnd,ID_SET);
  187.                     break;
  188.                 case ID_END:  // close dialog
  189.                     EndDialog(hWnd,ID_END);
  190.                     break;
  191.                 default:
  192.                     return FALSE;
  193.             }
  194.  
  195.         case WM_DESTROY:  // message: window being destroyed
  196.             return 0;
  197.  
  198.         default:
  199.             return FALSE;
  200.     }
  201.     return TRUE;
  202. }
  203.