#define SCREEN_WIDTH 700
#define SCREEN_HEIGHT 600
#define TIMER_ID 100
#define ID_BUTTON1 1
#define ID_BUTTON2 2
#define ID_BUTTON3 3
#define ID_VALUEFIELD1 4
#include <windows.h>
#include <tchar.h>
TCHAR className[] = TEXT("NazwaKlasy");
TCHAR appName[] = TEXT("Stoperan");
HWND hwnd;
MSG msg;
void Ustaw_czas (HWND &hwnd, unsigned int milisekundy)
{
unsigned int ms = 0, s = 0, min = 0;
if (milisekundy / 60000 >= 1)
{
min = milisekundy / 60000;
milisekundy = milisekundy - (60000 * min);
}
if (milisekundy / 1000 >= 1)
{
s = milisekundy / 1000;
milisekundy = milisekundy - (1000* s);
}
ms = milisekundy;
wchar_t Bufor[255];
_swprintf (Bufor, L"%d : %d : %d", min , s , ms);
SetWindowText (hwnd,Bufor);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static RECT R;
static bool Odliczaj=false;
static SYSTEMTIME czas, czas_odniesienia;
static unsigned int ms = 0 ,s = 0,min = 0, czas_poprzedni = 0;
static HWND ValueField, BUTTON3, BUTTON2, BUTTON1;
switch (msg)
{
case WM_CREATE:
{
SetTimer (hwnd,TIMER_ID, 1, NULL);
GetClientRect (hwnd,&R);
HINSTANCE &hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
ValueField = CreateWindowEx (0,L"STATIC",L"00:00:000",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_VALUEFIELD1, hInstance,0);
if (ValueField==0)
{
MessageBox (hwnd,L"Problem z ValueField", className, MB_OK);
return 1;
}
BUTTON1 = CreateWindowEx (0,L"BUTTON",L"Start",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON1, hInstance,0);
if (!BUTTON1)
{
MessageBox (hwnd,L"Problem z BUTTON1", className, MB_OK);
return 1;
}
BUTTON2 = CreateWindowEx (0,L"BUTTON",L"Stop",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON2, hInstance,0);
if (!BUTTON2)
{
MessageBox (hwnd,L"Problem z BUTTON2", className, MB_OK);
return 1;
}
BUTTON3 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON3, hInstance,0);
if (!BUTTON2)
{
MessageBox (hwnd,L"Problem z BUTTON3", className, MB_OK);
return 1;
}
}break;
case WM_TIMER:
{
if (Odliczaj)
{
GetLocalTime (&czas);
ms = ms + ((czas.wMinute - czas_odniesienia.wMinute) * 60000 ) + ( (czas.wSecond - czas_odniesienia.wSecond) * 1000 ) + (czas.wMilliseconds - czas_odniesienia.wMilliseconds) - czas_poprzedni;
czas_poprzedni = ( (czas.wMinute - czas_odniesienia.wMinute) * 60000 ) + ( (czas.wSecond - czas_odniesienia.wSecond) * 1000 ) + (czas.wMilliseconds - czas_odniesienia.wMilliseconds) ;
Ustaw_czas (ValueField, ms);
}
}break;
case WM_SIZE:
{
GetClientRect(hwnd, &R);
MoveWindow(ValueField, R.right / 3, R.bottom / 3, R.right / 7, R.bottom / 15, 1);
MoveWindow(BUTTON1, R.right / 3, R.bottom / 2.5 + 10, R.right / 7, R.bottom / 15, 1);
MoveWindow(BUTTON2, R.right / 2, R.bottom / 2.5 + 10, R.right / 7, R.bottom / 15, 1);
MoveWindow(BUTTON3, R.right / 2, R.bottom / 3, R.right / 7, R.bottom / 15, 1);
}break;
case WM_GETMINMAXINFO:
((MINMAXINFO*)lParam)->ptMinTrackSize.x = 550;
((MINMAXINFO*)lParam)->ptMinTrackSize.y = 400;
((MINMAXINFO*)lParam)->ptMaxTrackSize.x = 1000;
((MINMAXINFO*)lParam)->ptMaxTrackSize.y = 900;
break;
case WM_COMMAND:
switch (wParam)
{
case ID_BUTTON1:
czas_poprzedni = 0;
Odliczaj = true;
GetLocalTime(&czas_odniesienia);
break;
case ID_BUTTON2:
Odliczaj = false;
break;
case ID_BUTTON3:
ms = 0;
czas_poprzedni = 0;
Odliczaj = false;
Ustaw_czas(ValueField, ms);
break;
}break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
{
KillTimer(hwnd, TIMER_ID);
PostQuitMessage(0);
}break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpfnWndProc = WndProc;
wc.lpszClassName = className;
wc.lpszMenuName = NULL;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if (RegisterClassEx(&wc) == 0)
{
MessageBox(NULL, L"wc", className, MB_OK);
return 1;
}
hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_CLIENTEDGE, className, appName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, hInstance, 0);
if (hwnd == NULL)
{
MessageBox(NULL, L"hwnd", className, MB_OK);
return 1;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass(className, hInstance);
return msg.wParam;
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎