Chinaunix首页 | 论坛 | 博客
  • 博客访问: 514447
  • 博文数量: 576
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5020
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:47
文章分类

全部博文(576)

文章存档

2011年(1)

2008年(575)

我的朋友

分类:

2008-10-14 15:01:03

VC启动窗口画面制作方法研究
作者:



源代码运行效果图如下:


1. 概述

前几天在设计软件时,选择VC作为开发工具,想做个启动画面,由于以前没有制作过,所以到网上搜了一通。网上有几篇相关文章,有两篇我觉得很有价值:一篇是关于 为方便显示图像制作的CPicture类的文章,原文是由Paul DiLascia写的解答,很有影响力;还有一篇是关于制作真彩启动画面的文章,不过其限制对位图操作,而不支持jpg, gif,而且使用繁琐,基本上是对Splash Screen组件导入后的代码进行简单修改。琢磨了好大一会儿才学会使用。

有感于现有材料使用起来不方便,随进行了整合和再封装处理,设计了CSplashWnd类,使用起来非常简便。下面就把我设计的类介绍给大家。有什么不当或错误之处,敬请指正。我的Email: zhengxiliu@sohu.com

2.CSplashWnd功能

能够显示真彩启动画面,能在画面上显示初始化文字信息,支持jpg,gif,bmp图像文件。

3. CSplashWnd的设计

3.1 用户关心的接口

用户使用的公开接口:

public: 
CSplashWnd(LPCTSTR lpszFileName);// 指定作为启动画面的图像文件,并装载
BOOL ShowSplash();//显示画面
void CloseSplash();//关闭画面
void ShowText(LPCTSTR pCh);在显示的图像上中间位置处显示初始化信息文字
3.2 其他接口
系统使用的公开接口:(用户不关心)
~CSplashWnd()
void PostNcDestroy();
私有接口:(用户不关心)
BOOL Create(CWnd* pParentWnd = NULL);
int OnCreate(LPCREATESTRUCT lpCreateStruct);
void OnPaint();
3.3 数据设计(用户不关心)
BOOL fileIsValid//指示
CPicture pic;//用于对图像文件进行操作的类
int width,height;
3.4 限制

√ 不允许继承。
√ 为简化接口,只提供从文件装载图像

3.5 需要的头文件

StdAfx.h, VC++6.0自动生成的对MFC的支持,不同的工程选项会产生不同的StdAfx.h。

afxwin.h 支持CRect类

atlbase.h 提供对IPicture (COM类)的支持。

afxpriv2.h提供对CArchiveStream类的支持。

4.类的健壮性和可调试性设计

图像文件是否有效?

需要检查文件是否有效,当装载图像文件失败时,fileIsValid为false,否则为true。这样在调用ShowSplash时将什么都不做,返回false。这时,用户应检查图像文件是否存在,文件名称拼写是否正确。

5. 用法

√ 将CSplashWnd类加入项目中

√ 在使用CSplashWnd类的文件中#include “Splash.h”

√ 在合适的位置定义一个CSplashWnd对象

√ 在想显示启动画面的地方调用ShowSplash显示于屏幕上

√ 如果想在启动画面上显示一些初始化或其他提示信息,调用ShowText。

√ 在你想关闭启动画面的地方

在你的App类InitInstance函数中,显示主窗口之前使用,进行上述步骤,这是最典型的用法,如下面代码所示。

BOOL CTsApp::InitInstance()
{
       AfxEnableControlContainer();
 
#ifdef _AFXDLL
       Enable3dControls();                  // Call this when using MFC in a shared DLL
#else
       Enable3dControlsStatic();   // Call this when linking to MFC statically
#endif

       SetRegistryKey(_T("Local AppWizard-Generated Applications"));
       LoadStdProfileSettings();  // Load standard INI file options (including MRU)

       CSingleDocTemplate* pDocTemplate;
       pDocTemplate = new CSingleDocTemplate(
              IDR_MAINFRAME,
              RUNTIME_CLASS(CTsDoc),
              RUNTIME_CLASS(CMainFrame),       // main SDI frame window
              RUNTIME_CLASS(CTsView));
       AddDocTemplate(pDocTemplate);

       CCommandLineInfo cmdInfo;
       ParseCommandLine(cmdInfo);

       if (!ProcessShellCommand(cmdInfo))
              return FALSE;
 
/////////////////////////////////////////////////////////////////////////////////////
   CSplashWnd* pCsw = new CSplashWnd("fx.jpg");//located in the local directory,or else full-path file name is needed
       pCsw->ShowSplash();
       Sleep(750);//delay some time to observe the image displayed.
       pCsw->CloseSplash();
       delete pCsw;
       pCsw = NULL;
/////////////////////////////////////////////////////////////////////////////////////

       // The one and only window has been initialized, so show and update it.
       m_pMainWnd->ShowWindow(SW_SHOW);
       m_pMainWnd->UpdateWindow();

       return TRUE;
}
6. 类代码

6.1 Splash.h
/////////////////////////////////////////////////////////////////////////////
//Written by Liu Zhengxi
//May 5,2003
//Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 
// too.
/////////////////////////////////////////////////////////////////////////////

#ifndef _SPLASH
#define _SPLASH
#include 

--------------------next---------------------

调试是成功了,但是为什么debug后,点击可执行文件 运行后却又显不出来了呢? ( lonelydeerfdgc 发表于 2003-9-1 17:35:00)
 
我试用成功了,但,如何将图显示在CFormView中哪,请教各位大侠!! ( yuanl 发表于 2003-8-22 23:19:00)
 
这个对编译环境有要求啊?那是怎么回事?需要什么设置么? ( 艾葭 发表于 2003-8-10 21:32:00)
 
你的编译环境能否识别这种操作呀? ( EricWu 发表于 2003-8-10 21:28:00)
 
#include 
.....
protected:
CComQIPtrm_spIPicture; ( brooksong 发表于 2003-8-10 21:25:00)
 
哎呀,错误更多了
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(2945) : error C2065: '_Module' : undeclared identifier
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(2945) : error C2228: left of '.Lock' must have class/struct/union type
c:\program files\microsoft visual studio\vc98\atl\
( 艾葭 发表于 2003-8-10 21:15:00)
 
我试试 ( 艾葭 发表于 2003-8-10 21:08:00)
 
#include  
#include  
#include  // needed for _bstr_t 
#include  // needed for _com_error 
... 
CComQIPtrHRESULT hr = ::OleLoadPicturePath(_bstr_t((LPCTSTR)m_szFilename), NULL, 0, 0, IID_IPicture, (void**) &m_pPicture); 

if (hr != S_OK) 
return FALSE; 


HBITMAP hBitmap = NULL; 
pPicture->get_Handle((OLE_HANDLE*) * hBitmap); 

return hBitmap 

( brooksong 发表于 2003-8-10 21:06:00)
 
很明显"<"与">"编译不能识别 ( greensnow 发表于 2003-8-10 21:05:00)
 
改成IPicture* m_spIPicture试试 ( brooksong 发表于 2003-8-10 21:02:00)
 
.......................................................

--------------------next---------------------

阅读(293) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~