📄 01_9_13_18.asp.html
字号:
<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>计算机世界网-深入浅出屏幕保护程序编程</TITLE></HEAD>
<style>
.a14{font-size:14px;text-indent:25px;line-height:20px}
.f{font-size:18px;color=#0f3ccd}
img{border:0px;}
td,p,input{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<center>
<BODY topmargin=2 leftmargin=0>
<style>
.v12{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<style>
.v13{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v12{font-size:13px;color:"#4C029C";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<!--头-->
<table align=center cellpadding="0" cellspacing="0" border="0" width="767">
<tr><td valign=bottom>
<table cellpadding="0" cellspacing="0" border=0>
<tr><td valign=top><img src="../../../../../center/image/ccwlogo.gif"></td></tr>
<tr><td height="27" valign=top><img src="../../../../../center/image/knowledge.gif" width="207" height="27"></td></tr>
</table></td>
<td valign=bottom width=556 bgcolor="#4c029c" height=96>
<table cellpadding="0" cellspacing="0" border=0 width=556 bgcolor="#4c029c" height=96>
<tr><td height=25 valign=bottom bgcolor="#ffffff" colspan=2 ><img src="../../../../../image2002/top.gif" usemap="#F"></td></tr>
<tr valign=middle >
<td align=center valign=middle height="60" align=center>
<!-- <a href="http://www.ccw.com.cn/search/" target=_blank><img src="../../../../../img2/esearch.GIF" border=0 width=468 height=60></a> --><a href="http://www.ccw.com.cn/html/search/thememail/" target=_blank><img src="../../../../../img2/topbanner_thememail.GIF" border=0 width=468 height=60></a>
</td>
<td align=center width=15%>
<table width=95%>
<tr><td><a href="mailto:center@ccw.com.cn?subject=我要投稿:" target=_blank><font class=v13>我要投稿</a><br><a href="mailto:center@ccw.com.cn?subject=编读往来"><font class=v13>编读往来</a><br><a href="javascript:AddBookMark('计算机世界网首页')"><font class=v13>加入收藏</a></font></td></tr>
</table>
</td>
</tr>
<tr><td bgcolor="#ffffff" height=1 colspan=2 ></td></tr>
<tr><td bgcolor="#b4aafc" height=2 colspan=2 ></td></tr></table>
<map name="F">
<area href="http://www.ccw.com.cn/" shape="rect" coords="29, 3, 61, 18" target=_blank>
<area href="http://www.ccw.com.cn/news1/" shape="rect" coords="72, 3, 143, 18" target=_blank>
<area href="http://www.ccw.com.cn/center/" shape="rect" coords="155, 2, 216, 18" target=_blank>
<area href="http://www.ccw.com.cn/work/" shape="rect" coords="225, 2, 299, 18" target=_blank>
<area href="http://www.ccw.com.cn/search/" shape="rect" coords="310, 3, 364, 19" target=_blank>
<area href="http://www3.ccw.com.cn/" shape="rect" coords="372, 2, 412, 19" target=_blank>
<area href="http://www2.ccw.com.cn/" shape="rect" coords="424, 2, 550, 18" target=_blank></map>
</td></tr>
<tr><td colspan=2 bgcolor="#b4aafc">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td width=26% align=center><font class=v12>【2003年6月24日】 </font></td>
<td CLASS=V12> <a href="http://www.ccw.com.cn/center/topic.asp">专 题</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/tech.asp">技 术</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prod.asp">产 品</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/app.asp">应 用</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/net.asp">网 络</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prog.asp">编 程</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/skill.asp">技 巧</a> </td>
</tr>
</table>
</td></tr>
</table>
<table align=center width=728>
<tr><td align=center><br><h2><font color='#0f3ccd'>深入浅出屏幕保护程序编程</font></h2>
<br><b>北京工业大学 胡击</b>
</td></tr><tr><td align=right>01-9-13 下午 04:11:25<br><hr size=1 width=718 color=#f46240></td></tr></table><br>
<table align=center width=728><tr><td valign=top width=600>
<table width=100% ><tr>
<td class=a14> 读者对屏幕保护程序已经相当熟悉了。去年泰坦尼克号的屏幕保护程序风行了全世界,足见其魅力。有的屏幕保护程序功能十分强大,可以提供图象,动画,音频,视频等所有的多媒体功能。尽管可以很容易获得漂亮的屏幕保护程序,但拥有自己的屏幕保护程序对用户也许更有吸引力。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> VC5.0/6.0是开发屏幕保护程序的好工具。静态链接库SCRNSAVE.LIB对屏幕保护程序提供了支持。SCRNSAVE.LIB包含了建立屏幕保护程序的主程序和缺省功能,用户可以方便地使用SDK进行编程并与之连接。尽管SDK编程相对MFC麻烦,但编写相对简单的屏幕保护程序却相当容易甚至比用MFC编程更简单。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 也可以使用MFC编写屏幕保护程序。但遗憾的是MFC不支持SCRNSAVE.LIB,必须手工完成原来由SCRNSAVE.LIB提供的功能,比较麻烦和不好理解。不过,编写复杂的屏幕保护程序时,MFC对于显示模块和对话框处理可以提供比SDK方便得多的功能。为简单起见先介绍如何使用SDK编写屏幕保护程序。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> <b>一. 屏幕保护程序和SCRNSAVE.LIB </b></td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 先从开发者的角度对屏幕保护程序说明如下: </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 首先,屏幕保护程序是Win32 API 支持一种特殊的应用程序并由系统自动激活。其机制是当条件满足时,系统向当前活动窗口发出字参数
wParam 值为SC_SCREENSAVE 的WM_SYSCOMMAND消息,然后由当前活动窗口执行SYSTEM.INI文件中[boot]区指定的屏幕保护程序。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 屏幕保护程序激活的条件是 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
在规定时间内没有鼠标或键盘输入. </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
当前的活动窗口是标准的WINDOWS应用程序。因为非WINDOWS应用,不会理睬WM_SYSCOMMAND消息。 </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
显然,如果当前活动的程序接管了字参数 wParam 值为SC_SCREENSAVE 的WM_SYSCOMMAND 消息并且不传递到 DefWindowProc函数就可以禁止屏幕保护程序。这对某些运行中不愿意被打断的程序如视频播放,光盘刻录程序特别有用。 </td></tr></table><table width=100% ><tr>
<td class=a14> 其次,可以在控制面板的显示器中选择需要的屏幕保护程序,并可以配置屏幕保护程序的参数。屏幕保护程序应该提供配置屏幕保护程序的对话框。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 再次,屏幕保护程序有特别的输出函数,资源定义和变量声明。SCRNSAVE.LIB包含了建立屏幕保护程序的主程序。屏幕保护程序启动时SCRNSAVE.LIB自动创建一全屏窗口,并描述窗口类为无光标的满黑屏。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 用户编写的屏幕保护程序必须包含三个基本函数ScreenSaverProc,ScreenSaverConfigureDialog
和RegisterDialogClasses 并与SCRNSAVE.LIB连接。 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 1.ScreenSaverProc 窗口函数处理特定的消息并把未处理的消息传递给SCRNSAVE.LIB 。ScreenSaverProc
一般处理以下消息: </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> WM_CREATE 读取.INI或注册表的初始化数据,设置定时器以及其他初始化操作。 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> WM_ERASEBKGND 擦除背景为下一步绘图作准备。 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> WM_TIMER 进行绘图输出。用户可以实现自己的动画功能以及其他操作。 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> WM_DESTROY 删除定时器以及其他对象 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> ScreenSaverProc 把未处理的消息传递到SCRNSAVE.LIB中的 DefScreenSaverProc函数
处理。由它完成许多复杂和关键的操作比如何时激活,何时关闭等,大大方便了屏幕保护程序的编写。 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 2.ScreenSaverConfigureDialog函数处理屏幕保护程序配置对话框。该对话框由控制面板的显示器设置程序调用。用户输入的配置数据输出到.INI或注册表中。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 3. RegisterDialogClasses函数登记屏幕保护程序配置对话框的窗口类。如果不使用特殊的窗口或控件,可以简单地返回TRUE。
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 另外,编写屏幕保护程序还有一些原则。 </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
为使控制面板能够识别,屏幕保护程序的扩展名必须改为.SCR并存放在WINDOWS目录下。 </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
屏幕保护程序的图标(ICON)在资源文件中必须定义为ID_APP。ID_APP由系统的SCRNSAVE.H.定义。 </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
资源文件中必须包含一描述字符串。该字符串用于控制面板显示屏幕保护程序的名字。它必须位于字符串表的首位。SCRNSAVE.H.定义其ID为1。 </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
资源文件中屏幕保护程序配置对话框的ID必须为DLG_SCRNSAVECONFIGURE。它由系统的SCRNSAVE.H.定义。 </td></tr></table><table width=100% ><tr>
<td class=a14 height="15"> <b>二.编程实例</b> </td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 1.最小的屏幕保护程序MiniSaver。这是一个仅包含最基本模块的屏幕保护程序,运行时在屏幕上显示一行活动的文字。步骤如下:
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> 第一步,在VC5.0/6.0中建立32位应用工程(不选MFC WIZARD EXE).建立如下的MiniSaver.CPP文件:
</td>
</tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -