5D艺术网首页
商城
|
资讯
|
作品
|
博客
|
教程
|
论坛
登录
注册
加为好友
发短消息
来自:地球
性别:先生
最后登录:2015-09-16
http://linux.5d.cn/
俱网矣,数风流人物还看今朝!!
首页
|
新闻
|
话题
|
博客
|
相册
|
艺术作品
|
社交关系
|
留言板
|
社交圈
2004/10/11 | 自作荧屏小秘书,帮助自己提醒工作!~
类别(VC++天地)
|
评论
(0)
|
阅读(298)
|
发表于 11:31
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 );
}
0
评论
Comments
日志分类
首页
[562]
版主介绍
[6]
LINUX乐园
[2]
VC++天地
[30]
网络应用
[65]
外语沙龙
[29]
酷图欣赏
[81]
心情故事
[175]
开心灌吧
[157]
影音天地
[9]
电子乐园
[8]