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

Windows Kernel

Development Platform:

Visual C++

  1. #include "stdafx.h"
  2. #include "password.h"
  3. INT_PTR CPasswordDialog::DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.     switch (uMsg)
  6.     {
  7.         HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
  8.         HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
  9.     default:
  10.         break;
  11.     }
  12.     return FALSE;
  13. }
  14. BOOL CPasswordDialog::OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  15. {
  16.     TCHAR   szMessage[MAX_PATH + MAX_DOMAIN + MAX_USER + 256 + 2]; szMessage[0] = 0;
  17.     //
  18.     // Store the passed-in information
  19.     //
  20.     //
  21.     // Limit the size of the edit controls
  22.     //
  23.     Edit_LimitText(GetDlgItem(hwnd, IDC_USER),
  24.                    m_cchDomainUser - 1);
  25.     Edit_LimitText(GetDlgItem(hwnd, IDC_PASSWORD),
  26.                    m_cchPassword - 1);
  27.     //
  28.     // Set the username and share
  29.     //
  30.     SetDlgItemText(hwnd, IDC_USER, m_pszDomainUser);
  31.     
  32.     // We may need to generate a user name here to use if no user name was
  33.     // passed in
  34.     TCHAR szDomainUser[MAX_DOMAIN + MAX_USER + 2];
  35.     LPTSTR pszUserNameToUse;
  36.     if (*m_pszDomainUser)
  37.     {
  38.         pszUserNameToUse = m_pszDomainUser;
  39.     }
  40.     else
  41.     {
  42.         szDomainUser[0] = 0;
  43.         TCHAR szUser[MAX_USER + 1];
  44.         DWORD cchUser = ARRAYSIZE(szUser);
  45.         TCHAR szDomain[MAX_DOMAIN + 1];
  46.         DWORD cchDomain = ARRAYSIZE(szDomain);
  47.         GetCurrentUserAndDomainName(szUser, &cchUser, szDomain, &cchDomain);
  48.         
  49.         MakeDomainUserString(szDomain, szUser, szDomainUser, ARRAYSIZE(szDomainUser));
  50.         pszUserNameToUse = szDomainUser;
  51.     }
  52.     FormatMessageString(IDS_PWD_STATIC, szMessage, ARRAYSIZE(szMessage), m_pszResourceName, pszUserNameToUse);
  53.     SetDlgItemText(hwnd, IDC_MESSAGE, szMessage);
  54.     // Now set the error message description
  55.     TCHAR szError[512];
  56.     DWORD dwFormatResult = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, m_dwError, 0, szError, ARRAYSIZE(szError), NULL);
  57.     if (0 == dwFormatResult)
  58.     {
  59.         LoadString(g_hInstance, IDS_ERR_UNEXPECTED, szError, ARRAYSIZE(szError));
  60.     }
  61.     SetDlgItemText(hwnd, IDC_ERROR, szError);
  62.     return TRUE;
  63. }
  64. BOOL CPasswordDialog::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  65. {
  66.     switch(id) 
  67.     {
  68.     case IDOK:
  69.         {
  70.             // Read the username and password from the dialog.  Note
  71.             // that we don't call FetchText for the password since it
  72.             // strips leading and trailing whitespace and, for all we
  73.             // know, that could be an important part of the password
  74.             FetchText(hwnd, IDC_USER, m_pszDomainUser, m_cchDomainUser);
  75.             GetDlgItemText(hwnd, IDC_PASSWORD, m_pszPassword, m_cchPassword);
  76.         }
  77.         // Fall through
  78.     case IDCANCEL:
  79.         EndDialog(hwnd, id);
  80.         return TRUE;
  81.     }
  82.     return FALSE;
  83. }