#include <windows.h>
LRESULT CALLBACK Moje_Smycka_Zprav(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdline, int nCmdShow)
{
char *szAppName = "Ahoj !";
WNDCLASSEX wndclass;
HWND hwnd;
MSG msg;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = Moje_Smycka_Zprav;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wndclass.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
RegisterClassEx(&wndclass);
hwnd = CreateWindow(szAppName,
"Ahoj",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, // pozice
320, 200, // rozmery
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// zobrazi okno
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// smyčka zpráv
return msg.wParam;
}
LRESULT CALLBACK Moje_Smycka_Zprav(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
switch(iMsg) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
// Začátek kreslení
GetClientRect(hwnd, &rect);
// Načte rozměry okna
DrawText(hdc, "Willy je silnější než ty !", -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
// vypíše text
EndPaint (hwnd, &ps);
// konec kreslení
case WM_KEYDOWN:
if(wParam == 27)
PostMessage(hwnd, WM_CLOSE, 0, 0); // Escape
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
|