屏幕保护程序
2011-09-25 20:56
141 查看
CWnd::OnActivate
The framework calls this member function when a CWnd object is being activated or deactivated.
afx_msg void OnActivate(
UINT nState,
CWnd* pWndOther,
BOOL bMinimized
);
Parameters
nState
Specifies whether the CWnd is being activated or deactivated. It can be one of the following values:
WA_INACTIVE The window is being deactivated.
WA_ACTIVE The window is being activated through some method other than a mouse click (for example, by use of the keyboard interface to select the window).
WA_CLICKACTIVE The window is being activated by a mouse click.
pWndOther
Pointer to the CWnd being activated or deactivated. The pointer can be NULL, and it may be temporary.
bMinimized
Specifies the minimized state of the CWnd being activated or deactivated. A value of TRUE indicates the window is minimized.
If TRUE, the CWnd is being activated; otherwise deactivated.
Remarks
If the CWnd object is activated with a mouse click, it will also receive an OnMouseActivate member function call.
Note
This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation
of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
CWnd::OnActivateApp
The framework calls this member function to all top-level windows of the task being activated and for all top-level windows of the task being deactivated.
afx_msg void OnActivateApp(
BOOL bActive,
DWORD dwThreadID
);
Parameters
bActive
Specifies whether the CWnd is being activated or deactivated. TRUE means the CWnd is being activated. FALSE means the CWnd is being deactivated.
dwThreadID
Specifies the value of the thread ID. If bActive is TRUE, dwThreadID identifies the thread that owns the CWnd being deactivated. If bActive is FALSE,dwThreadID identifies the thread that owns the CWnd being activated.
Remarks
Note
This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation
of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
构造自己的窗体CMyWnd
class CMyWnd : public CWnd
{
public:
CMyWnd();
static LPCSTR lpszClassName; //注册类名
public:
BOOL Create();
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyWnd)
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
public:
virtual ~CMyWnd();
protected:
CPoint m_prePoint; //检测鼠标移动
void DrawBitmap(CDC& dc, int nIndexBit);
//{{AFX_MSG(CMyWnd)
afx_msg void OnPaint();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnDestroy();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#define ID_TIMER WM_USER+1000
CMyWnd::CMyWnd()
{
m_prePoint=CPoint(-1,-1);
}
CMyWnd::~CMyWnd()
{
}
BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
//{{AFX_MSG_MAP(CMyWnd)
ON_WM_PAINT()
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_SYSKEYDOWN()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_ACTIVATE()
ON_WM_ACTIVATEAPP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LPCSTR CMyWnd::lpszClassName=NULL;
BOOL CMyWnd::Create()
{
if(lpszClassName==NULL)
{
lpszClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR)));
//注册类;IDC_NOCURSOR为新建光标的ID,这个光标没有任何图案
}
CRect rect(0, 0, ::GetSystemMetrics(SM_CXSCREEN),
::GetSystemMetrics(SM_CYSCREEN));
CreateEx(WS_EX_TOPMOST, lpszClassName, _T(""), WS_VISIBLE|WS_POPUP,
rect.left,rect.top,rect.right - rect.left, rect.bottom - rect.top,
GetSafeHwnd(), NULL, NULL); //创建一个全屏窗口
SetTimer(ID_TIMER, 500, NULL);//计时器,ID_TIMER别忘了定义
return TRUE;
}
//为了防止同时运行两个相同的程序,下面两个函数是必需的
void CMyWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CWnd::OnActivate(nState,pWndOther,bMinimized);
if(nState==WA_INACTIVE)
PostMessage(WM_CLOSE);
}
void CMyWnd::OnActivateApp(BOOL bActive, DWORD dwThreadID)
{
CWnd::OnActivateApp(bActive, dwThreadID);
if(!bActive) //is being deactivated
PostMessage(WM_CLOSE);
}
//OnPaint()函数将全屏窗口置为黑色
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
CBrush brush(RGB(0,0,0));
CRect rect;
GetClientRect(rect);
dc.FillRect(&rect,&brush);
}
//由计数器调用DrawBitmap()函数,切换图片;
//注意,下面两个函数中的IDB_BITMAP1, dc.BitBlt(0,0,800,600……以及if(nIndexBit>=5)中的
//有关数据依据你的bmp图片个数、尺寸、位置不同而不同,我是选择了5张
//800x600的bmp图片。注意,ID值是连续的,IDB_BITMAP1最小
void CMyWnd::DrawBitmap(CDC& dc, int nIndexBit)
{
CDC dcmem;
dcmem.CreateCompatibleDC(&dc);
CBitmap m_Bitmap;
m_Bitmap.LoadBitmap(IDB_BITMAP1+nIndexBit);
dcmem.SelectObject(m_Bitmap);
dc.BitBlt(0,0,800,600,&dcmem,0,0,SRCCOPY);
}
void CMyWnd::OnTimer(UINT nIDEvent)
{
CClientDC dc(this);
static int nIndexBit=0;
if(nIndexBit>=5)
nIndexBit=0;
DrawBitmap(dc, nIndexBit++);
CWnd::OnTimer(nIDEvent);
}
//响应键盘、鼠标是屏幕保护程序不可缺少的
void CMyWnd::OnKeyDown(UINT nChar,UINT nRepCnt,UINT nFlags)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnLButtonDown(UINT nFlags,CPoint point)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnMButtonDown(UINT nFlags,CPoint point)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnRButtonDown(UINT nFlags,CPoint point)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnSysKeyDown(UINT nChar,UINT nRepCnt,UINT nFlags)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnMouseMove(UINT nFlags,CPoint point)
{
if(m_prePoint == CPoint(-1,-1))
m_prePoint = point;
else if(m_prePoint!=point)
PostMessage(WM_CLOSE);
}
void CMyWnd::OnDestroy()
{
//删掉计时器
KillTimer(ID_TIMER);
}
void CMyWnd::PostNcDestroy()
{
delete this;
}
在App::InitInstance()中
//显示屏保窗口
CMyWnd* pWnd = new CMyWnd;
pWnd->Create();
m_pMainWnd = pWnd;
The framework calls this member function when a CWnd object is being activated or deactivated.
afx_msg void OnActivate(
UINT nState,
CWnd* pWndOther,
BOOL bMinimized
);
Parameters
nState
Specifies whether the CWnd is being activated or deactivated. It can be one of the following values:
WA_INACTIVE The window is being deactivated.
WA_ACTIVE The window is being activated through some method other than a mouse click (for example, by use of the keyboard interface to select the window).
WA_CLICKACTIVE The window is being activated by a mouse click.
pWndOther
Pointer to the CWnd being activated or deactivated. The pointer can be NULL, and it may be temporary.
bMinimized
Specifies the minimized state of the CWnd being activated or deactivated. A value of TRUE indicates the window is minimized.
If TRUE, the CWnd is being activated; otherwise deactivated.
Remarks
If the CWnd object is activated with a mouse click, it will also receive an OnMouseActivate member function call.
Note
This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation
of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
CWnd::OnActivateApp
The framework calls this member function to all top-level windows of the task being activated and for all top-level windows of the task being deactivated.
afx_msg void OnActivateApp(
BOOL bActive,
DWORD dwThreadID
);
Parameters
bActive
Specifies whether the CWnd is being activated or deactivated. TRUE means the CWnd is being activated. FALSE means the CWnd is being deactivated.
dwThreadID
Specifies the value of the thread ID. If bActive is TRUE, dwThreadID identifies the thread that owns the CWnd being deactivated. If bActive is FALSE,dwThreadID identifies the thread that owns the CWnd being activated.
Remarks
Note
This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation
of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
构造自己的窗体CMyWnd
class CMyWnd : public CWnd
{
public:
CMyWnd();
static LPCSTR lpszClassName; //注册类名
public:
BOOL Create();
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyWnd)
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
public:
virtual ~CMyWnd();
protected:
CPoint m_prePoint; //检测鼠标移动
void DrawBitmap(CDC& dc, int nIndexBit);
//{{AFX_MSG(CMyWnd)
afx_msg void OnPaint();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnDestroy();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#define ID_TIMER WM_USER+1000
CMyWnd::CMyWnd()
{
m_prePoint=CPoint(-1,-1);
}
CMyWnd::~CMyWnd()
{
}
BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
//{{AFX_MSG_MAP(CMyWnd)
ON_WM_PAINT()
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_SYSKEYDOWN()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_ACTIVATE()
ON_WM_ACTIVATEAPP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LPCSTR CMyWnd::lpszClassName=NULL;
BOOL CMyWnd::Create()
{
if(lpszClassName==NULL)
{
lpszClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR)));
//注册类;IDC_NOCURSOR为新建光标的ID,这个光标没有任何图案
}
CRect rect(0, 0, ::GetSystemMetrics(SM_CXSCREEN),
::GetSystemMetrics(SM_CYSCREEN));
CreateEx(WS_EX_TOPMOST, lpszClassName, _T(""), WS_VISIBLE|WS_POPUP,
rect.left,rect.top,rect.right - rect.left, rect.bottom - rect.top,
GetSafeHwnd(), NULL, NULL); //创建一个全屏窗口
SetTimer(ID_TIMER, 500, NULL);//计时器,ID_TIMER别忘了定义
return TRUE;
}
//为了防止同时运行两个相同的程序,下面两个函数是必需的
void CMyWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CWnd::OnActivate(nState,pWndOther,bMinimized);
if(nState==WA_INACTIVE)
PostMessage(WM_CLOSE);
}
void CMyWnd::OnActivateApp(BOOL bActive, DWORD dwThreadID)
{
CWnd::OnActivateApp(bActive, dwThreadID);
if(!bActive) //is being deactivated
PostMessage(WM_CLOSE);
}
//OnPaint()函数将全屏窗口置为黑色
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
CBrush brush(RGB(0,0,0));
CRect rect;
GetClientRect(rect);
dc.FillRect(&rect,&brush);
}
//由计数器调用DrawBitmap()函数,切换图片;
//注意,下面两个函数中的IDB_BITMAP1, dc.BitBlt(0,0,800,600……以及if(nIndexBit>=5)中的
//有关数据依据你的bmp图片个数、尺寸、位置不同而不同,我是选择了5张
//800x600的bmp图片。注意,ID值是连续的,IDB_BITMAP1最小
void CMyWnd::DrawBitmap(CDC& dc, int nIndexBit)
{
CDC dcmem;
dcmem.CreateCompatibleDC(&dc);
CBitmap m_Bitmap;
m_Bitmap.LoadBitmap(IDB_BITMAP1+nIndexBit);
dcmem.SelectObject(m_Bitmap);
dc.BitBlt(0,0,800,600,&dcmem,0,0,SRCCOPY);
}
void CMyWnd::OnTimer(UINT nIDEvent)
{
CClientDC dc(this);
static int nIndexBit=0;
if(nIndexBit>=5)
nIndexBit=0;
DrawBitmap(dc, nIndexBit++);
CWnd::OnTimer(nIDEvent);
}
//响应键盘、鼠标是屏幕保护程序不可缺少的
void CMyWnd::OnKeyDown(UINT nChar,UINT nRepCnt,UINT nFlags)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnLButtonDown(UINT nFlags,CPoint point)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnMButtonDown(UINT nFlags,CPoint point)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnRButtonDown(UINT nFlags,CPoint point)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnSysKeyDown(UINT nChar,UINT nRepCnt,UINT nFlags)
{
PostMessage(WM_CLOSE);
}
void CMyWnd::OnMouseMove(UINT nFlags,CPoint point)
{
if(m_prePoint == CPoint(-1,-1))
m_prePoint = point;
else if(m_prePoint!=point)
PostMessage(WM_CLOSE);
}
void CMyWnd::OnDestroy()
{
//删掉计时器
KillTimer(ID_TIMER);
}
void CMyWnd::PostNcDestroy()
{
delete this;
}
在App::InitInstance()中
//显示屏保窗口
CMyWnd* pWnd = new CMyWnd;
pWnd->Create();
m_pMainWnd = pWnd;
相关文章推荐
- MacBook Pro 桌面与屏幕保护程序出现假死
- 利用VB6.0设计屏幕保护程序
- Win8如何设置或取消恢复屏幕保护程序不提示输入登录密码
- Windows屏幕保护程序的制作
- 鱼C屏幕保护程序 - 零基础入门学习Delphi11
- Windows xp 安装的屏幕保护程序
- 用Visual C#设计屏幕保护程序
- 使用Python 启动windows 屏幕保护程序 及在线程中启动
- 写一个DX8的屏幕保护程序-------Alpha 闪烁效果
- windows屏幕保护opengl程序模板
- Win7系统在使用改进电源使用时提示屏幕保护程序已启用问题
- 黑客帝国 数字雨 屏幕保护程序 linux ubuntu
- 黑客帝国_屏幕保护程序
- c#制作屏幕保护程序步骤(字幕屏保)
- c#简单屏幕保护程序,共4个线程
- 教你如何把文章、图片制成屏幕保护程序,只要你会Word
- 【原创】用MASM32制作屏幕保护程序的问题及解决
- 为Delphi编写的屏幕保护程序增加描述
- 怎样把做好的Flash动画转换成屏幕保护程序?
- Win8.1如何根据需要设置屏幕保护程序