Rieccomi: come si crea un bottone? Cosa c'è di sbagliato in questo:
codice:
#include <stdio.h>
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int RegisterDefaultClass(HINSTANCE hInstance);
HWND window;
HWND button;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
if (!(RegisterDefaultClass(hInstance)))
{
return 1;
}
window = CreateWindow (
"defaultClass",
"Window!!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
250,
250,
(HWND) NULL,
(HMENU) NULL,
hInstance,
NULL
);
if (!window)
{
return 1;
}
button = CreateWindow (
"Button",
"Button!!",
0,
2,
2,
50,
50,
window,
(HMENU) NULL,
hInstance,
NULL
);
if (!button)
{
return 2;
}
ShowWindow(window, SW_SHOW);
UpdateWindow(window);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int RegisterDefaultClass(HINSTANCE hInstance)
{
const char g_szClassName[] = "defaultClass";
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!(RegisterClassEx(&wc)))
{
return 0;
}
}
?
Si vede solo la finestra ma non il bottone o.O