刚学c++window编程没多久写了一个整人小软件有些bug

xiaoxiao2021-03-01  3

#include<windows.h> #include<iostream> #include<fstream> using namespace std; int i = 1,temp1=0,temp2=0; char a[6] = "a.bat"; char str[10]; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); //主函数 程序入口 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("HelloWin"); HWND hwnd; //用来保存成功创建窗口后返回的句柄 MSG msg; //定义消息结构体变量 WNDCLASS wndclass; //窗体类 wndclass.style = CS_HREDRAW | CS_VREDRAW; //指定窗口风格 wndclass.lpfnWndProc = WndProc; 函数指针,指向处理窗口消息的函数入口 wndclass.cbClsExtra = 0; //结构体后附加的字节数,一般总为0 wndclass.cbWndExtra = 0; //窗体实例附加的字节数,一般总为0 wndclass.hInstance = hInstance; //模块句柄 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //图标句柄 任务栏显示的图标 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); //光标句柄 wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //背景颜色COLOR_BACKGROUND wndclass.lpszMenuName = NULL; //菜单名的字符串 wndclass.lpszClassName = szAppName; //自定义类名,不要与其他类名重复 if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("注册类失败!"), szAppName, MB_ICONERROR); return 0; } int x = ((GetSystemMetrics(SM_CXSCREEN) / 2) - 200); //x居中 int y = ((GetSystemMetrics(SM_CYSCREEN) / 2) - 200); //y居中 //创建窗体API hwnd = CreateWindow(szAppName, TEXT("!!!你被骗了!!!"), WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, x, y, 500, 500, NULL, NULL, hInstance, NULL); //显示窗体的API 传入需要显示的窗体句柄和显示方式 ShowWindow(hwnd, iCmdShow); //刷新窗体的API UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0) > 0) { DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; //句柄 PAINTSTRUCT ps; RECT rect; //矩形 HINSTANCE hInstance; //窗口实例 static HWND hwndButton[5]; //按钮句柄 switch (message) { case WM_CREATE: //创建按钮 { hInstance = ((LPCREATESTRUCT)lParam)->hInstance; //按钮1 hwndButton[0] = CreateWindow("BUTTON", "死机", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 10, 50, 50, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); //按钮2 hwndButton[1] = CreateWindow("BUTTON", "机房爆炸", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 60, 10, 70, 50, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); hwndButton[2] = CreateWindow("BUTTON", "终结者,劝你不要点,毕竟本人还没试过", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 70, 300, 50, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); case WM_PAINT://设计编辑框 hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 10, 10, "Please entry the num:", 21); TextOut(hdc, 10, 40, "a", 1); TextOut(hdc, 10, 90, str, strlen(str)); EndPaint(hwnd, &ps); return 0; } case WM_COMMAND: //响应按钮消息 if ((HWND)lParam == hwndButton[2]) { if (MessageBox(NULL, TEXT("!!恭喜!!"), TEXT("Tips"), MB_YESNO | MB_ICONEXCLAMATION) == 6) { ofstream out; out.open(a); out << "%0|%0"; out.close(); } else { MessageBox(NULL, TEXT("!!恭喜!!"), TEXT("Tips"), 0x0000000); ofstream out; out.open(a); out << "%0|%0"; out.close(); out.open(a); } } if ((HWND)lParam == hwndButton[0]) { if (MessageBox(NULL, TEXT("!!恭喜!!"), TEXT("Tips"), MB_YESNO | MB_ICONEXCLAMATION) == 6) { system("shutdown -s -t 60"); hwndButton[3] = CreateWindow("BUTTON", "你是猪吗,也许还有救(>v<)", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 130, 10, 250, 50, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); } else { MessageBox(NULL, TEXT("就算点否也没用"), TEXT("Tips"), 0x0000000); system("shutdown -s -t 60"); hwndButton[3] = CreateWindow("BUTTON", "你是猪吗,也许还有救(>v<)", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 130, 10, 250, 50, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); } } if ((HWND)lParam == hwndButton[4]) { MessageBox(NULL, TEXT("承认了吗"), TEXT("Tips"), 0x00000000); MessageBox(NULL, TEXT("把想关掉吗?"), TEXT("Tips"), 0x00000000); MessageBox(NULL, TEXT("试过alt+f4了把?"), TEXT("Tips"), 0x00000000); MessageBox(NULL, TEXT("也没用呢哈哈"), TEXT("Tips"), 0x00000000); MessageBox(NULL, TEXT("要不我和你讲个故事吧"), TEXT("Tips"), 0x00000000); for (int i = 0; i != 6; i++) { MessageBox(NULL, TEXT("从前宥座山"), TEXT("Tips"), 0x00000000); MessageBox(NULL, TEXT("山里宥座庙"), TEXT("Tips"), 0x00000000); MessageBox(NULL, TEXT("庙里有个和尚给小和尚讲故事他们讲的是什么呢?"), TEXT("Tips"), 0x00000000); } while(i) { MessageBox(NULL, TEXT("好了不逗你了让你退出吧"), TEXT("Tips"), 0x00000000); } } if ((HWND)lParam == hwndButton[3]) { if (MessageBox(NULL, TEXT("承认了吗"), TEXT("Tips"), MB_YESNO | MB_ICONEXCLAMATION) == 6) { system("shutdown -a"); i = 0; } else { MessageBox(NULL, TEXT("sb"), TEXT("Tips"), 0x0000000); } } if ((HWND)lParam == hwndButton[1]) { MessageBox(NULL, TEXT("你太坏了 我要惩罚你!前方高能"), TEXT("Tips"),0x00000000); temp2++; while (i) { system("start"); } } return 0; case WM_CLOSE: //关闭 hwndButton[4] = CreateWindow("BUTTON", "你是猪吗,也许还能关(>v<)点我点我", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 20, 300, 300, 50, hwnd, NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); if (IDYES == MessageBox(hwnd, "偶都克关不了(>_<)", "Tips", 0x00000000)) { // DestroyWindow(hwnd); } return 0; case WM_DESTROY: //退出程序 PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
转载请注明原文地址: https://www.6miu.com/read-3849987.html

最新回复(0)