用vc5 制 作 应 用 程 序 启 动 封 面
很 多 大 型 应 用 程 序 都 有 启 动 封 面, 如word 等 办 公 系 列 软件 和vc + + 等编 程 软 件。 通 过 启 动 封 面, 除 了 显 示 应 用程 序 名 称 和 版 权 等 提 示 画 面,还 可 避 免 由 于 应 用 程 序启 动 前 进 行 大 量 数 据 初 始 化 时, 用 户 较 长 时 间 的等待, 给 应 用 程 序 增 添 了 许 多 动 态 特 性 和 专 业 规 范。 鉴于vc + + 开 发 工 具 应 用 较 广, 这 里 以vc5 为 例 阐 述 启 动封 面 的 一 般 实 现 步 骤。
---- 1. 制 作 封 面 位 图
---- 制 作 应 用 程 序 启 动 封 面 真 彩 位 图, 记 录 位 图 的 高度 和 宽 度, 建 立 所 需要 的 其 他 声 音 等 文 件。
---- 2. 建 立 应 用 程 序
---- 利 用file >new 菜 单 建 立 名 为start 的 多 文 档 应 用 程 序框 架, 并 利 用 类 向导appwizard 增 加 基 类 为generic cwnd 的 新 类csplashwnd,将 新 类 的 文 件 改 名 为splash.h 和splash.cpp, 并 增 加wm -creatb 和wm -paint 的 消 息 映 射 函 数。
---- 3. 定 义 变 量 和 函 数
---- 在splash.h 中 定 义 如 下 成 员 变 量 和 函 数:
public:
bool create(cwnd * pparentwnd=null);
handle hbitssrc;
lpstr pbitssrc;
uint iw,ih;
---- 4. 建 立 启 动 封 面 窗 口
---- 在splash.cpp 中 增 加create 函 数, 建 立 显 示 位 图 的 弹 出 窗口:
#include “windowsx.h” / / 增 加 扩 展 窗 口 建 立
… …
struct{ / / 位 图 文 件 头 结 构
bitmapinfoheader header;
}info;
bool csplashwnd::create(cwnd * pparentwnd)
{ / / 建 立 显 示 位 图 的 弹 出 窗 口
return createex(0,afxregisterwndclass(0,afxgetapp() -〉loadstandardcursor
(idc_arrow)),
null,ws_popup|ws_visible,0,0,672,480,
pparentwnd -〉getsafehwnd(),null);
}
int csplashwnd::oncreate(lpcreatestruct lpcreatestruct)
{ … …
/ / todo:add your specialized creation code here
centerwindow(); / / 使 弹 出 窗 口 居 中
return 0;
}
---- 5. 完 善 析 构 函 数
---- 在splash.cpp 中 完 善 析 构 函 数, 为 显 示 位 图 作 准 备:
csplashwnd::csplashwnd() / / 完 善 析 构 函 数
{iw=672;ih=480; / / 位 图 的 宽 度 和 高 度
info.header.bisize=sizeof(bitmapinfoheader);
info.header.biwidth=iw;
info.header.biheight=ih;
info.header.biplanes=1l;
info.header.bibitcount=24l;
hbitssrc=::globalalloc(ghnd,(long)(iw *ih *3)); / / 分 配 内 存
pbitssrc=(lpstr)::globallock(hbitssrc); / / 加 锁 内 存
}
csplashwnd::csplashwnd()
{::globalunlock(hbitssrc); / / 解 锁 内 存
::globalfree(hbitssrc); / / 释 放 内 存
}
---- 6. 显 示 真 彩 位 图
---- 在splash.cpp 中 完 善onpaint 函 数, 实 现 真 彩 位 图 的 显 示:
void csplashwnd::onpaint()
{ … … / /todo:add your message handler code here
cfile fbmp;
fbmp.open(“c:\\windows\\emc1.bmp”,cfile::moderead|
cfile::typebinary|cfile::shareexclusive); / / 打 开 文 件
fbmp.seek(54,cfile::begin); / / 位 图 文 件 头 为54 字 节