Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <math.h>
- #include <list>
- #include <stdio.h>
- using namespace std;
- LPCSTR NazwaKlasy = TEXT("Klasa Okienka");
- MSG Komunikat;
- HDC hdc;
- HWND hwnd;
- RECT Rect;
- PAINTSTRUCT ps;
- HWND hText,hButtonStart,hButtonStop,hButtonReset;
- int m, s, ms;
- bool start = NULL;
- char buf[50];
- SYSTEMTIME czasAktualny, czasStartu;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- 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 + 1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = NazwaKlasy;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if (!RegisterClassEx(&wc))
- {
- MessageBox(NULL, TEXT("Nie mozna utworzyc okna"), TEXT("Niestety..."),
- MB_ICONEXCLAMATION | MB_OK);
- return 1;
- }
- hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, NazwaKlasy, TEXT("Oto okienko"), WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 800, 400, NULL, NULL, hInstance, NULL);
- hText = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
- hwnd, NULL, hInstance, NULL);
- hButtonStart = CreateWindowEx(0, "BUTTON", "Start", WS_CHILD | WS_VISIBLE,
- 0, 0, 150, 30, hwnd, NULL, hInstance, NULL);
- hButtonStop = CreateWindowEx(0, "BUTTON", "Stop", WS_CHILD | WS_VISIBLE,
- 0, 0, 150, 30, hwnd, NULL, hInstance, NULL);
- hButtonReset = CreateWindowEx(0, "BUTTON", "Reset", WS_CHILD | WS_VISIBLE,
- 0, 0, 150, 30, hwnd, NULL, hInstance, NULL);
- if (hwnd == NULL)
- {
- MessageBox(NULL, TEXT("Okno odmówiło przyjścia na świat!"), TEXT("Ale kicha..."), MB_ICONEXCLAMATION);
- return 1;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&Komunikat, NULL, 0, 0))
- {
- TranslateMessage(&Komunikat);
- DispatchMessage(&Komunikat);
- }
- return Komunikat.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- case WM_COMMAND:
- if ((HWND)lParam == hButtonStart) { start = TRUE; GetLocalTime(&czasStartu); }
- if ((HWND)lParam == hButtonStop) start = NULL;
- if ((HWND)lParam == hButtonReset)
- {
- ms = 0, m = 0, s = 0;
- wsprintf(buf, "%02d:%02d:%02d", m, s, ms);
- SetWindowText(hText, buf);
- }
- break;
- case WM_CREATE:
- SetTimer(hwnd, 1, 10, 0);
- break;
- case WM_TIMER:
- if (start == TRUE)
- {
- GetLocalTime(&czasAktualny);
- int r;
- r = (czasAktualny.wMinute - czasStartu.wMinute) * 60000 + (czasAktualny.wSecond - czasStartu.wSecond) * 1000 + (czasAktualny.wMilliseconds - czasStartu.wMilliseconds);
- m = (r / 60000);
- s = (r % 60000) / 1000;
- ms = ((r % 60000) % 1000) / 100;
- wsprintf(buf, "%02d:%02d:%02d", m,s,ms);
- SetWindowText(hText, buf);
- InvalidateRect(hwnd, 0, 1);
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- KillTimer(hwnd, 1);
- PostQuitMessage(0);
- break;
- case WM_SIZE:
- GetClientRect(hwnd, &Rect);
- MoveWindow(hText, Rect.right / 2 - 75, Rect.bottom / 2 - 50, 150, 50, TRUE);
- MoveWindow(hButtonStart, Rect.right / 2 - 75, Rect.bottom / 2, 50, 25, TRUE);
- MoveWindow(hButtonStop, Rect.right / 2 - 25, Rect.bottom / 2 , 50, 25, TRUE);
- MoveWindow(hButtonReset, Rect.right / 2 + 25, Rect.bottom / 2 , 50, 25, TRUE);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement