问题标题: 计时器

0
0
已解决
王梓轩
王梓轩
资深光能
资深光能
#include<windows.h>
#include<bits/stdc++.h>
#define M1 Beep(523,300);
#define M2 Beep(587,300);
#define M3 Beep(659,300);
#define M4 Beep(698,300);
#define M5 Beep(784,300);
#define M6 Beep(880,300);
#define M7 Beep(980,300);
#define M8 Beep(1015,300);
#define M9 Beep(1090,300);
using namespace std;
int num=0;
HWND yi,wu,shi,sanshi,ershiwu,shiwu,kaishi,guiling;
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
    switch(Message)
    {
        case WM_CREATE:
        {
            yi=CreateWindow("button","+1",WS_CHILD|WS_VISIBLE,
                                0,0,100,100,hwnd,(HMENU)1,hInst,NULL);
            wu=CreateWindow("button","+5",WS_CHILD|WS_VISIBLE,
                                0,100,100,100,hwnd,(HMENU)2,hInst,NULL);
            shi=CreateWindow("button","+10",WS_CHILD|WS_VISIBLE,
                                0,200,100,100,hwnd,(HMENU)3,hInst,NULL);
            sanshi=CreateWindow("button","30分钟",WS_CHILD|WS_VISIBLE,
                                500,0,100,100,hwnd,(HMENU)4,hInst,NULL);
            ershiwu=CreateWindow("button","25分钟",WS_CHILD|WS_VISIBLE,
                                500,100,100,100,hwnd,(HMENU)5,hInst,NULL);
            shiwu=CreateWindow("button","15分钟",WS_CHILD|WS_VISIBLE,
                                500,200,100,100,hwnd,(HMENU)6,hInst,NULL);
            kaishi=CreateWindow("button","开始",WS_CHILD|WS_VISIBLE,
                                250,500,100,100,hwnd,(HMENU)7,hInst,NULL);
            guiling=CreateWindow("button","归零",WS_CHILD|WS_VISIBLE,
                                250,400,100,100,hwnd,(HMENU)8,hInst,NULL);
            break;
        }
        case WM_COMMAND:
        {
            switch(wParam)
            {
                case 1:
                {
                    num++;
                    if(num>=100000000)num=99999999;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 2:
                {
                    num+=5;
                    if(num>=100000000)num=99999999;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 3:
                {
                    num+=10;
                    if(num>=100000000)num=99999999;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 4:
                {
                    num=30;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 5:
                {
                    num=25;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 6:
                {
                    num=15;
                    if(num>=100000000)num=99999999;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 8:
                {
                    num=0;
                    if(num>=100000000)num=99999999;
                    stringstream ss;
                    system("cls");
                    cout<<num<<"分钟";
                    break;
                }
                case 7:
                {
                    num=num*60;
                    for(int i=num; i>=0; i--)
                    {
                        system("cls");
                        cout<<num/3600<<":"<<num/60<<":"<<num%60;
                        Sleep(1000);
                        num--;
                    }
                    for(int i=1; i<=5; i++)
                    {
                        M1;
                        M2;
                        M3;
                        M4;
                        M5;
                        M6;
                        M7;
                        M7;
                        M6;
                        M5;
                        M4;
                        M3;
                        M2;
                        M1;
                    }
                }
                default:
                {
                    DefWindowProc(hwnd,Message,wParam,lParam);
                    break;
                }
            }
            break;
        }
        default:
        {
            DefWindowProc(hwnd,Message,wParam,lParam);
            break;
        }
    }
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    hInst=hInstance;
    WNDCLASSEX wc;
    HWND hwnd; 
    MSG msg; 
    memset(&wc,0,sizeof(wc));
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.lpfnWndProc   = WndProc;
    wc.hInstance     = hInstance;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","计时器",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, 
                          CW_USEDEFAULT, 
                          1000, 
                          1000,
                          NULL,NULL,hInstance,NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }
    while(GetMessage(&msg,NULL,0,0)>0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
    return 0;
}

谢谢使用


0
0
李泽屿
李泽屿
新手启示者
新手启示者

所以

直接用Sleep他不香吗

0
0
郝天尘
郝天尘
资深光能
资深光能

可是运算不要时间吗?

0
我要回答