在windows环境下用c语言做一个简单的GUI,新手当然是用win32API啊
其实是我的作业,我提出的负责前端
原本想做网页的,但是c语言进行网络编程,没找到什么教程啊
主要代码
main函数
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
| int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc = {0}; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW); wc.lpszClassName = Appname;
RegisterClass(&wc);
g_hMainWnd = CreateWindowExA( 0, Appname, Appname, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
ShowWindow(g_hMainWnd, nCmdShow); UpdateWindow(g_hMainWnd);
MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }
|
窗口过程函数
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
| LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { All_Page_Init(hWnd); All_PAge_hide(hWnd); Login_Page_show(hWnd); break; } case WM_COMMAND: { switch (LOWORD(wParam)) { case ID_LOGIN_BUTTON: { char username[24], password[10]; GetWindowTextA(g_hUsernameEdit, username, 24); GetWindowTextA(g_hPasswordEdit, password, 10);
switch (Login_Check(username, password)) { case Employee_Login: { Login_Page_hide(hWnd); Employee_Page_show(hWnd); break; } case Id_Not_Found: { SetWindowText(g_hLoginAlert, "账号未注册"); break; } case Password_Error: { SetWindowText(g_hLoginAlert, "密码错误"); break; } default: { MessageBox(hWnd, "Invalid username or password", "Error", MB_OK | MB_ICONERROR); break; } } break; } case ID_REGISTER_BUTTON: { Login_Page_hide(hWnd); Regist_Page_show(hWnd); break; } default: break; } break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
|