#define ID_INPUTEDIT 1001 #define ID_OK 1002 LRESULT CALLBACK inputBoxWndProc(HWND wndHandle, UINT message, WPARAM wParam, LPARAM lParam) { static char **result = 0; static HWND inputLabelHandle = 0; static HWND inputHandle = 0; switch (message) { case WM_NCCREATE: result = ((CREATESTRUCT *)lParam)->lpCreateParams; break; case WM_CLOSE: case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: int notifyCode = HIWORD(wParam); int controlId = LOWORD(wParam); HWND controlHandle = (HWND)lParam; switch (controlId) { case ID_INPUTEDIT: inputHandle = controlHandle; break; case ID_OK: *result = malloc(256); GetWindowText(inputHandle, *result, 256); PostQuitMessage(0); break; } break; } return DefWindowProc(wndHandle, message, wParam, lParam); } char *inputbox(char *hint) { #define X 5 #define OKBUTTON_WIDTH 75 #define INPUTEDIT_WIDTH (width0 - OKBUTTON_WIDTH) #define INPUTEDIT_Y 29 #define HINT_HEIGHT 24 #define CHAR_WIDTH 8 HWND dialogHandle, inputLabelHandle, inputHandle, okButtonHandle; char *result; WNDCLASS wndClass; int hint_width = strlen(hint) * CHAR_WIDTH, width0 = hint_width + OKBUTTON_WIDTH, height = HINT_HEIGHT + INPUTEDIT_Y + 50; MSG msg; ZeroMemory(&wndClass, sizeof wndClass); wndClass.hCursor = LoadCursor(0, IDC_ARROW); // WndClass.hIcon = LoadIcon(0, IDI_APPLICATION); // wndClass.cbSize = sizeof wndClass; wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = inputBoxWndProc; wndClass.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME; wndClass.lpszClassName = "InputBox"; wndClass.hInstance = GetModuleHandle(0); RegisterClass(&wndClass); dialogHandle = CreateWindow( wndClass.lpszClassName, "Bilibili弹幕反查用户工具", WS_OVERLAPPEDWINDOW, 100, 100, width0 + 50, height, 0, 0, wndClass.hInstance, &result); inputLabelHandle = CreateWindow( "STATIC", hint, WS_CHILD | WS_VISIBLE, X, 5, hint_width, HINT_HEIGHT, dialogHandle, 0, wndClass.hInstance, 0); inputHandle = CreateWindow( "EDIT", "", WS_BORDER | WS_CHILD | WS_VISIBLE, X, INPUTEDIT_Y, INPUTEDIT_WIDTH, 24, dialogHandle, (HMENU)ID_INPUTEDIT, wndClass.hInstance, 0); okButtonHandle = CreateWindow( "BUTTON", "确定", WS_CHILD | WS_VISIBLE, X + INPUTEDIT_WIDTH + 5, INPUTEDIT_Y, OKBUTTON_WIDTH, 24, dialogHandle, (HMENU)ID_OK, wndClass.hInstance, 0); if(dialogHandle == 0) return 0; // 在桌面显示窗口 ShowWindow(dialogHandle, SW_SHOWNORMAL); // 刷新窗口客户区 UpdateWindow(dialogHandle); do { if (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } while (msg.message != WM_QUIT); return result; }