标题:求高手给注释,谢了
只看楼主
lcx529
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2013-12-22
结帖率:0
已结贴  问题点数:10 回复次数:3 
求高手给注释,谢了
#define _CRT_SECURE_NO_WARNINGS

#include <windows.h>

#include <math.h>

#include <time.h>

#pragma comment(lib, "user32.lib")

#pragma comment(lib, "gdi32.lib")

#pragma comment(linker, "/SUBSYSTEM:Windows")

  

void GetPos(double degree, int len, int* x, int* y)

{

    *x = len * sin(degree);

    *y = len * cos(degree);

}

  

void DrawClock(HWND hw, HDC h, int hour, int minute, int second)

{

    HDC bufdc = CreateCompatibleDC(h);

    HBITMAP buf = CreateCompatibleBitmap(bufdc, 200, 200);

    RECT cr;

    HBRUSH bBg = CreateSolidBrush(RGB(255, 255, 255));

    GetClientRect(hw, &cr);

    SelectObject(bufdc, bBg);

    SelectObject(bufdc, buf);

    FillRect(bufdc, &cr, bBg);

  

    {

        int sx, sy, ex, ey;

        int i;

        for(i = 0; i < 12; ++i) {

            GetPos(2*3.14159/12*i, 85, &sx, &sy);

            GetPos(2*3.14159/12*i, 95, &ex, &ey);

            MoveToEx(bufdc, 100+sx, 100-sy, 0);

            LineTo(bufdc, 100+ex, 100-ey);

        }

    }

  

    {

        int hx, hy, mx, my, sx, sy;

        GetPos(2*3.14159 / 12 * (hour + (double)minute / 60 + (double)second / 3600), 50, &hx, &hy);

        GetPos(2*3.14159 / 60 * (minute + (double)second / 60), 65, &mx, &my);

        GetPos(2*3.14159 / 60 * second, 80, &sx, &sy);

        MoveToEx(bufdc, 100, 100, NULL);

        LineTo(bufdc, 100+hx, 100-hy);

        MoveToEx(bufdc, 100, 100, NULL);

        LineTo(bufdc, 100+mx, 100-my);

        MoveToEx(bufdc, 100, 100, NULL);

        LineTo(bufdc, 100+sx, 100-sy);

    }

      

    BitBlt(h, 0, 0, 200, 200, bufdc, 0, 0, SRCCOPY);

    DeleteDC(bufdc);

    DeleteObject(bBg);

    DeleteObject(buf);

}

  

LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l)

{

    switch(m) {

        case WM_CREATE:

            SetTimer(h, 1, 1000, 0);

            return 0;

        case WM_ERASEBKGND:

            return 1;

        case WM_TIMER:

            InvalidateRect(h, 0, FALSE);

            return 0;

        case WM_PAINT: {

            PAINTSTRUCT ps;

            HDC dc = BeginPaint(h, &ps);

            {

                time_t t;

                struct tm* pst;

                time(&t);

                pst = localtime(&t);

                DrawClock(h, dc, pst->tm_hour, pst->tm_min, pst->tm_sec);

            }

            EndPaint(h, &ps);

            return 0;

        }

        case WM_DESTROY:

            KillTimer(h, 1);

            PostQuitMessage(0);

            return 0;

        default:

            return DefWindowProc(h, m, w, l);

    }

}

  

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmd, INT nShow)

{

    WNDCLASS wc;

    ZeroMemory(&wc, sizeof(wc));

    wc.style = CS_HREDRAW | CS_VREDRAW;

    wc.lpfnWndProc = WndProc;

    wc.hInstance = hInst;

    wc.hbrBackground = (HBRUSH) COLOR_WINDOW;

    wc.lpszClassName = TEXT("MYCLOCK");

      

    if (RegisterClass(&wc) != 0) {

        MSG m;

        HWND hw = CreateWindow(TEXT("MYCLOCK"), TEXT("Clock"), WS_OVERLAPPEDWINDOW,

            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, 0);

         

        if (hw != NULL) {

            RECT r;

            GetWindowRect(hw, &r);

            r.right = r.left + 200;

            r.bottom = r.top + 200;

            AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);

            MoveWindow(hw, r.left, r.top, r.right - r.left, r.bottom - r.top, FALSE);

            ShowWindow(hw, SW_SHOWNORMAL);

            UpdateWindow(hw);

         

            while( GetMessage(&m, 0, 0, 0) > 0) {

                TranslateMessage(&m);

                DispatchMessage(&m);

            }

            return 0;

        }

        return 1;

    } else

        return 1;
}
搜索更多相关主题的帖子: Windows comment include double minute 
2013-12-31 17:56
lcx529
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2013-12-22
得分:0 
..
2013-12-31 20:35
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:10 
拿来编译运行一下不久知道了?
没有咩可以解析的,就是看函数名,变量名,应该大概知道究竟

我行我乐
我的博客:
http://blog.yuccn. net
2014-01-01 10:31
ravenhu13
Rank: 2
等 级:新手上路
威 望:3
帖 子:4
专家分:0
注 册:2014-2-3
得分:0 
绘图的吧,你自己逐个查名就知道了。
2014-02-04 00:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-425959-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.224552 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved