На autoit я затратил меньше времени на разработку секундомера.Но зато этот проект использует чистый winapi и язык си.
#include <windows.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HWND textsecond;
int boolstart = 0;
char szClassName[ ] = "WindowsApp";
HWND hwnd;
HFONT hFont;
#define FIRST_TIMER 1
int seconds = 0;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Секундомер",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
700,
700,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
textsecond = CreateWindow(TEXT("static"),
TEXT("Старт"),
WS_VISIBLE | WS_CHILD ,
20, 0, 150,150,
hwnd, 0, hThisInstance, NULL);
HWND start = CreateWindow(TEXT("button"),
TEXT("Старт"),
WS_VISIBLE | WS_CHILD ,
20, 200, 100, 35,
hwnd, (HMENU)1000, hThisInstance, NULL);
HWND stop = CreateWindow(TEXT("button"),
TEXT("Стоп"),
WS_VISIBLE | WS_CHILD ,
150, 200, 100, 35,
hwnd, (HMENU)1001, hThisInstance, NULL);
HWND reset = CreateWindow(TEXT("button"),
TEXT("продолжить"),
WS_VISIBLE | WS_CHILD ,
270, 200, 120, 35,
hwnd, (HMENU)1002, hThisInstance, NULL);
ShowWindow (hwnd, nFunsterStil);
HFONT hFont = CreateFont (55, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Tahoma"));
SendMessage(textsecond, WM_SETFONT, (LPARAM)hFont, TRUE);
SetTimer(hwnd,FIRST_TIMER ,1000,NULL);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_TIMER:
{
if(wParam == FIRST_TIMER)
{
if (boolstart == 1){
seconds = seconds + 1;
char buffertext[10];
sprintf (buffertext, "%d",seconds);
SetWindowText(textsecond,buffertext);
}
}
}
break;
case WM_COMMAND:
{
int START = 1000;
int STOP = 1001;
int CONTINUE= 1002;
if (wParam == START)
{
printf("start");
seconds = 0;
boolstart = 1;
}
if (wParam == STOP)
{
printf("stop");
boolstart = 2;
}
if (wParam == CONTINUE)
{
if (boolstart == 2){
printf("continue");
boolstart = 1;
}
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|