#include<windows.h> LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; HFONT hfont, ohfont; static HWND hwndedit, hedit, hwndButton; switch(message) { case WM_CREATE: //应用程序建立一个窗口 hwndedit = CreateWindow( TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 90, 60, 150, 30, hwnd, NULL, NULL, NULL); hedit = CreateWindow( TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 90, 100, 150, 30, hwnd, NULL, NULL, NULL); hwndButton = CreateWindow( TEXT("button"), TEXT("安全登录"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 90, 200, 80, 28, hwnd, NULL, NULL, NULL); return 0; case WM_COMMAND: //处理点击按钮、菜单等控件时的触发消息 if( (HWND)lParam == hwndButton ) { MessageBox( hwnd, TEXT("登录测试成功!"), TEXT("测试"), MB_ICONINFORMATION | MB_OK); } return 0; case WM_PAINT: //重新自我绘制 hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; hfont = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "微软雅黑"); ohfont=SelectObject(hdc,hfont); TextOut(hdc, 20, 60, "账户:", 5); TextOut(hdc, 20, 100, "密码:", 5); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: //当窗口关闭时产生的原因 PostQuitMessage(0); //产生WM_QUIT消息 return 0; case WM_CLOSE: DestroyWindow(hwnd); return 0; } return DefWindowProc(hwnd,message,wParam,lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { static TCHAR szAppName[] = TEXT ("DARKCHII"); HWND hwnd; HBRUSH hbrh; MSG msg; WNDCLASS wndclass; hbrh=CreateSolidBrush(RGB(255,255,255)); wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hbrBackground = hbrh; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WndProc; wndclass.lpszClassName = szAppName; wndclass.lpszMenuName = NULL; wndclass.style = CS_HREDRAW|CS_VREDRAW; if(!RegisterClass (&wndclass)) { MessageBox(NULL,TEXT("注册窗口失败!"),szAppName,MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, "DarkChii", WS_OVERLAPPEDWINDOW, 640, //窗口的初始位置左边距 180, //窗口的初始位置顶边距 280, 380, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
运行效果:
时间: 2024-10-26 09:08:40