?? login.c
字號(hào):
/***************************************************************************** 文件名:Login.C* 功能:MiniGUI應(yīng)用例子。* 使用MiniGUI的靜態(tài)框、按鈕和編輯框控件,實(shí)現(xiàn)一個(gè)Login系統(tǒng)登錄對話框。 * 說明:使用MiniGUI for uC/OS-II,使用ADS 1.2編譯器。****************************************************************************//* 包含MiniGUI的配置頭文件(編譯配置選項(xiàng)) */#include "MiniGUI_config.h"/* 包含MiniGUI頭文件 */#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include <string.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, "密碼錯(cuò)誤!", "校驗(yàn)錯(cuò)誤", MB_OK | MB_ICONHAND); SetWindowText(GetDlgItem(hDlg, IDC_EUSER), ""); SetWindowText(GetDlgItem(hDlg, IDC_EPASS), ""); } 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 = "歡迎登錄系統(tǒng)!";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 "dti.c"#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -