weixin_40011552
且听下回分说
2019-03-16 13:21

实现登录界面,自定义用户名和密码

  • c++
  • c语言
  • 开发语言

实现一个登录界面,自定义用户名和密码,然后登录时输入用户名和密码,成功就登录进去,显示主窗口,失败则清空用户输入的用户名和密码,退出就直接退出。
但现在不论输入什么都会清空用户输入
INT_PTR CALLBACK Dialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
CreateWindow(_T("button"), _T("确认"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 70, 100, 30, hDlg, (HMENU)5001, hInst, NULL);
CreateWindow(_T("button"), _T("退出"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
100, 70, 100, 30, hDlg, (HMENU)5002, hInst, NULL);
CreateWindow(_T("edit"), _T("请输入用户:"), WS_CHILD | WS_VISIBLE,
0, 0, 1024, 20, hDlg, (HMENU)6001, hInst, NULL);
CreateWindow(_T("edit"), _T("请输入密码:"), WS_CHILD | WS_VISIBLE,
0, 30, 1024, 20, hDlg, (HMENU)6002, hInst, NULL);
return (INT_PTR)TRUE;

case WM_COMMAND://命令消息
    switch (LOWORD(wParam))
    {
    case 5002:
        EndDialog(hDlg, 0);
        break;
    case 5001:
    {        

                 char str1[20] = {};
                 char str2[20] = {};
                 GetDlgItemTextA(hDlg, 6001, str1, 1024);
                 GetDlgItemTextA(hDlg, 6002, str2, 1024);

                 if (strcmp("1234",str1)==0 && strcmp("4321",str2)==0)
                 {
                     EndDialog(hDlg,0); 
                 }
                else
                 {
                    SetDlgItemText(hDlg, 6001, _T("请输入用户:"));
                    SetDlgItemText(hDlg, 6002, _T("请输入密码:"));                                   
                 }  

    }
        break;
    }

    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
    {
        EndDialog(hDlg, LOWORD(wParam));
        return (INT_PTR)TRUE;
    }
    break;
}
return (INT_PTR)FALSE;

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐