#include<windows.h>
#define NUM 5
#define GROUPBOX NUM+1
#define PUSHBUTTON1 NUM+2
#define PUSHBUTTON2 NUM+3
#define PUSHBUTTON3 NUM+4
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
static TCHAR szAppName[] = TEXT("翻牌子");
HWND hwnd=0;
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(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(hwnd, TEXT("抱歉,本程序需要在Windows NT上运行!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, TEXT("赛博选妃"),
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
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[NUM];
static RECT rect;
const TCHAR* Name[] = { TEXT("王昭君"),TEXT("貂蝉"),TEXT("西施"),TEXT("杨玉环"),TEXT("AAA") };
static int cxChar, cyChar;
HDC hdc;
PAINTSTRUCT ps;
int i;
switch (message)
{
case WM_CREATE:
cxChar = LOWORD(GetDialogBaseUnits());
cyChar = HIWORD(GetDialogBaseUnits());
GetWindowRect(hwnd, &rect);
MoveWindow(hwnd, rect.left, rect.top, 27 * cxChar, 13 * cyChar, TRUE);
for ( i = 0; i < NUM-1; i++)
{
hwndButton[i]= CreateWindow(TEXT("BUTTONS"),
Name[i],
BS_AUTORADIOBUTTON|WS_VISIBLE| WS_CHILD,
2*cxChar, cyChar * (2+2*i),
10* cxChar, 7 * cyChar/4,
hwnd, (HMENU)i,
((LPCREATESTRUCT)lParam)->hInstance, NULL);
}
//CreateWindow(TEXT("BUTTONS"),
// TEXT("美女们"),
// BS_GROUPBOX | WS_CHILD | WS_VISIBLE,
// cxChar, cyChar / 2,
// 12 * cxChar, 10 * cyChar,
// hwnd, (HMENU)GROUPBOX,
// ((LPCREATESTRUCT)lParam)->hInstance, NULL);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
代码如上,理论上讲应该会出现四个按钮,但是运行起来并没有按钮。
运行结果如图
请问哪一步做错了导致这样的结果呢?