#include<windows.h> #include "resource.h"
BOOL CALLBACK DlgProc(HWND hDlg, UINT message,WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowcmd) {
hInstance=GetModuleHandle(NULL); DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG),NULL,DlgProc); return 0; } BOOL CALLBACK DlgProc(HWND hDlg, UINT message,WPARAM wParam, LPARAM lParam) { TCHAR szUserName[256]=" "; TCHAR szPassword[256]=" "; TCHAR szUN[9]="kanghtta"; TCHAR szPW[8]="7126630"; int count,i; HWND hUser,hPasd; switch(message) { case WM_CLOSE: EndDialog(hDlg,NULL); break; case WM_COMMAND: switch(LOWORD(wParam)) {
case ID_OK: hUser = GetDlgItem(hDlg,IDC_USERNAME); hPasd = GetDlgItem(hDlg,IDC_PASSWARD); count = GetWindowTextLength(hUser); GetWindowText(hUser,szUserName,count+1); for(i = 0; i<=count; i++) { if(szUserName[i]!=szUN[i]) { MessageBox(hDlg,TEXT("用户名错误,请重新输入"),TEXT("错误"),MB_OK); break; } } count = GetWindowTextLength(hPasd); GetWindowText(hPasd,szPassword,count+1); if(count==0) MessageBox(hDlg,TEXT("密码不能为空"),TEXT("错误"),MB_OK); else { for(i = 0; i<=count; i++) { if(szPassword[i]!=szPW[i]) { MessageBox(hDlg,TEXT("密码错误,请重新输入"),TEXT("错误"),MB_OK); break; } } } if(i>=count&&count!=0) MessageBox(hDlg,TEXT("登陆成功"),TEXT("欢迎使用"),MB_OK); else break;
case ID_CANCEL: EndDialog(hDlg,NULL); break;
} } return FALSE; }
|