Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <time.h>
- #include <string>
- using namespace std;
- bool bStart = false, bPauze = false;
- HWND _TEXT;
- clock_t timeStart, timeEnd;
- HWND _START, _STOP, _SUBTIME;
- string TimeText(int MS) {
- return to_string((MS / 3600000)) + ":" + to_string((MS / 60000) - ((MS / 3600000) * 60)) + ":" +
- to_string((MS / 1000) - ((MS / 60000) * 60)) + ":" + to_string(MS - ((MS / 1000) * 1000));
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- switch (msg) {
- case WM_TIMER:
- if (bStart && !bPauze)
- timeEnd = clock();
- SetWindowText(_TEXT, TimeText(timeEnd - timeStart).c_str());
- break;
- case WM_COMMAND:
- switch (wParam) {
- case 100:
- if (!bStart) {
- timeStart = clock();
- bStart = true;
- SetWindowText(_START, "Stop");
- EnableWindow(_STOP,1);
- EnableWindow(_SUBTIME, 1);
- }
- else if (bStart) {
- bStart = false;
- SetWindowText(_START, "Start");
- EnableWindow(_SUBTIME, 0);
- EnableWindow(_STOP, 0);
- }
- break;
- case 101:
- if (!bPauze) {
- bPauze = true;
- SetWindowText(_STOP, "Wznów");
- EnableWindow(_START, 0);
- EnableWindow(_SUBTIME, 0);
- }
- else if (bPauze) {
- bPauze = false;
- SetWindowText(_STOP, "Pauza");
- EnableWindow(_START, 1);
- EnableWindow(_SUBTIME, 1);
- }
- break;
- case 102:{ Sleep(2000); } break;
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- break;
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
- WNDCLASSEX window;
- MSG msg;
- TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(NULL, IDC_HAND);
- window.hIcon = LoadIcon(NULL, IDI_INFORMATION);
- window.hIconSm = NULL;
- window.hInstance = hInstance;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = CS_VREDRAW | CS_HREDRAW;
- RegisterClassEx(&window);
- HWND hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- _START = CreateWindowEx(0, "BUTTON", "Start", WS_CHILD | WS_VISIBLE, 10, 10, 150, 30, hwnd, (HMENU)100, hInstance, NULL);
- _STOP = CreateWindowEx(0, "BUTTON", "Pauza", WS_CHILD | WS_VISIBLE, 10, 45, 150, 30, hwnd, (HMENU)101, hInstance, NULL);
- _SUBTIME = CreateWindowEx(0, "BUTTON", "Miedzyczas", WS_CHILD | WS_VISIBLE, 10, 80, 150, 30, hwnd, (HMENU)102, hInstance, NULL);
- _TEXT = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_DISABLED | ES_MULTILINE | ES_AUTOVSCROLL, 165, 10, 200, 65, hwnd, (HMENU)102, hInstance, NULL);
- SetTimer(hwnd, NULL, 20, NULL);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- UnregisterClass(Class_Name, hInstance);
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement