| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 231 人关注过本帖
标题:我的数字钟0.0
取消只看楼主 加入收藏
小鱼儿c
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:852
专家分:1317
注 册:2011-4-1
结帖率:95.74%
收藏
 问题点数:0 回复次数:2 
我的数字钟0.0
图片附件: 游客没有浏览图片的权限,请 登录注册
  
图片附件: 游客没有浏览图片的权限,请 登录注册

程序代码:
#include <windows.h>
#include <stdio.h>
#define IDT_TIMER 1
#define IDM_TOPMOST 0x1000
#define HEIGHT 59 // 每个数字的高度
#define WIDTH  35 // 每个数字的宽度
#define MAX_LOADSTRING 36
#define IDT_TIMER 1
#define IDM_TOPMOST 0x1000
#define IDM_ALERT 0X1001
#define IDM_CLOSE 0X1002
#define HEIGHT 59 // 每个数字的高度
#define WIDTH  35
BOOL bTopMost = TRUE;
bool init_win();
HWND create_win();
void show_win();
void run_win();
void display_time();
void chk();
HBITMAP bg;
HBITMAP bitmap;
HBITMAP clock_1,clock_2;
char buf[10];
HDC hdc;
HDC mdc;
HDC bufdc;
HDC bufdc1;
HDC bufdc2;
int dx=0;
SYSTEMTIME time;
char *name="xiaoyuer";
HINSTANCE hinst;
HWND hwnd;
WNDCLASS wnd;
int x=0,y=0;
LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{hinst=hInstance;

if(init_win())
{
    if(hwnd=create_win())
    {    hdc=GetDC(hwnd);
    mdc=CreateCompatibleDC(hdc);
    bufdc=CreateCompatibleDC(hdc);
    bitmap=CreateCompatibleBitmap(hdc,35*8,59);
SelectObject(mdc,bitmap);
        bg=(HBITMAP)LoadImage(hinst,"bg.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    clock_1=(HBITMAP)LoadImage(hinst,"time_bg.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
clock_2=(HBITMAP)LoadImage(hinst,"time.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
        show_win();
        run_win();
        return true;
    }
}
return false;
}
bool init_win()
{memset(&wnd,0,sizeof(wnd));
wnd.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wnd.hInstance=hinst;
wnd.lpfnWndProc=WinProc;
wnd.lpszClassName=name;
if(RegisterClass(&wnd))
return true;
else
return false;
}
HWND create_win()
{
    return CreateWindow(name,name, WS_SYSMENU|WS_POPUP,0,
        0,
        35*8, 59, NULL,
      NULL, hinst, NULL);
}
void show_win()
{
    ShowWindow(hwnd,SW_SHOW);
    UpdateWindow(hwnd);
}
void run_win()
{MSG msg;
    while(GetMessage(&msg,0,0,0 ))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{int wmId;
    HMENU hSysMenu;
    HDC hdc;
    PAINTSTRUCT ps;
    switch(msg)
    {case WM_CLOSE:
    KillTimer(hwnd,1);
    DeleteObject(bg);
    DeleteObject(clock_1);
    DeleteObject(clock_2);
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
        PostQuitMessage(0);
            break;
    case WM_TIMER:
        hdc=GetDC(hwnd);
        chk();
        ReleaseDC(hwnd, hdc);
        break;
    case WM_CREATE:
        if( SetTimer(hwnd,IDT_TIMER,1000,NULL) == 0 )
        {
            MessageBox(hwnd,TEXT("安装定时器失败"), TEXT("错误"),MB_OK | MB_ICONHAND);
            exit(-1);
        }
        hSysMenu = GetSystemMenu(hwnd, FALSE);
        DeleteMenu(hSysMenu, 0, MF_BYPOSITION);
        DeleteMenu(hSysMenu, 1, MF_BYPOSITION);
        DeleteMenu(hSysMenu, 1, MF_BYPOSITION);
        DeleteMenu(hSysMenu, 1, MF_BYPOSITION);
        DeleteMenu(hSysMenu, 1, MF_BYPOSITION);
        AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
        AppendMenu(hSysMenu, MF_STRING, IDM_TOPMOST, TEXT("总在最前"));
        AppendMenu(hSysMenu,MF_STRING,IDM_ALERT,"提醒");
        AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
        AppendMenu(hSysMenu,MF_STRING,IDM_CLOSE,"定时关机");
        EnableMenuItem(hSysMenu,IDM_TOPMOST, MF_BYCOMMAND | MF_ENABLED);
        SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
            SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE);
        CheckMenuItem(hSysMenu, IDM_TOPMOST, MF_BYCOMMAND | MF_CHECKED);       
        break;
    case WM_PAINT:hdc=BeginPaint(hwnd,&ps);
    chk();
    EndPaint(hwnd,&ps);
        break;
    case WM_NCHITTEST:
        {
            UINT nHitTest;
            nHitTest = DefWindowProc(hwnd, WM_NCHITTEST, wparam, lparam);
            if(nHitTest == HTCLIENT && GetAsyncKeyState(MK_LBUTTON) < 0)
                nHitTest = HTCAPTION;
    return nHitTest;
            }   
            case WM_ERASEBKGND: // 防止开始绘制时的闪烁
            return TRUE;

            case WM_SYSCOMMAND:
                wmId = wparam;
                {
                    if(wmId == IDM_TOPMOST)
                    {
                        hSysMenu = GetSystemMenu(hwnd, FALSE);
                        if(bTopMost)
                        {
                            CheckMenuItem(hSysMenu, IDM_TOPMOST, MF_UNCHECKED);
                            SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
                    SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE);
                            bTopMost = FALSE;
                        }
                        else
                        {
                            CheckMenuItem(hSysMenu, IDM_TOPMOST, MF_CHECKED);
                            SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
                    SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE);
                            bTopMost = TRUE;
                        }
                    }
                    return DefWindowProc(hwnd, WM_SYSCOMMAND, wmId, 0);
            }

            case WM_KEYDOWN:
                switch(wparam)
                {
                case VK_ESCAPE:
                    SendMessage(hwnd,WM_CLOSE,0,0);
                    break;
                default:break;
                }
            break;
           
            case WM_CONTEXTMENU:
                POINT pt;
                pt.x = LOWORD(lparam);
                pt.y = HIWORD(lparam);
                hSysMenu = GetSystemMenu(hwnd, FALSE);
                wmId =TrackPopupMenu(hSysMenu, TPM_LEFTALIGN | TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
                 if(wmId>0)
                    SendMessage(hwnd, WM_SYSCOMMAND, wmId, 0);
            return 0;
    default:return DefWindowProc(hwnd,msg,wparam,lparam);
    }
    return 0;
}
void display_time(int x)
{
if(dx==2)
dx++;
if(dx==5)
dx++;
SelectObject(bufdc,clock_1);
BitBlt(mdc,dx*35,0,35,59,bufdc,x*35,0,SRCAND);
SelectObject(bufdc,clock_2);
BitBlt(mdc,dx*35,0,35,59,bufdc,x*35,0,SRCPAINT);
dx+=1;
if(dx==8)
dx=0;
}
void chk()
{
int x;
GetLocalTime(&time);
SelectObject(mdc,bitmap);
SelectObject(bufdc,bg);
BitBlt(mdc,0,0,35*8,59,bufdc,0,0,SRCCOPY);
x=time.wHour/10;
display_time(x);
x=time.wHour%10;
display_time(x);
SelectObject(bufdc,clock_1);
BitBlt(mdc,2*35,0,35,59,bufdc,10*35,0,SRCAND);
SelectObject(bufdc,clock_2);
BitBlt(mdc,2*35,0,35,59,bufdc,10*35,0,SRCPAINT);
x=time.wMinute/10;
display_time(x);
x=time.wMinute%10;
display_time(x);
SelectObject(bufdc,clock_1);
BitBlt(mdc,5*35,0,35,59,bufdc,10*35,0,SRCAND);
SelectObject(bufdc,clock_2);
BitBlt(mdc,5*35,0,35,59,bufdc,10*35,0,SRCPAINT);
x=time.wSecond/10;
display_time(x);
x=time.wSecond%10;
display_time(x);
BitBlt(hdc,0,0,8*35,59,mdc,0,0,SRCCOPY);
}
2011-06-20 22:42
小鱼儿c
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:852
专家分:1317
注 册:2011-4-1
收藏
得分:0 
代码没有写完,代码参考别人的,因为一些GDI不知道就直接拿来用了。

用心做一件事情就这么简单
2011-06-20 22:45
小鱼儿c
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:852
专家分:1317
注 册:2011-4-1
收藏
得分:0 
就要考试了,唉,没时间啊,
问一下
图片附件: 游客没有浏览图片的权限,请 登录注册

这个要怎么写,要调用什么API啊。用这个想实现提示的功能。不会创建一盒子窗口吧,如果实现窗口的淡化,是不是不停的把背景色调暗。。。
高手指点。。。

用心做一件事情就这么简单
2011-06-20 22:49
快速回复:我的数字钟0.0
数据加载中...
 
   



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

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