📄 h20000127-28.htm
字号:
<html><head><script language="JavaScript"> function reset(){ for ( var i=0; i < document.Form1.elements.length; i++ ) { document.Form1.elements[i].options[0].selected=true }}function going(url){ parent.location=url; reset();}</script><style><!--A:link {text-decoration: none; color: #000000; font-family: 宋体}A:visited {text-decoration: none; color: #000000; font-family: 宋体}A:active {text-decoration: none; font-family: 宋体}A:hover {text-decoration: underline:#ffffff; color: #ff0000}body,table {font-size: 9pt; font-family: 宋体}.H1 {font-size: 9pt ; line-height:9pt; align=center}.ourfont {font-size: 9pt ; line-height:9pt; }.ourfont1 {font-size: 9pt ; line-height:9pt; }--></style><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>用C++ Builder 3制作屏幕保护程序</title></head><body topmargin="0" leftmargin="0"><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td><p class="content4"><span class="font"><img border="0" height="3" src="../../soft/pix.gif" width="700"></span></td> </tr></tbody></table></center></div><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td bgColor="#3399ff" width="658"><p class="content4"><span class="font"> </span><a style="text-decoration: none; color: rgb(255,255,255)" href="../os/H00705-2.htm">操作系统</a><font color="#FFFFFF"><span class="font"><span> |</span></span></font><a style="color: rgb(255,255,255); text-decoration: none" href="../image/H00705-14.htm">图像处理</a><font color="#FFFFFF"><span>|<span class="font"> </span></span></font><a style="color: rgb(255,255,255); text-decoration: none" href="../autoCAD/H00705-19.htm">辅助设计</a><span class="font"><font color="#FFFFFF"><span> | </span></font></span><a style="color: rgb(255,255,255); text-decoration: none" href="../data/H00705-18.htm">数 据 库</a><span class="font"><font color="#FFFFFF"><span> | </span></font></span><a style="color: rgb(255,255,255); text-decoration: none" href="H00706-1.htm">高级编程</a><span class="font"><font color="#FFFFFF"><span> | </span></font></span><a style="color: rgb(255,255,255); text-decoration: none" href="../netuse/H00705-20.htm">网络应用</a><font color="#FFFFFF"><span><span class="font"> | </span></span></font><a style="color: rgb(255,255,255); text-decoration: none" href="../webpage/H00705-21.htm">网页制作</a><font color="#FFFFFF"><span><span class="font"> |</span></span></font> <a style="color: rgb(255,255,255); text-decoration: none" href="../technic/H00706-3.htm">技术交流</a> <font color="#000000"><strong> <a style="COLOR: rgb(255,255,255); TEXT-DECORATION: none" href="http://202.100.13.77/clslyb/default.asp?clsid=jiaoc">过客留言</a></strong></font></td> <td bgColor="#3399ff" width="32"><p align="center" class="content4"><a href="http://202.100.13.77/clslyb/default.asp?clsid=jiaoc"><img src="../../soft/email.gif" alt="email.gif (493 字节)" border="0" WIDTH="20" HEIGHT="19"></a></td> </tr></tbody></table></center></div><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td align="middle" bgColor="#3399ff" vAlign="top" width="130"></td> <td vAlign="top" width="20"><p class="content4"><img src="../../soft/jiao2.gif" alt="jiao2.gif (176 字节)" WIDTH="14" HEIGHT="14"></td> <td vAlign="top" width="550"><p class="content4" align="center"><span class="font"></span></td> </tr></tbody></table></center></div><div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="700"><tbody> <tr> <td bgColor="#000000" height="1" width="130"><p class="content4"><span class="font"></span></td> <td height="1" width="20"><p class="content4"><span class="font"></span></td> <td bgColor="#000000" height="1" width="200"><p class="content4"><span class="font"></span></td> <td bgColor="#000000" height="1" width="200"><p class="content4"><span class="font"></span></td> <td height="1" width="10"><p class="content4"><span class="font"></span></td> <td bgColor="#000000" height="1" width="140"><p class="content4"><span class="font"></span></td> </tr> <tr> <td align="middle" bgColor="#3399FF" vAlign="top" width="130"><p class="content4" align="center"><span class="font"><br> </span></p> <p class="content4" align="center"><strong><a style="text-decoration: none; color: rgb(255,255,255)" href="../os/H00705-2.htm">操作系统</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../image/H00705-14.htm">图像处理</a></strong><br> <font color="#ff0000"><b><br> </b></font><strong><a style="color: rgb(255,255,255); text-decoration: none" href="../autoCAD/H00705-19.htm">辅助设计</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../data/H00705-18.htm">数 据 库</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="H00706-1.htm">高级编程</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../netuse/H00705-20.htm">网络应用</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../webpage/H00705-21.htm">网页制作</a></strong><br> <br> <strong><a style="color: rgb(255,255,255); text-decoration: none" href="../technic/H00706-3.htm">技术交流</a></strong></p> <div align="center"><center><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tbody></tbody> </table> </center></div><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tbody></tbody> </table> </td> <td align="middle" vAlign="top" width="20"><p align="left" class="content4"><span class="font"><span><br> </span></span></td> <td colSpan="2" vAlign="top" width="400"> <font SIZE="2"><p align="center">用C++ Builder 3制作屏幕保护程序</p> <p>西北工业大学 郭志鹏 </p> <p>---- 屏 幕 保 护 程 序 是 以scr 为 扩 展 名 的 标 准Windows 可 执 行 程 序, 在 激 活 控 制 面 板 的 显 示 器 属 性 的" 屏 幕 保 护 程 序" 页 时, 该 模 块 会 自 动 在Windows 启 动 目 录(Windows 目 录 和 系 统 目 录) 下 查 找 扩 展 名 是scr 的 基 于Windows 的 可 执 行 文 件。 使 用 屏 幕 保 护 程 序, 不 仅 可 以 延 长 显 示 器 的 使 用 寿 命, 还 可 以 保 护 私 人 信 息。 </p> <p>---- 编 制 屏 幕 保 护 程 序 不 仅 要 涉 及 消 息 的 处 理, 还 要 涉 及 命 令 行 参 数 的 处 理。 在WIN32 SDK 文 档 中 描 述 了 编 制 基 于WIN32 的 标 准 的 屏 幕 保 护 程 序 所 必 须 遵 守 的 严 格 标 准。 按 照 这 些 标 准, 屏 幕 保 护 程 序 必 须 要 输 出 两 个 函 数:ScreenSaverProc 和ScreenSaverConfigureDialog, 但 是, 在Windows 系 统 中 的 很 多 屏 幕 保 护 程 序 并 没 有 遵 循 这 些 标 准( 使 用impdef 或 者tdump 实 用 工 具 查 看 即 可)。 并 且 使 用 该 文 档 中 介 绍 的 方 法 编 写 屏 幕 保 护 程 序, 不 仅 要 使 用 资 源 编 辑 器, 并 且 在 链 接 时 还 要 利 用Scrsaver.lib 文 件( 在C++ Builder 3 环 境 下, 不 能 成 功 连 接)。 不 仅 要 涉 及 消 息 的 处 理, 还 要 涉 及 命 令 行 参 数 的 处 理。 </p> <p>---- C++ Builder 3 是 一 种 快 速 的 应 用 程 序 开 发 工 具, 提 供 了 许 多 类 型 的 应 用 程 序 开 发 模 板, 但 没 有 提 供 开 发 屏 幕 保 护 程 序 的 模 板, 并 且 在 其 在 线 帮 助 中 也 没 有 提 及 如 何 开 发 这 类 应 用 程 序。 经 过 本 人 的 研 究, 找 到 了 用C++ Builder3 编 制 屏 幕 保 护 程 序 的 方 法。 </p> <p>---- 在 控 制 面 板 的" 显 示 器 属 性" 项 的" 屏 幕 保 护 程 序" 页 中 进 行 设 置 时, 要 遇 到 三 种 类 型 的 命 令 行 参 数, 并 且, 各 种 情 况 下 的 屏 幕 保 护 程 序 的 显 示 结 果 也 各 不 相 同, 一 般 来 讲, 就 需 要 三 种 类 型 的 窗 体( 或 两 种, 在 随 后 的 内 容 中 讨 论)。 下 面 将 分 四 步 来 具 体 地 说 明 如 何 编 制 屏 幕 保 护 程 序。 </p> <p>---- 一、 屏 幕 保 护 程 序 的 选 择 </p> <p>---- 如 果 在 标 题 为" 屏 幕 保 护 程 序" 的 下 拉 列 表 框 中 选 中 了 某 个 保 护 程 序 时, 系 统 会 自 动 启 动 该 程 序, 这 个 程 序 的 显 示 范 围 是 在 这 个 页 面 上 的 显 示 器 图 形 的 屏 幕 范 围, 同 时, 会 将 两 个 命 令 行 参 数: 一 个 是"/p"; 另 一 个 是 显 示 窗 口 的 句 柄, 传 递 给 这 个 被 选 中 的 程 序。 因 此, 这 类 程 序 首 先 应 该 能 够 处 理 命 令 行 参 数。 在C++ Builder3 中, 与 命 令 行 参 数 处 理 有 关 的 函 数 是:ParamCount() 和ParamStr(), 具 体 的 申 明 方 式 如 下: </p> <p>---- 1 . extern PACKAGE int __fastcall ParamCount(void); </p> <p>---- 该 函 数 返 回 命 令 行 参 数 的 个 数, 但 不 包 含 应 用 程 序 本 身。 </p> <p>---- 2 . extern PACKAGE AnsiString __fastcall ParamStr(int Index); </p> <p>---- 该 函 数 返 回 指 定 索 引 值 的 命 令 行 参 数。ParamStr(0) 返 回 的 是 应 用 程 序 本 身。 </p> <p>---- 所 以, 在 这 以 步 骤 中 的 参 数 判 断 的 语 句 如 下: </p> <p>if(UpperCase(ParamStr(1)) == </p> <p>"-p" || UpperCase(ParamStr(i)) == "/p")</p> <p>{</p> <p>// add the code in here </p> <p>} </p> <p>---- 在 完 成 了 参 数 判 断 后, 就 应 该 对 显 示 窗 口 的 处 理, 为 能 够 使 程 序 在 显 示 器 图 形 的 屏 幕 区 域 内 显 示, 就 要 重 新 设 置 程 序 的 父 窗 口 和 显 示 区 域。 这 要 涉 及 到 父 窗 口 句 柄 的 获 得 及 父 窗 口 的 设 置, 以 及API 函 数 的 调 用。 这 种 环 境 下 的 父 窗 口 句 柄 就 是 传 递 过 来 的 第 二 个 命 令 行 参 数; 要 设 置 父 窗 口, 只 需 设 置 窗 体 的ParentWindow 属 性 即 可。 这 段 程 序 如 下: </p> <p> </p> <p>RECT rc; // Line1</p> <p>HWND hWnd=(HWND)</p> <p>(atol(ParamStr(2).c_str())); // Line2</p> <p>::GetClientRect(hWnd, &rc); // Line3</p> <p>ParentWindow=hWnd; // Line4</p> <p>Left=rc.left; // Line5</p> <p>Top=rc.top; // Line6</p> <p>Width=rc.right-rc.left; // Line7</p> <p>Height=rc.bottom-rc.top; // Line8</p> <p>---- 在 上 面 的 程 序 片 段 中, 第2 行 语 句 是 将 传 递 过 来 的 第2 个 参 数 转 换 成 窗 口 句 柄; 然 后, 第3 行 语 句 利 用 这 个 窗 口 句 柄, 调 用API 函 数 以 获 得 该 窗 口 的 客 户 区 域; 第4 行 语 句 将 选 中 的 屏 幕 保 护 程 序 的 父 窗 口 设 置 为 指 定 的 窗 口; 余 下 的 语 句 是 将 该 程 序 的 窗 口 大 小 设 置 成 副 窗 口 的 客 户 区 大 小。 这 一 程 序 片 段 的 位 置 应 该 是 在 窗 体 的OnCreate 事 件 处 理 中。 </p> <p>---- 需 要 说 明 的 是, 这 种 类 型( 包 括 第 三 步 介 绍 的 窗 体) 的 窗 体 样 式 应 是: </p> <p>FormStyle=fsStayOnTop;</p> <p>---- 窗 体 边 界 的 样 式 应 为: </p> <p>BorderStyle=bsNone;</p> <p>---- 当 然, 这 时 也 不 需 要 鼠 标 图 形, 因 此, 可 以 将 鼠 标 的 形 状 设 为 crNone: </p> <p>Cursor=crNone;</p> <p>---- 二、 初 始 化 参 数 的 设 置 </p> <p>---- 单 击" 显 示 器 属 性" 模 块 的" 屏 幕 保 护 程 序" 页 面 中 的" 设 置" 按 钮 时, 系 统 会 启 动 指 定 的 保 护 程 序 的 初 始 值 设 置 对 话 框, 这 时 传 递 过 来 的 命 令 行 参 数 是:"/c" 或"-c"( 参 数 的 处 理 与 前 面 介 绍 的 相 同)。 通 过 该 对 话 框, 可 以 设 置 保 护 程 序 的 一 些 初 始 参 数, 比 如 图 形 的 变 化 快 慢 等。 在 这 段 程 序 中, 还
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -