VC启动窗口画面制作方法研究[图](2)
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 #include // Splash.h : header file///////////////////////////////////////////////////////////////////////////////// Splash Screen class#pragma once///////////////////////////////////////////////////////////////////////////// Picture object―encapsulates IPicture//Written by Paul DiLascia.//used to display picture//// declare CPicture class//class CPicture {public: BOOL Render(CDC* pDC,CRect rc,LPCRECT prcMFBounds=NULL) const; CPicture(); ~CPicture(); // Load from various resources BOOL Load(UINT nIDRes); BOOL Load(LPCTSTR pszPathName); BOOL Load(CFile& file); BOOL Load(CArchive& ar); BOOL Load(IStream* pstm); // render to device context CSize GetImageSize(CDC* pDC=NULL) const; operator IPicture*() { return m_spIPicture; } void GetHIMETRICSize(OLE_XSIZE_HIMETRIC& cx, OLE_YSIZE_HIMETRIC& cy) const { cx = cy = 0; const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Width(&cx); ASSERT(SUCCEEDED(m_hr)); const_cast<CPicture*>(this)->m_hr = m_spIPicture->get_Height(&cy); ASSERT(SUCCEEDED(m_hr)); } void Free() { if (m_spIPicture) { m_spIPicture.Release(); } }protected: CComQIPtr<IPicture>m_spIPicture; // ATL smart pointer to IPicture HRESULT m_hr; // last error code};///////////////////////////////////////////////////////////////////////declare CSplashWnd//class CSplashWnd : public CWnd{// Constructionpublic: CSplashWnd(LPCTSTR lpszFileName);// Operationspublic: BOOL ShowSplash(); BOOL PreTranslateAppMessage(MSG* pMsg); void ShowText(LPCTSTR lpStr); void CloseSplash();// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSplashWnd) //}}AFX_VIRTUAL// Implementationpublic: ~CSplashWnd(); virtual void PostNcDestroy();private: BOOL Create(CWnd* pParentWnd = NULL);// Generated message map functionsprivate: //{{AFX_MSG(CSplashWnd) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP()private: int height;//the height of the displayed picture int width;//the width of the displayed picture CPicture pic;//used to operate the picture BOOL fileIsValid;};#endif6.2 Splash.cpp
- 上一篇:动画窗口的实现-VC++实例一则
- 下一篇:在VC++.net中制作启动屏幕的新方法