小飞的世界

°★·°∴☆°广阔的星空中有发生在你我身边的故事∴☆°★·,亦真亦幻。如若这漫长的月夜,无人与你同行,那就让我用微笑来伴你一程......欢迎来到小飞的幻想世界,留下那永恒的瞬间!
自作荧屏小秘书,帮助自己提醒工作!~
作者:止一  发表时间:2004-10-11

1,设计思想:用MSN方式提示用户


图片如下:

2,设计思路:采用定时方式,提醒休息间隔,保护眼睛;定时关机,防止电脑老化;提示早,中,晚的上下班时间
设计界面如下:

图片如下:

3,采用了XP界面风格,对VC++界面风格学习起到一定的作用
4,有声音铃声提示
5,难点是MSN风格提示,我加入了声音接口,核心代码如下:
希望对喜爱VC++的读者起到帮助作用.
// MsgWnd.cpp : implementation file
//
#include "stdafx.h"
#include "MsgWnd.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//---------------------------------------------------------------------------
#define ID_TIMER_POP_WINDOW        10
#define ID_TIMER_CLOSE_WINDOW    11
#define ID_TIMER_DISPLAY_DELAY    12
#define ID_TIMER_FINAL_CLOSE 9
#define ID_TIMER_START            8
#define WIN_WIDTH    181
#define WIN_HEIGHT    116
/////////////////////////////////////////////////////////////////////////////
// CMsgWnd

CMsgWnd::CMsgWnd()
{

    m_Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_SHOWMSG)); //Load Bitmap
    m_Bitmap.GetBitmap(&bmBitmap); //Get Bitmap Info
}

CMsgWnd::~CMsgWnd()
{
}


BEGIN_MESSAGE_MAP(CMsgWnd, CWnd)
    //{{AFX_MSG_MAP(CMsgWnd)
    ON_WM_PAINT()
    ON_WM_TIMER()
    ON_WM_CREATE()
    ON_WM_MOUSEMOVE()
    ON_WM_KILLFOCUS()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMsgWnd message handlers
void CMsgWnd::CreateMsgWindow()
{
//    RECT rect;
//    SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
//    int y=rect.bottom-rect.top;
//    int x=rect.right-rect.left;
//    x=x-WIN_WIDTH;
//    y=y-WIN_HEIGHT;
    CreateEx(0,
         AfxRegisterWndClass(
             0,
             ::LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_HAND_1)),(HBRUSH)(COLOR_DESKTOP+1),NULL),
             "",
             WS_POPUP|WS_EX_TOPMOST,
             0,
             0,
             0,//bmBitmap.bmWidth, //Bitmap Width = Splash Window Width
             0,//bmBitmap.bmHeight, //Bitmap Height = Splash Window Height
             NULL,//AfxGetMainWnd()->GetSafeHwnd(),
             NULL,
             NULL);
    SetTimer(ID_TIMER_POP_WINDOW,20,NULL);
}
void CMsgWnd::SetPromptMessage(LPCTSTR lpszMsg)
{
    lstrcpy(m_strMessage,lpszMsg);
}

void CMsgWnd::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    CDC dcMemory;
    CRect rect;
    GetClientRect(&rect);
dcMemory.CreateCompatibleDC(NULL);
    dcMemory.SelectObject(&m_Bitmap);
    dc.StretchBlt(0,
        0,
        rect.right-rect.left,//bmBitmap.bmWidth,
        rect.bottom-rect.top,//bmBitmap.bmHeight,
        &dcMemory,
        0,
        0,
        bmBitmap.bmWidth,
        bmBitmap.bmHeight,
        SRCCOPY);    
    CFont font;
    font.CreatePointFont(90,"Impact");
    dc.SelectObject(&font);
    dc.SetTextColor(RGB(0,64,128));
dc.SetBkMode(TRANSPARENT);
    dc.TextOut(30,10,m_strCaption);
    rect.top=30;
    dc.DrawText(m_strMessage,-1,&rect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
    // Do not call CWnd::OnPaint() for painting messages
}

void CMsgWnd::OnTimer(UINT nIDEvent)
{    
    static int nHeight=0;
    int cy=GetSystemMetrics(SM_CYSCREEN);
    int cx=GetSystemMetrics(SM_CXSCREEN);
    RECT rect;
    SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
    int y=rect.bottom-rect.top;
    int x=rect.right-rect.left;
    x=x-WIN_WIDTH;
    
    switch(nIDEvent)
    {
    case ID_TIMER_START:
        KillTimer(ID_TIMER_START);
        SetTimer(ID_TIMER_POP_WINDOW,20,NULL);
        break;
    case ID_TIMER_POP_WINDOW:
        if(nHeight<=WIN_HEIGHT)
        {
            ++nHeight;            
            MoveWindow(x,
                y-nHeight,
                WIN_WIDTH,
                WIN_HEIGHT);
            
         Invalidate(FALSE);
        }
        else
        {
            KillTimer(ID_TIMER_POP_WINDOW);
            SetTimer(ID_TIMER_DISPLAY_DELAY,5000,NULL);
        }
        break;
    case ID_TIMER_CLOSE_WINDOW:
        if(nHeight>=0)
        {
            nHeight--;
            MoveWindow(x,
                y-nHeight,
                WIN_WIDTH,
                nHeight);
        }
        else
        {
            KillTimer(ID_TIMER_CLOSE_WINDOW);
        //    SendMessage(WM_CLOSE);
            static timex=0;
            timex++;
            if(timex<=5)//show user 5 times
            {
                SetTimer(ID_TIMER_START,1000,NULL);//1s later show again
            }
            else
            {
                timex=0;
                SendMessage(WM_CLOSE);
            }
        }
        break;
    case ID_TIMER_DISPLAY_DELAY:
        KillTimer(ID_TIMER_DISPLAY_DELAY);
        SetTimer(ID_TIMER_CLOSE_WINDOW,20,NULL);
        break;
    case ID_TIMER_FINAL_CLOSE:
        KillTimer(ID_TIMER_DISPLAY_DELAY);
        KillTimer(ID_TIMER_POP_WINDOW);
        KillTimer(ID_TIMER_START);
        if(nHeight>=0)
        {
            nHeight--;
            MoveWindow(x,
                y-nHeight,
                WIN_WIDTH,
                nHeight);
        }
        else
        {
            KillTimer(ID_TIMER_FINAL_CLOSE);
            SendMessage(WM_CLOSE);
        }
        break;
    }
    
    CWnd::OnTimer(nIDEvent);
}

int CMsgWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    
    
    
    return 0;
}



void CMsgWnd::onMouseMove(UINT nFlags, CPoint point)
{
    CRect rect;
    GetClientRect(&rect);
    if(rect.PtInRect(point))
    {//    m_bFlag=true;
        //KillTimer(ID_TIMER_DISPLAY_DELAY);
     SetTimer(ID_TIMER_FINAL_CLOSE,20,NULL);
    }    
    CWnd::onMouseMove(nFlags, point);
}

void CMsgWnd::OnKillFocus(CWnd* pNewWnd)
{
    CWnd::OnKillFocus(pNewWnd);
//    if(m_bFlag)
//    SetTimer(ID_TIMER_DISPLAY_DELAY,20,NULL);//3000
    // TODO: Add your message handler code here
    
}

void CMsgWnd::SetPromptCaption(LPCTSTR lpszCaption)
{
    lstrcpy(m_strCaption,lpszCaption);
}

void CMsgWnd::SetText(char* strTopic, char* strContent)
{
    m_strMessage=strContent;//strContent;
    m_strCaption=strTopic;//"Monitor Messager";

}

void CMsgWnd::PlaySoundWav(CString strWavSound)
{
    PlaySound(strWavSound,AfxGetResourceHandle(),SND_RESOURCE|SND_PURGE|SND_NODEFAULT );
}

所属栏目:VC++天地  


 
评论内容(共有{Count}条)


{CommentAuthor}:
{{CommentContent}

--- {CommentTime} | {CommentEmail} {CommentUrl} {CommentIp}


 
 About ME

Name    : Xiaofei
Gender :  Male
Hobby   : Internet,chess,
       fishing,music,reading......
QQ     : 8201655
EMail : lizzie001@163.com


月夜思绪

在这月儿高挂的夜里

整理着散乱的

与感情有关的思绪

那些生活事业的前尘往事

飘然而至

原以为自己

可以做的云淡风轻

在飘渺的夜风里却发现

那些东西化做无边的落寂

在细柳轻舞的池塘边 舞蹈着

有谁 愿意让心辗转反侧

让影子相陪 举杯 饮尽

杯里 都是 星星的碎片

夜有月梦 心亦有梦

月儿皎洁的光辉 落在

苍白的脸庞 如水的目光

映耀 人世间的离合悲欢

一切的一切

在它的清光里

都不及鱼儿的悠闲 快乐



 友情链接




 最新评论




 访问统计



 日志搜索



 
Designed By xiaofei Powered by 5DBLog
版权所有 Copyright 2005-2008 小飞的世界