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

Windows Kernel

Development Platform:

Visual C++

  1. /********************************************************
  2.  autolog.cpp
  3.   User Manager autologon dialog implementation
  4.  History:
  5.   09/23/98: dsheldon created
  6. ********************************************************/
  7. #include "stdafx.h"
  8. #include "resource.h"
  9. #include "data.h"
  10. #include "autolog.h"
  11. INT_PTR CAutologonUserDlg::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  12. {
  13.     switch(uMsg)
  14.     {
  15.         HANDLE_MSG(hwndDlg, WM_INITDIALOG, OnInitDialog);
  16.         HANDLE_MSG(hwndDlg, WM_COMMAND, OnCommand);
  17.     }
  18.     return FALSE;
  19. }
  20. BOOL CAutologonUserDlg::OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  21. {
  22.     TraceEnter(TRACE_USR_CORE, "CAutologonUserDlg::OnInitDialog");
  23.     // Limit the sizes of the edit boxes
  24.     HWND hwndUsername = GetDlgItem(hwnd, IDC_USER);
  25.     SendMessage(hwndUsername, EM_SETLIMITTEXT, MAX_USER, 0);
  26.     HWND hwndPassword = GetDlgItem(hwnd, IDC_PASSWORD);
  27.     SendMessage(hwndPassword, EM_SETLIMITTEXT, MAX_PASSWORD, 0);
  28.     HWND hwndConfirm = GetDlgItem(hwnd, IDC_CONFIRMPASSWORD);
  29.     SendMessage(hwndConfirm, EM_SETLIMITTEXT, MAX_PASSWORD, 0);
  30.     // Populate the username field and set focus to password
  31.     SetWindowText(hwndUsername, m_pszUsername);
  32.     SetFocus(hwndPassword);
  33.     BOOL fSetDefaultFocus = FALSE;
  34.     TraceLeaveValue(fSetDefaultFocus);
  35. }
  36. BOOL CAutologonUserDlg::OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  37. {
  38.     TraceEnter(TRACE_USR_CORE, "CAutologonUserDlg::OnCommand");
  39.     switch (id)
  40.     {
  41.     case IDOK:
  42.         {
  43.             TCHAR szUsername[MAX_USER + 1];
  44.             TCHAR szPassword[MAX_PASSWORD + 1];
  45.             TCHAR szConfirm[MAX_PASSWORD + 1];
  46.             FetchText(hwnd, IDC_USER,
  47.                 szUsername, ARRAYSIZE(szUsername));
  48.             GetWindowText(GetDlgItem(hwnd, IDC_PASSWORD),
  49.                 szPassword, ARRAYSIZE(szPassword));
  50.             GetWindowText(GetDlgItem(hwnd, IDC_CONFIRMPASSWORD),
  51.                 szConfirm, ARRAYSIZE(szConfirm));
  52.             if (StrCmp(szConfirm, szPassword) != 0)
  53.             {
  54.                 // Display a message saying the passwords don't match
  55.                 DisplayFormatMessage(hwnd, IDS_USR_APPLET_CAPTION, 
  56.                     IDS_ERR_PWDNOMATCH, MB_OK | MB_ICONERROR);
  57.                 break;
  58.             }
  59.             else
  60.             {
  61.                 // Actually apply the autologon
  62.                 SetAutoLogon(szUsername, szPassword);
  63.                 ZeroMemory(szPassword, ARRAYSIZE(szPassword));
  64.             }
  65.         }
  66.         
  67.         // Fall through
  68.     case IDCANCEL:
  69.         EndDialog(hwnd, id);
  70.     }
  71.     TraceLeaveValue(TRUE);
  72. }