Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <windowsx.h>
- #include <tchar.h>
- #include <stdlib.h>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- VOID CALLBACK TimerEvent( HWND window, UINT Msg, UINT_PTR EventID, DWORD SYSTime);
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- MSG msg ;
- WNDCLASS wc;
- ZeroMemory(&wc, sizeof(wc));
- wc.lpszClassName = TEXT( "Timer" );
- wc.hInstance = hInstance ;
- wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
- wc.lpfnWndProc = WndProc ;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- RegisterClass(&wc);
- CreateWindow( wc.lpszClassName, TEXT("Stop Watch"),
- WS_SYSMENU | WS_VISIBLE,
- 150, 150, 230, 230, 0, 0, hInstance, 0);
- while( GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int) msg.wParam;
- }
- int GlobTime = 0;
- LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
- {
- static HWND MenuItems[3] = {0};
- switch(msg)
- {
- case WM_CREATE:
- {
- MenuItems[0] = CreateWindow(TEXT("button"), TEXT("Старт"),
- WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
- 120, 150, 80, 25,
- hwnd, (HMENU) 1, NULL, NULL);
- MenuItems[1] = CreateWindow(TEXT("button"), TEXT("Стоп"),
- WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
- 20, 150, 80, 25,
- hwnd, (HMENU) 2, NULL, NULL);
- MenuItems[2] = CreateWindow(TEXT("button"), NULL,
- WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
- 20, 15, 180, 120,
- hwnd, (HMENU) 3, NULL, NULL);
- break;
- }
- case WM_COMMAND:
- {
- if(HIWORD(wParam) == BN_CLICKED)
- {
- if (LOWORD(wParam) == 1)
- {
- GlobTime = 0;
- KillTimer(hwnd, 1);
- SetTimer(hwnd, 1, 1000, TimerEvent);
- }
- else if(LOWORD(wParam) == 2)
- {
- GlobTime = 0;
- InvalidateRect(hwnd, 0, false);
- KillTimer(hwnd, 1);
- }
- }
- break;
- }
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hd = BeginPaint((HWND)MenuItems[2], &ps);
- HFONT hfontMSSS = CreateFont (80,40,FW_DONTCARE,FW_DONTCARE,FW_BOLD,
- FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
- CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,L"System");
- SelectFont(hd, hfontMSSS);
- SetTextColor(hd, RGB(255,0,0));
- SetBkColor(hd, RGB(0,0,0));
- TCHAR timeNow[6] = {0}, csec[3] = {0}, cmin[3] = {0};
- int sec = GlobTime, mins = GlobTime;
- do
- {
- if(sec - 60 < 0 && sec != 0)
- {
- wsprintfW(csec, sec > 9 ? L"%d" : L"0%d", sec);
- break;
- }
- else if(!sec)
- {
- wcscat(csec, L"00");
- break;
- }
- sec -= 60;
- } while (1);
- //wcscat(timeNow, L":");
- if(GlobTime - sec == 0)
- {
- wcscat(cmin, L"00");
- }
- else
- {
- wsprintfW(cmin, (GlobTime - sec) / 60 > 9 ? L"%d" : L"0%d", (GlobTime - sec) / 60);
- }
- wsprintf(timeNow, L"%s:%s", cmin, csec);
- TextOut(hd, 0, 10, timeNow, _tcslen(timeNow));
- EndPaint(hwnd, &ps);
- break;
- }
- case WM_DESTROY:
- {
- KillTimer(hwnd, 1);
- PostQuitMessage(0);
- break;
- }
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- VOID CALLBACK TimerEvent( HWND window, UINT Msg, UINT_PTR EventID, DWORD SYSTime)
- {
- if(++GlobTime > 60 * 60 - 1) GlobTime = 0;
- InvalidateRect(window, 0, false);
- }
Add Comment
Please, Sign In to add comment