Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <Windows.h>
- #include "stdio.h"
- #include <ctime>
- #define ID_START 501
- #define ID_STOP 502
- #define ID_ZERUJ 503
- TCHAR Class_Name[] = TEXT("OKNO_TEST");
- MSG Komunikat;
- int zmienna = 0;
- char ilosc[128];
- HINSTANCE *hInst;
- HWND okno1, okno2;
- bool start = false; // stan timera wlaczony lub wylaczony
- bool miedzyczas = false;
- int odlicz =0;
- HWND pole, p_start, p_stop, p_zeruj; // uchwyty dla przycisków i kontrolek
- WORD ID_TIMER = 1; // deklaracja poczatkowa timera
- int s = 0; // sekundy minuty godziny
- int m = 0;
- int g = 0;
- WCHAR wyswietl[32];
- void DodajCzas() {
- if (s < 59)
- s++;
- else
- {
- s = 0;
- m++;
- }
- if (m > 59)
- {
- m = 0;
- g++;
- }
- wsprintf(wyswietl, TEXT("%2.2d:%2.2d:%2.2d"),g,m, s);
- SetWindowText(pole,wyswietl);
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg) {
- case WM_CREATE:
- if (SetTimer(hwnd, ID_TIMER, 10, NULL) == 0)
- MessageBox(hwnd, TEXT("Nie można utworzyć timera!"), TEXT("Kurde"), MB_ICONSTOP);
- break;
- case WM_TIMER:
- if (start == true)
- DodajCzas();
- if (miedzyczas == true)
- {
- //odlicz
- }
- break;
- case WM_LBUTTONDOWN:
- break;
- case WM_CLOSE:
- if ((MessageBox(hwnd, TEXT("Czy chcesz wyłączyć okno ?"), TEXT("Pytanie"), MB_OKCANCEL)) == IDOK)
- DestroyWindow(hwnd);
- else break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_COMMAND:
- switch (wParam)
- {
- case ID_START:
- if (start == false)
- {
- start = true;
- SetWindowText(p_start, TEXT("STOP"));
- }
- else
- {
- start = false;
- SetWindowText(p_start, TEXT("start"));
- }
- break;
- case ID_STOP:
- start = false;
- break;
- case ID_ZERUJ:
- start = false;
- s = 0;
- m = 0;
- g = 0;
- wsprintf(wyswietl, TEXT("%2.2d:%2.2d:%2.2d"), g, m, s);
- SetWindowText(pole, wyswietl);
- break;
- default:
- MessageBox(hwnd, TEXT("Zrobiłeś coś innego ;-)"), TEXT("Test"), MB_ICONINFORMATION);
- }
- break;
- default:
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- hInst = &hInstance;
- WNDCLASSEX window;
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(*hInst, IDC_ARROW);
- window.hIcon = LoadIcon(*hInst, IDI_APPLICATION);
- window.hIconSm = NULL;
- window.hInstance = *hInst;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = NULL;
- if (!RegisterClassEx(&window)) {
- MessageBox(NULL, TEXT("Zarejestrowanie klasy nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
- return 1;
- }
- okno1 = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, TEXT("Najlepszy stoper ever!!!"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, *hInst, NULL);
- if (okno1 == NULL) {
- MessageBox(NULL, TEXT("Stworzenie okna nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
- return 2;
- }
- pole = CreateWindowEx(0, TEXT("STATIC"), TEXT("00:00:00"), WS_CHILD | WS_VISIBLE , 100, 100, 150, 30, okno1, NULL, hInstance, NULL);
- p_start = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Start"), WS_CHILD | WS_VISIBLE, 100, 150, 150, 30, okno1, (HMENU)ID_START, hInstance, NULL);
- p_stop = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Stop"), WS_CHILD | WS_VISIBLE, 100, 190, 150, 30, okno1, (HMENU)ID_STOP, hInstance, NULL);
- p_zeruj = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Zeruj"), WS_CHILD | WS_VISIBLE, 100, 240, 150, 30, okno1, (HMENU)ID_ZERUJ, hInstance, NULL);
- ShowWindow(okno1, nCmdShow);
- UpdateWindow(okno1);
- while (GetMessage(&Komunikat, NULL, 0, 0)) {
- TranslateMessage(&Komunikat);
- DispatchMessage(&Komunikat);
- }
- UnregisterClass(Class_Name, *hInst);
- return Komunikat.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement