1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
BOOL CALLBACK
ConnectDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch(uMsg)
{
case WM_INITDIALOG:
{
HWND hwndOK = GetDlgItem(hwndDlg, IDOK);
_ASSERTE(NULL != hwndOK);
EnableWindow(hwndOK, FALSE);
return TRUE;
}
// break not needed
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
int wmEvent = HIWORD(wParam);
switch(wmId)
{
case IDOK:
{
const char RUsername[] = "SEnergy";
const char RPassword[] = "pw";
char Username[256] = "";
char Password[256] = "";
GetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, Username, sizeof(Username)/sizeof(char));
GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD, Password, sizeof(Password)/sizeof(char));
if(lstrcmp(RUsername, Username) == 0 && lstrcmp(RPassword, Password) == 0)
{
EndDialog(hwndDlg, IDOK);
}
else
{
MessageBox(hwndDlg, "Invalid Username or Password!", g_appName, MB_ICONERROR);
}
return TRUE;
}
break;
case IDCANCEL:
{
EndDialog(hwndDlg, IDCANCEL);
return TRUE;
}
break;
case IDC_EDIT_USERNAME:
case IDC_EDIT_PASSWORD:
{
if(EN_CHANGE == wmEvent)
{
HWND hwndOK = GetDlgItem(hwndDlg, IDOK);
_ASSERTE(NULL != hwndOK);
char Username[256] = "";
char Password[256] = "";
GetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, Username, sizeof(Username)/sizeof(char));
GetDlgItemText(hwndDlg, IDC_EDIT_PASSWORD, Password, sizeof(Password)/sizeof(char));
BOOL bEnable = (0 < lstrlen(Username)) && (0 < lstrlen(Password));
EnableWindow(hwndOK, bEnable);
}
}
break;
default:
{
}
}
}
break;
default:
{
}
}
return FALSE;
}
|