| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 702 人关注过本帖
标题:真心求助大神,帮忙编一个VC++6.0程序……很着急啊
只看楼主 加入收藏
shuoxiaolang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
真心求助大神,帮忙编一个VC++6.0程序……很着急啊
这两天要做一个模拟时钟转动的程序,有4个功能要求:
1.在屏幕上显示一个活动时钟;
2.能模拟机械钟表行走;
3.屏幕上准确得用数字显示出日期和时间;
4.按任意键程序退出。

是要在VC++6.0的平台上运行,.cpp的文件

望各位大神不吝赐教,真心感谢啊~~
搜索更多相关主题的帖子: 机械 
2012-08-22 09:53
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:10 
找不到例子吗?
2012-08-22 16:05
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
程序代码:
#include <Windows.h>
#include <strsafe.h>
#include <math.h>

#define PI    (3.1415)
#define ID    (1000)
#define BUF_SIZE    (50)

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT("Clock");   
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;


    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = szAppName;

    if (!RegisterClass(&wndclass))
    {
        MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR);
        return 0;
    }

    hwnd = CreateWindow(szAppName, TEXT("Clock Demo"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, NULL, hInstance, NULL);
    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

static int cxClient;//客户区x方向的长度
static int cyClient;//客户区y方向的长度
static unsigned int g_H;//
static unsigned int g_M;//
static unsigned int g_S;//
static TCHAR szBuffer[BUF_SIZE];
void ShowClock(HWND, HDC);
void TimerProc(HWND);

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;//
    PAINTSTRUCT ps;

    switch (msg)
    {
    case WM_CREATE:
        SetTimer(hwnd, ID, 1000, NULL);
    case WM_SIZE:
        cxClient = LOWORD(lParam);//GetSystemMetrics(SM_CXMAXIMIZED);
        cyClient = HIWORD(lParam);//GetSystemMetrics(SM_CYMAXIMIZED);
        return 0;

    case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);
        ShowClock(hwnd, hdc);
        EndPaint(hwnd, &ps);
        return 0;
       
    case WM_TIMER:
        TimerProc(hwnd);
        return 0;
    case WM_KEYDOWN://按键
    case WM_DESTROY://退出
        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

void TimerProc(HWND hwnd)
{
    ++g_S;
    if (g_S < 60)
    {
        goto g_Out;
    }
    g_S = 0;

    ++g_M;
    if (g_M < 60)
    {
        goto g_Out;
    }
    g_M = 0;

    ++g_H;
    if (g_H < 24)
    {
        goto g_Out;
    }
    g_H = 0;
g_Out:
    InvalidateRect(hwnd, NULL, FALSE);
}

//显示
void ShowClock(HWND hwnd, HDC hdc)
{
    POINT rCenter;
    unsigned int r;
    HPEN hPen;
    HBRUSH hBrush;

    rCenter.x = cxClient/2;
    rCenter.y = cyClient/2;
    r = (min(rCenter.x, rCenter.y) * 9) / 10;

    if (g_H >= 12)
    {
        StringCchPrintfW(szBuffer, 50, TEXT("PM %02d : %02d : %02d"), g_H, g_M, g_S);
    }
    else
    {
        StringCchPrintfW(szBuffer, 50, TEXT("AM %02d : %02d : %02d"), g_H, g_M, g_S);
    }
    SetTextAlign(hdc, TA_RIGHT| TA_BOTTOM);
    TextOut(hdc, cxClient, cyClient, szBuffer, lstrlen(szBuffer));
       
    hPen = (HPEN)SelectObject(hdc, CreatePen(PS_DASHDOTDOT, 0, RGB(0x80, 0x80, 0x80)));
    Ellipse(hdc, rCenter.x - r, rCenter.y - r, rCenter.x + r, rCenter.y + r);
    SelectObject(hdc, hPen);
    hBrush = (HBRUSH)SelectObject(hdc, GetStockObject(GRAY_BRUSH));
    Ellipse(hdc, rCenter.x - r/50, rCenter.y - r/50, rCenter.x + r/50, rCenter.y + r/50);
    MoveToEx(hdc, rCenter.x, rCenter.y, NULL);
    LineTo(hdc,  rCenter.x + r * sin((g_S*PI)/30.0), rCenter.y - r * cos((g_S*PI)/30.0) );
    SelectObject(hdc, hBrush);
}
2012-08-22 19:45
mfs111116
Rank: 2
来 自:山东烟台
等 级:论坛游民
帖 子:28
专家分:38
注 册:2012-8-22
收藏
得分:10 
谢谢了啊^
谢谢,我也需要这样的例子,不为别的,只为学习,加强一下印象,再次感谢。
2012-08-24 18:23
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
回复 4楼 mfs111116
!!!
2012-08-25 08:33
快速回复:真心求助大神,帮忙编一个VC++6.0程序……很着急啊
数据加载中...
 
   



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

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