⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.c

📁 MiniGUI图形界面实验系列之控件应用实验例程。
💻 C
字号:
// 系统登录窗口#include <string.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>HWND hMainWnd;#define  IDC_SLOGIN	300#define  IDC_SUSER	301#define  IDC_SPASS	302#define  IDC_EUSER	401#define  IDC_EPASS	402// 定义对话框static  DLGTEMPLATE  MyDlg ={   WS_BORDER | WS_CAPTION,    WS_EX_NONE,    2, 50, 235, 190,    "登录",     0,     0,    6,     NULL,    0    };// 定义对话框中的控件static CTRLDATA CtrlInitData[] = {       {   "static",        WS_VISIBLE | SS_SIMPLE,	25,10,  200, 16,	IDC_SLOGIN,	"请输入用户名和密码.",	0,        WS_EX_NONE    },    {   "static",        WS_VISIBLE | SS_SIMPLE,	10,40,  60, 16,	IDC_SUSER,	"用户名:",	0,        WS_EX_NONE    },    {   "static",        WS_VISIBLE | SS_SIMPLE,	10,80,  60, 16,	IDC_SPASS,	"密码:",	0,        WS_EX_NONE    },    {   "edit",       WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,       70,40,  140,25,       IDC_EUSER,       "",       0,       WS_EX_NONE    },      {   "edit",       WS_CHILD | WS_VISIBLE | WS_BORDER | ES_PASSWORD | WS_TABSTOP,       70,80, 140,25,       IDC_EPASS,       "",       0,       WS_EX_NONE    },    {  "button",       WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON,       80,120,  80,25,       IDOK,       "确定",       0,       WS_EX_NONE    }};#define  USER_NO	3static char *g_user[USER_NO] = {"root",			      "51",			      "WXM"			     };static char *g_pass[USER_NO] = {"******",			      "888888",			      "2046"			     };static BOOL CheckUser(char *user, char *pass){  int  i;     if(USER_NO==0) return(TRUE);	// 不启用密码   for(i=0; i<USER_NO; i++)   {  if(strcmp(user, g_user[i]) == 0)      {  if(strcmp(pass, g_pass[i]) == 0) return(TRUE);           else  return(FALSE);      }   }	   return(FALSE);}static int  MyDlgProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam){   char  user[30];    char  pass[30];    switch(message)    {   case MSG_INITDIALOG:           return(1);	          case MSG_COMMAND:	   switch(LOWORD(wParam))	   {   case IDC_EUSER:			// 处理控件的通知消息(EN_ENTER)               case IDC_EPASS:                  if(HIWORD(wParam) != EN_ENTER) break;	       case IDOK:		  // 读取编辑框的输入		  GetWindowText(GetDlgItem(hDlg, IDC_EUSER), user, 22);                  GetWindowText(GetDlgItem(hDlg, IDC_EPASS), pass, 22);		  if(CheckUser(user, pass))	          {  EndDialog(hDlg, wParam);                     DestroyAllControls(hDlg);		  }		  else		  {  MessageBox(hDlg, "密码错误!", "校验错误", MB_OK | MB_ICONHAND);		  }		  break;	       default:           	  break;	   }	   break;	default:           break;    }       return(DefaultDialogProc(hDlg, message, wParam, lParam));}static void  LoginBox(HWND hWnd){   MyDlg.controls = CtrlInitData;    DialogBoxIndirectParam(&MyDlg, hWnd, MyDlgProc, 0L);}static char *hello_str = "欢迎登录系统!";static int  WinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){   HDC  hdc;        switch(message)    {  case MSG_PAINT:	  hdc = BeginPaint(hWnd);	  TextOut(hdc, 50, 50, hello_str);	  EndPaint(hWnd, hdc);	  break;       case MSG_CLOSE:	  DestroyMainWindow(hWnd);	  PostQuitMessage(hWnd);	  break;       default:	  return(DefaultMainWinProc(hWnd, message, wParam, lParam));    }    return(0);}int InitMainWindow(void){   MAINWINCREATE  window_info;    window_info.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION;    window_info.dwExStyle = WS_EX_NONE;    window_info.spCaption = "MiniGUI";    window_info.hMenu = 0;    window_info.hCursor = GetSystemCursor(0);    window_info.hIcon = 0;    window_info.MainWindowProc = WinProc;    window_info.lx = 2;    window_info.ty = 50;    window_info.rx = 238;    window_info.by = 200;    window_info.iBkColor = COLOR_lightwhite;    window_info.dwAddData = 0;    window_info.hHosting = HWND_DESKTOP;         hMainWnd = CreateMainWindow (&window_info);    if (hMainWnd == HWND_INVALID) return(0);      else  return(1);}int  MiniGUIMain(int argc, const char *argv[]){   MSG Msg;#ifdef _LITE_VERSION    SetDesktopRect(0,0, 800,600);#endif    LoginBox(HWND_DESKTOP);    InitMainWindow();    ShowWindow(hMainWnd, SW_SHOWNORMAL);    while (GetMessage(&Msg, hMainWnd))     {   TranslateMessage(&Msg);        DispatchMessage(&Msg);    }        MainWindowThreadCleanup (hMainWnd);    return(0);}#ifndef _LITE_VERSION	#include <minigui/dti.c>#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -