codice:
#include <stdio.h>
#include <windows.h>
#define BUTTON 1001
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int RegisterDefaultClass(HINSTANCE hInstance);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND window;
HWND button;
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",
"Hello!",
WS_CHILD|
WS_VISIBLE,
2,
2,
90,
20,
window,
BUTTON,
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;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case BUTTON:
MessageBox(hwnd, "Hello, World!", "Bottone premuto", MB_OK);
break;
}
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;
}
}