Created
October 29, 2016 09:14
-
-
Save Soulstorm50/7b3d37dab19d2cdc1dd2bae16d366ce2 to your computer and use it in GitHub Desktop.
MiliSecondsFromStart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <tchar.h> | |
#include <time.h> | |
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); | |
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); | |
SYSTEMTIME startTime; | |
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) | |
{ | |
TCHAR szClassWindow[] = L"Win32Application"; | |
GetSystemTime(&startTime); | |
HWND hWnd; | |
MSG lpMsg; | |
WNDCLASSEX wcl; | |
wcl.cbSize = sizeof(wcl); | |
wcl.style = CS_HREDRAW | CS_VREDRAW; | |
wcl.lpfnWndProc = WindowProc; | |
wcl.cbClsExtra = 0; | |
wcl.cbWndExtra = 0; | |
wcl.hInstance = hInst; | |
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); | |
wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); | |
wcl.lpszMenuName = NULL; | |
wcl.lpszClassName = szClassWindow; | |
wcl.hIconSm = NULL; | |
if (!RegisterClassEx(&wcl)) | |
return 0; | |
hWnd = CreateWindowEx(0, szClassWindow, TEXT("Работа с таймером"), WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, NULL, NULL, hInst, NULL); | |
ShowWindow(hWnd, nCmdShow); | |
UpdateWindow(hWnd); | |
SetTimer(hWnd, 1, 1, TimerProc); | |
while (GetMessage(&lpMsg, NULL, 0, 0)) | |
{ | |
TranslateMessage(&lpMsg); | |
DispatchMessage(&lpMsg); | |
} | |
return lpMsg.wParam; | |
} | |
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) | |
{ | |
SYSTEMTIME currentTime; | |
GetSystemTime(¤tTime); | |
TCHAR szCaption[100] = {}; | |
int millisecondsFromStart = ((currentTime.wMinute - startTime.wMinute) * 1000 * 60) | |
+ ((currentTime.wSecond - startTime.wSecond) * 1000) | |
+ (currentTime.wMilliseconds - startTime.wMilliseconds); | |
_stprintf_s(szCaption, TEXT("%d ms from start"), millisecondsFromStart); | |
SetWindowText(hwnd, szCaption); | |
} | |
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
{ | |
switch (message) | |
{ | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
break; | |
default: | |
return DefWindowProc(hWnd, message, wParam, lParam); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment