您的位置:首页 > 移动开发

vc中为应用程序制作启动画面的简单方法

2004-07-23 22:03 567 查看
Make a Splash Window for your application
                                                            By  kv300  040723
step 1. first, add the following two files SplashWindow.cpp and SplashWindow.h to your project
/* SplashWindow.cpp */
#include "StdAfx.h"
#include "resource.h"
#include "SplashWindow.h"
#include
BEGIN_MESSAGE_MAP(CSplashWindow, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CSplashWindow::CSplashWindow()
{
 m_Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_SPLASHWINDOW)); //Load Bitmap, must add a bmp to your resource with name IDB_SPLASHWINDOW!!!
 m_Bitmap.GetBitmap(&bmBitmap);         //Get Bitmap Info
 
 /*Play SplashWindow.wav*/
 ::PlaySound("SplashWindow.wav", NULL, SND_ASYNC | SND_FILENAME); // if you need sound effect, add a valid wav file named SplashWindow.wav , and if not, comment this line
}
CSplashWindow::~CSplashWindow()
{
}
void CSplashWindow::Show()
{
 CSplashWindow *m_pSplashWindow = new CSplashWindow;
 m_pSplashWindow->CreateSplash();
 m_pSplashWindow->CenterWindow();
 m_pSplashWindow->ShowWindow(SW_SHOW);
 m_pSplashWindow->UpdateWindow();
 
 Sleep(3000); //Delay 3 Seconds, you can modify it as your idea
 m_pSplashWindow->DestroyWindow(); //Destroy Splash Window
 delete m_pSplashWindow;
}
void CSplashWindow::CreateSplash()
{
 //Create Splash Window
 CreateEx(0,
  AfxRegisterWndClass(
  0,
  AfxGetApp()->LoadStandardCursor(IDC_UPARROW)),
  "Welcome",
  WS_POPUP,
  0,
  0,
  bmBitmap.bmWidth,  //Bitmap Width = Splash Window Width
  bmBitmap.bmHeight, //Bitmap Height = Splash Window Height
  NULL,
  NULL,
  NULL);
  
}

void CSplashWindow::OnPaint()
{
 CPaintDC dc(this);
 MemDC.CreateCompatibleDC(NULL); //Create Memory DC
 Old_Bitmap = MemDC.SelectObject(&m_Bitmap); //Select DC
 dc.StretchBlt(0,
  0,
  bmBitmap.bmWidth,
  bmBitmap.bmHeight,  
  &MemDC,  
  0,
  0,
  bmBitmap.bmWidth,   
  bmBitmap.bmHeight,
  SRCCOPY);
 
 MemDC.SelectObject(Old_Bitmap); //Select Bitmap
}
/* SplashWindow.h */
#ifndef _SPLASH_WONDOW_
#define _SPLASH_WINDOW_
#pragma comment(lib, "winmm.lib") // needed for PlaySound() method
class CSplashWindow : public CWnd
{
private:
 CDC MemDC;
 BITMAP bmBitmap;
 CBitmap m_Bitmap;
 CBitmap* Old_Bitmap;
 CSplashWindow *m_pSplash;
 void CreateSplash();
public:
 CSplashWindow();
 ~CSplashWindow();
 
 static void Show();
 
 afx_msg void OnPaint();
 DECLARE_MESSAGE_MAP()
};
#endif //~_SPLASH_WINDOW_

step 2: Show splash screen in CWinApp::InitInstance()
#include "SplashWindow.h"
.....
// Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);
 
 CSplashWindow::Show(); //show your SplashWindow here
.....
step 3: bulid and run your application...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息