netfinpg.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 5k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "stdafx.h"
  2. #include "password.h"
  3. #include <wininet.h>
  4. #include "netfinpg.h"
  5. INT_PTR CNetPlacesWizardPage3::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  6. {
  7.     switch(uMsg)
  8.     {
  9.         HANDLE_MSG(hwndDlg, WM_COMMAND, OnCommand);
  10.         HANDLE_MSG(hwndDlg, WM_INITDIALOG, OnInitDialog);
  11.         HANDLE_MSG(hwndDlg, WM_NOTIFY, OnNotify);
  12.     default:
  13.         break;
  14.     }
  15.     return FALSE;
  16. }
  17. BOOL CNetPlacesWizardPage3::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  18. {
  19.     if ((EN_CHANGE == codeNotify) && (IDC_NETPLNAME_EDIT == id))
  20.     {
  21.         TCHAR szFriendlyName[MAX_PATH];
  22.         // Edit contents have changed - disable Finish if necessary
  23.         DWORD dwButtons = PSWIZB_BACK;
  24.         FetchText(hwnd, id, szFriendlyName, ARRAYSIZE(szFriendlyName));
  25.         if (*szFriendlyName)
  26.         {
  27.             dwButtons |= PSWIZB_FINISH;
  28.         }
  29.         else
  30.         {
  31.             dwButtons |= PSWIZB_DISABLEDFINISH;
  32.         }
  33.         PropSheet_SetWizButtons(GetParent(hwnd), dwButtons);
  34.         return TRUE;
  35.     }
  36.     return FALSE;
  37. }
  38. BOOL CNetPlacesWizardPage3::OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  39. {
  40.     // Bold the welcome title
  41.     SendDlgItemMessage(hwnd, IDC_COMPLETE_TITLE, WM_SETFONT, (WPARAM) GetIntroFont(hwnd), 0);
  42.  
  43.     Edit_LimitText(GetDlgItem(hwnd, IDC_NETPLNAME_EDIT), NETPLACE_MAX_FRIENDLY_NAME);
  44.     return TRUE;
  45. }
  46. BOOL CNetPlacesWizardPage3::OnNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
  47. {
  48.     switch (pnmh->code)
  49.     {
  50.         case PSN_SETACTIVE:
  51.             {
  52.                 // Load the completion message
  53.                 TCHAR szMessage[MAX_STATIC + MAX_PATH];
  54.                 if (FormatMessageString(IDS_COMPLETION_STATIC, szMessage, ARRAYSIZE(szMessage), m_pdata->netplace.GetResourceName()))
  55.                 {
  56.                     SetDlgItemText(hwnd, IDC_COMPLETION_STATIC, szMessage);
  57.                 }
  58.                 // Create a default name
  59.             
  60.                 LPCTSTR pszFriendlyName = m_pdata->netplace.GetFriendlyName();
  61.                 if (NULL != pszFriendlyName)
  62.                 {
  63.                     SetDlgItemText(hwnd, IDC_NETPLNAME_EDIT, pszFriendlyName);
  64.                 }
  65.                 else
  66.                 {
  67.                     SetDlgItemText(hwnd, IDC_NETPLNAME_EDIT, _T(""));
  68.                 }
  69.                 PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_BACK | PSWIZB_FINISH);
  70.             }
  71.             return TRUE;
  72.         case PSN_WIZBACK:
  73.             // See if the user came here from the Welcome page or the 
  74.             // Select Folders page and go back there
  75.             //
  76.             // Notify the network place data structure in case it needs to do cleanup
  77.             m_pdata->netplace.Cancel();
  78.             
  79.             if (m_pdata->fShowFoldersPage)
  80.             {
  81.                 // We need to remove the folder selected last time from the path
  82.                 // Find last whack ''
  83.                 TCHAR* pchWhack = _tcsrchr(m_pdata->netplace.GetResourceName(), _T('\'));
  84.                 if (pchWhack != NULL)
  85.                     *pchWhack = _T('');
  86.                 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, m_pdata->idFoldersPage);
  87.             }
  88.             else if (m_pdata->fShowFTPUserPage)
  89.             {
  90.                 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, m_pdata->idPasswordPage);
  91.             }
  92.             else
  93.             {
  94.                 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, m_pdata->idWelcomePage);
  95.             }
  96.             return -1;
  97.         case PSN_WIZFINISH:
  98.             {
  99.                 //
  100.                 // If we couldn't map the drive, return a non-zero
  101.                 // value to prevent the page from being destroyed
  102.                 //
  103.                 
  104.                 TCHAR szFriendlyName[MAX_PATH + 1];
  105.                 FetchText(hwnd, IDC_NETPLNAME_EDIT, szFriendlyName, ARRAYSIZE(szFriendlyName));
  106.                 HRESULT hrSetFriendlyName = m_pdata->netplace.SetFriendlyName(szFriendlyName);
  107.                 HRESULT hrCreatePlace;
  108.                 
  109.                 if (SUCCEEDED(hrSetFriendlyName))
  110.                 {
  111.                     hrCreatePlace = m_pdata->netplace.CreatePlace(hwnd);
  112.                 }
  113.                 SetWindowLongPtr(hwnd, DWLP_MSGRESULT, (LONG_PTR) (SUCCEEDED(hrCreatePlace) ? 0 : GetDlgItem(hwnd, IDC_NETPLNAME_EDIT)));
  114.                
  115.                 return TRUE;
  116.             }
  117.         case PSN_QUERYCANCEL:
  118.             {
  119.                 // Notify the network place data structure in case it needs to do cleanup
  120.                 m_pdata->netplace.Cancel();
  121.                 return TRUE;
  122.             }
  123.     }
  124.     return FALSE;
  125. }