// ScreenSaverWnd.cpp : implementation file
//
//////////
//
// Copyright (C) 1991-98 Ed Halley.
// http://www.explorati.com/people/ed/
// ed@explorati.com
//
// This published source code represents original intellectual
// property, owned and copyrighted by Ed Halley.
//
// The owner has authorized this source code for general public
// use without royalty, under two conditions:
// * The source code maintains this copyright notice in full.
// * The source code is only distributed for free or
// reasonable duplication cost, not for distribution profit.
//
// Unauthorized use, copying or distribution is a violation of
// U.S. and international laws and is strictly prohibited.
//
//////////
//
#include "StdAfx.h"
#include "ScreenSaverWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CScreenSaverWnd1, CWnd)
BEGIN_MESSAGE_MAP(CScreenSaverWnd1, CWnd)
//{{AFX_MSG_MAP(CScreenSaverWnd)
ON_WM_CREATE()
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_PALETTECHANGED()
ON_WM_QUERYNEWPALETTE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/* static */ CScreenSaverWnd1* CScreenSaverWnd1::sm_pTheScreenSaver = NULL;
CScreenSaverWnd1::CScreenSaverWnd1()
{
sm_pTheScreenSaver = this;
m_bAutoBlack = TRUE;
m_pPalette = NULL;
}
CScreenSaverWnd1::~CScreenSaverWnd1()
{
sm_pTheScreenSaver = NULL;
}
/////////////////////////////////////////////////////////////////////////////
//
// Setting up the new screen saver window.
//
int CScreenSaverWnd1::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
#ifdef _DEBUG
// Screen savers should be TOPMOST to block out any other windows,
// such as other topmost windows created previously. However, if you
// are trying to debug a screen saver, it can get in the way.
// We remove the topmost status from this window only if we're _DEBUG.
//
SetWindowPos(&CWnd::wndNoTopMost,
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
#endif
RestoreOptions();
OnInitialUpdate();
return 0;
}
void CScreenSaverWnd1::OnInitialUpdate()
{
// Base version does nothing.
// A derived class can set up basic data structures.
}
void CScreenSaverWnd1::SaveOptions()
{
// Base version does nothing.
// A derived class can store options in the registry or ini files.
}
void CScreenSaverWnd1::RestoreOptions()
{
// Base version does nothing.
// A derived class can retrieve options from the registry or ini files.
}
/////////////////////////////////////////////////////////////////////////////
//
// The screen saver is made to paint. We support OnDraw(), just like CView
// does, as a matter of convenience.
//
// Also for convenience, by the time an override of OnDraw() is called, the
// background has been blacked (if m_bAutoBlack), and the palette in
// m_pPalette has been realized properly. These are optional.
//
BOOL CScreenSaverWnd1::OnEraseBkgnd(CDC* pDC)
{
if (m_bAutoBlack)
{
CRect rcClient;
GetClientRect(&rcClient);
pDC->FillSolidRect(&rcClient, RGB(0, 0, 0));
}
return TRUE;
}
void CScreenSaverWnd1::OnPaint()
{
CPaintDC dc(this);
if (m_pPalette)
{
dc.SelectPalette(m_pPalette, FALSE);
dc.RealizePalette();
}
OnDraw(&dc);
}
void CScreenSaverWnd1::OnDraw(CDC* pDC)
{
// Base version does nothing.
// A derived class can use the DC to paint in any manner on the screen.
}
/////////////////////////////////////////////////////////////////////////////
//
// There is nothing about CScreenSaverWnd which requires using a CPalette.
// As a convenience, it can hold onto a CPalette and realize it at the proper
// times according to WM_QUERYNEWPALETTE and WM_PALETTECHANGED notifications.
//
// Separately, a derived class can turn on and off the automatic black
// background behavior which is handled in OnEraseBkgnd(). When it is off,
// all of the user's windows will still be visible when the screen saver
// starts its OnDraw().
//
CPalette* CScreenSaverWnd1::GetPalette() const
{
return m_pPalette;
}
CPalette* CScreenSaverWnd1::SetPalette(CPalette* pPalette)
{
// At no time does the CScreenSaverWnd take 'ownership' of a palette
// object; i.e., it will never delete or create them. It's just holding.
//
CPalette* pOldPalette = m_pPalette;
m_pPalette = pPalette;
OnQueryNewPalette();
return pOldPalette;
}
BOOL CScreenSaverWnd1::OnQueryNewPalette()
{
if (!m_pPalette)
return FALSE;
CClientDC dc(this);
dc.SelectPalette(m_pPalette, FALSE);
UINT uChanged = dc.RealizePalette();
return TRUE;
}
void CScreenSaverWnd1::OnPaletteChanged(CWnd* pFocusWnd)
{
if (pFocusWnd == this)
return;
OnQueryNewPalette();
}
BOOL CScreenSaverWnd1::IsAutoBlack() const
{
return m_bAutoBlack;
}
void CScreenSaverWnd1::SetAutoBlack(BOOL bAutoBlack /* = TRUE */)
{
m_bAutoBlack = bAutoBlack;
}
/////////////////////////////////////////////////////////////////////////////
//
// The message routing for screen saver windows is nonstandard. Calling the
// regular default window proc is not appropriate. These overrides will
// route the messages properly.
//
// For example, when the user hits a key or moves the mouse, if it's not
// handled by the screen saver in some way, it should go to the default
// ::DefScreenSaverProc() which will end the screen saver cleanly.
//
LRESULT CScreenSaverWnd1::WindowProc(UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
return CWnd::WindowProc(uMsg, wParam, lParam);
}
LRESULT CScreenSaverWnd1::DefWindowProc(UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
return ::DefScreenSaverProc(m_hWnd, uMsg, wParam, lParam);
}
/////////////////////////////////////////////////////////////////////////////
// ::ScreenSaverProc():
// This API must be exported to be recognized as a screen saver. This serves
// as the window message proc called by Windows to display the screen saver
// window. Not all messages that go to the window actually get sent to our
// proc.
//
LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
// There should be one global instance of a CScreenSaverWnd derivative.
ASSERT(CScreenSaverWnd1::sm_pTheScreenSaver);
if (!CScreenSaverWnd1::sm_pTheScreenSaver)
return 0L;
// Since we don't have a CWinApp object, we need to initialize the MFC
// internals ourselves, and terminate them when the window is destroyed.
if (!CScreenSaverWnd1::sm_pTheScreenSaver->m_hWnd)
{
AfxWinInit((HINSTANCE)::GetWindowLong(hWnd, GWL_HINSTANCE),
NULL, "", SW_SHOWNORMAL);
CScreenSaverWnd1::sm_pTheScreenSaver->Attach(hWnd);
}
LRESULT lResult =
::AfxCallWndProc(
CScreenSaverWnd1::sm_pTheScreenSaver,
CScreenSaverWnd1::sm_pTheScreenSaver->m_hWnd,
uMsg, wParam, lParam);
if (uMsg == WM_NCDESTROY)
{
ASSERT(!CScreenSaverWnd1::sm_pTheScreenSaver ||
!CScreenSaverWnd1::sm_pTheScreenSaver->m_hWnd);
AfxWinTerm();
}
return lResult;
}
/////////////////////////////////////////////////////////////////////////////
没有合适的资源?快使用搜索试试~ 我知道了~
MFC_screen_protect.rar_屏幕保护程序 vc
共53个文件
h:6个
sbr:5个
cpp:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 119 浏览量
2022-09-24
00:56:54
上传
评论 1
收藏 2.36MB RAR 举报
温馨提示
使用mfc制作屏幕保护程序,一个简单的屏幕保护程序范例!
资源推荐
资源详情
资源评论
收起资源包目录
MFC_screen_protect.rar (53个子文件)
37 用MFC制作屏幕保护程序
MfcSaver.vcproj 7KB
MfcSaver.rc 6KB
MfcSaver.dsp 5KB
MfcSaver.cpp 7KB
res
MfcSaver.ico 1KB
icons.bmp 9KB
MfcSaver.rc2 400B
MfcSaverDlg.cpp 3KB
MfcSaver.005 5KB
MfcSaver.009 5KB
MfcSaver.010 5KB
MfcSaver.003 5KB
ScreenSaverDlg.cpp 6KB
MfcSaver.002 5KB
MfcSaver.004 5KB
MfcSaver.ncb 57KB
MfcSaverDlg.h 2KB
ScreenSaverDlg.h 3KB
ScreenSaverWnd.h 5KB
MfcSaver.008 5KB
MfcSaver.h 2KB
ScreenSaverWnd.cpp 7KB
MfcSaver.006 5KB
StdAfx.cpp 789B
resource.h 685B
MfcSaver.plg 1KB
MfcSaver.007 5KB
StdAfx.h 1KB
MfcSaver.aps 46KB
MfcSaver.clw 1KB
MfcSaver.001 5KB
Debug
StdAfx.obj 53KB
ScreenSaverWnd.sbr 0B
ScreenSaverDlg.sbr 0B
MfcSaver.ilk 280KB
MfcSaver.bsc 2.03MB
MfcSaver.obj 46KB
MfcSaver.res 13KB
MfcSaver.scr 136KB
MfcSaver.pdb 441KB
MfcSaverDlg.obj 14KB
vc60.idb 153KB
ScreenSaverDlg.obj 20KB
StdAfx.sbr 804KB
vc60.pdb 124KB
MfcSaver.sbr 0B
MfcSaverDlg.sbr 0B
ScreenSaverWnd.obj 24KB
MfcSaver.pch 4.64MB
MfcSaver.opt 62KB
MfcSaver.suo 10KB
MfcSaver.sln 905B
MfcSaver.dsw 541B
共 53 条
- 1
资源评论
alvarocfc
- 粉丝: 112
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功