问题描述
- 我想单击一个按钮弹出一个MessageBox对话框,但是我单击之后什么也没有,求解?
-
下面是我的代码:#include
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
struct
{
int iStyle;
TCHAR * szText;
}
button[] =
{
BS_PUSHBUTTON, TEXT("插入"),
BS_PUSHBUTTON, TEXT("删除"),
BS_PUSHBUTTON, TEXT("查找"),
BS_PUSHBUTTON, TEXT("退出"),
BS_PUSHBUTTON, TEXT("帮助")};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int cxscreen = GetSystemMetrics(SM_CXSCREEN);
int cyscreen = GetSystemMetrics(SM_CYSCREEN);
static TCHAR szAppName[] = TEXT("studentadministratorsystem");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("学生信息管理系统"), WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP, cxscreen/2-279/2, cyscreen/2-392/2, 279, 392, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton[5];
static int cxClient, cyClient;
static int cxChar, cyChar;int i,inity=88;
switch (message) { case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); return 0; case WM_CREATE: for (i = 0; i < 5;i++) hwndButton[0] = CreateWindow( TEXT("button"),button[i].szText,WS_CHILD | WS_VISIBLE | button[0].iStyle,60,inity+39*(i),159,33,hwnd, (HMENU)i, ((LPCREATESTRUCT)lParam)->hInstance, NULL); return 0; case WM_COMMAND: if (wParam ==0 ) switch (HIWORD(lParam)) { case BN_PUSHED: //按下 MessageBox(hwnd, "按下按钮", "", 0); break; } break; return 0; case WM_PAINT: return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam);
}