多彩时钟

作者在 2012-02-16 22:00:51 发布以下内容
// 001.cpp : a simple console application write by xiaohailun.

#include <graphics.h>
#include <STDIO.H>
#include <TIME.H>
#include <WINDOWS.H>
#pragma comment(lib,"Winmm.lib")  // 引用 Windows Multimedia API

//static int rgb[7]={BLUE,GREEN,RED,YELLOW,MAGENTA,LIGHTBLUE,LIGHTCYAN};
IMAGE ima[7];

void load()
{
    loadimage(&(ima[0]),"图片\\17.jpg");
    loadimage(&(ima[1]),"图片\\1.jpg");
    loadimage(&(ima[2]),"图片\\2.jpg");
    loadimage(&(ima[3]),"图片\\3.jpg");
    loadimage(&(ima[4]),"图片\\5.jpg");
    loadimage(&(ima[5]),"图片\\7.jpg");
    loadimage(&(ima[6]),"图片\\9.jpg");
}
void loadbkgroud(int k)
{
    putimage(0,0,&(ima[k]));
}
void playtime(int k)
{
    static int sint = 0;
    COLORREF color;
    SYSTEMTIME timenow;
    char s0[5]={'0'},s1[5]={'0'},s2[5]={'0'};    
    GetLocalTime(&timenow);        
    sprintf(s0,"%d",(int)timenow.wHour);
    sprintf(s1,"%d",(int)timenow.wMinute);
    sprintf(s2,"%d",(int)timenow.wSecond);

    cleardevice();
    //printf("%s\n%s\n%s\n\n",s0,s1,s2);
    loadbkgroud(k);
    color = HSVtoRGB(sint, 1.0f, 1.0f);
    if((sint+=3) > 360) sint = 0;
    setcolor(color);
    setbkmode(TRANSPARENT);
    setfont(150,30,"黑体");
    outtextxy(0,0,s0);
    outtextxy(50,0,"");
    outtextxy(89,0,s1);
    outtextxy(139,0,"");
    outtextxy(180,0,s2);
    
}
int main(int argc, char* argv[])
{
    int driver,mode,k;
    MOUSEMSG msg;
    driver=VGA;mode=VGAHI;

    mciSendString("open backgroudmusic.mp3 alias mymusic",NULL ,0,NULL);
    initgraph(240, 150);
    cleardevice();
    load();
    k=0;
    while(true)
    {
        playtime(k);
        Sleep(220);
        if(MouseHit())
        {            
            msg=GetMouseMsg();
            FlushMouseMsgBuffer();
            if(msg.uMsg==WM_LBUTTONDOWN)
            {
                k++;
                k=k%7;
                playtime(k);
            }
            else if(msg.uMsg==WM_RBUTTONDBLCLK)
            {
                break;
            }
            else if(msg.uMsg==WM_MBUTTONDOWN)
            {
                mciSendString("play mymusic",0,0,0);
            }
            else if(msg.uMsg==WM_RBUTTONDOWN)
            {
                mciSendString("stop mymusic",0,0,0);
            }
        }

    }
    mciSendString("stop mymusic",0,0,0);
    closegraph();
    return 0;
}

c图形编程 | 阅读 1140 次
文章评论,共0条
游客请输入验证码
浏览69241次