vc中有一个 splash 组件,可以显示启动画面

解决方案 »

  1.   

    menu->project->add to project->components and controls->"Visual C++ Components\Splash screen"->rebuild->ok.
      

  2.   

    splash组件加入后,
    怎么不显示呢??
      

  3.   

    什么意思呀???
    splash组件加入后,
    怎么不显示呢?? 
      

  4.   

    #if !defined(AFX_SPLASH_H__AD9E2FA0_527A_11D4_9CBA_444553540001__INCLUDED_)
    #define AFX_SPLASH_H__AD9E2FA0_527A_11D4_9CBA_444553540001__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // Splash.h : header file
    //
    //#include "cdib.h"
    /////////////////////////////////////////////////////////////////////////////
    // CSplash dialogclass CMySplashWnd : public CWnd
    {// Constructionpublic:
    public:
    int USID;
    CDIB dib;
        CMySplashWnd(UINT nBitmapID, UINT nDuration = 2500);// Attributespublic:
        CMySplashWnd(char* bmpname, UINT nDuration = 2500);// Attributespublic:
        BOOL Create();// Operationspublic:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMySplashWnd)
    public:
    virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL// Implementation
    public: // Generated message map functionsprotected: //{{AFX_MSG(CMySplashWnd)
    afx_msg void OnPaint();
    afx_msg void OnTimer(UINT nIDEvent); //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    protected:
    BOOL GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal);
    protected:
    UINT m_nBitmapID;
    UINT m_nDuration;
    UINT m_nTimerID;
    CBitmap m_bitmap;
    CPalette m_pal;
    CWnd m_wndInvisible;
    };
    /////////////////////////////////////////////////////////////////////////////
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
    #endif // !defined(AFX_MYSPLASHWND_H__08C608F3_1FB3_11D1_830E_58A47E000000__INCLUDED_)// Splash.cpp : implementation file
    //#include "stdafx.h"
    #include "Splash.h"
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMySplashWnd
    CMySplashWnd::CMySplashWnd(UINT nBitmapID, UINT nDuration /*= 2500*/)
    {
    m_nBitmapID = nBitmapID;
    m_nDuration = nDuration;
    USID=1;
    }CMySplashWnd::CMySplashWnd(char* bmpname, UINT nDuration /*= 2500*/)
    {
    dib.Open(bmpname);
    USID=0;
    }BEGIN_MESSAGE_MAP(CMySplashWnd, CWnd) //{{AFX_MSG_MAP(CMySplashWnd)
    ON_WM_PAINT()
    ON_WM_TIMER()
    //}}AFX_MSG_MAPEND_MESSAGE_MAP()
    END_MESSAGE_MAP()BOOL CMySplashWnd::Create()
    {
    if( !GetBitmapAndPalette(m_nBitmapID, m_bitmap, m_pal) )
    {
    TRACE1( "Could not load bitmap resource - %d\n", m_nBitmapID );
    return FALSE;
    }
    BITMAP bm;
    m_bitmap.GetObject(sizeof(BITMAP), &bm);
    // First create an invisible window
    m_wndInvisible.CreateEx(WS_EX_TOPMOST, 
    AfxRegisterWndClass(CS_CLASSDC),  _T(""), WS_POPUP, 0, 0, 
    bm.bmWidth, bm.bmHeight, NULL, NULL);
    // Create the the splash window with invisible parent as parent
    BOOL bRetVal = CWnd::CreateEx(WS_EX_TOPMOST, 
    AfxRegisterWndClass(CS_CLASSDC),  _T(""), WS_POPUP, 0, 0, 
    bm.bmWidth, bm.bmHeight, m_wndInvisible.m_hWnd, NULL); CenterWindow();
    ShowWindow(SW_SHOW); UpdateWindow(); //Create the timer.
    m_nTimerID = SetTimer(1, m_nDuration, NULL); ASSERT(m_nTimerID);
    return bRetVal;
    }BOOL CMySplashWnd::GetBitmapAndPalette(UINT nIDResource, CBitmap &bitmap, CPalette &pal)
    { LPCTSTR lpszResourceName = (LPCTSTR)nIDResource;
    HBITMAP hBmp = (HBITMAP)::LoadImage( AfxGetInstanceHandle(), 
    lpszResourceName, IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION );
    if( hBmp == NULL ) 
    return FALSE;
    bitmap.Attach( hBmp );
    // Create a logical palette for the bitmap
    DIBSECTION ds;
    BITMAPINFOHEADER &bmInfo = ds.dsBmih;
    bitmap.GetObject( sizeof(ds), &ds );
    int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 << bmInfo.biBitCount;
    // Create a halftone palette if colors > 256. 
    CClientDC dc(NULL); // Desktop DC
    if( nColors > 256 )
    pal.CreateHalftonePalette( &dc );
    else { // Create the palette
    RGBQUAD *pRGB = new RGBQUAD[nColors]; CDC memDC;
    memDC.CreateCompatibleDC(&dc); memDC.SelectObject( &bitmap );
    ::GetDIBColorTable( memDC, 0, nColors, pRGB );
    UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
    LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300;
    pLP->palNumEntries = nColors;
    for( int i=0; i < nColors; i++)
    {
    pLP->palPalEntry[i].peRed = pRGB[i].rgbRed;
    pLP->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
    pLP->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
    pLP->palPalEntry[i].peFlags = 0; } pal.CreatePalette( pLP ); delete[] pLP;
    delete[] pRGB;
    }
    return TRUE;
    }
    void CMySplashWnd::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting
    // Create a memory DC compatible with the paint DC
    if(USID)
    {
    CDC memDC;
    memDC.CreateCompatibleDC( &dc );
    CBitmap *pBmpOld = memDC.SelectObject( &m_bitmap );
    // Select and realize the palette
    if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && m_pal.m_hObject != NULL )
    {
    dc.SelectPalette( &m_pal, FALSE );
    dc.RealizePalette();
    }
    // Window is same size as bitmap
    CRect rcWnd;
    GetWindowRect( &rcWnd );
    dc.BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &memDC, 0, 0,SRCCOPY);
    // Restore bitmap in memDC memDC.SelectObject( pBmpOld );
    // Do not call CWnd::OnPaint() for painting messages
    }
    else
    dib.Draw(dc.m_hDC,1,1);
    }void CMySplashWnd::OnTimer(UINT nIDEvent)
     { if (m_nTimerID == nIDEvent)
    {
    //Destroy the timer and splash window KillTimer(m_nTimerID);
    m_wndInvisible.DestroyWindow();
      delete this;
    return;
    }  
    CWnd::OnTimer(nIDEvent);
    }BOOL CMySplashWnd::PreTranslateMessage(MSG* pMsg) { ASSERT(pMsg != NULL);
    if (pMsg->message == WM_KEYDOWN ||
    pMsg->message == WM_SYSKEYDOWN ||
    pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_RBUTTONDOWN ||
    pMsg->message == WM_MBUTTONDOWN )
    { //Destroy the timer and splash window
    KillTimer(m_nTimerID);
    m_wndInvisible.DestroyWindow();  delete this;
    return 1;
    }
      return CWnd::PreTranslateMessage(pMsg);
    }
    use:
    in initinstance function:
    splash=new CMySplashWnd(IDB_BITMAP,2000);
    splash->Create();
      

  5.   

    来来来,按下面的做,肯定没问题,我刚做了一个阿    用MFC的应用向导创建一个有主框架结构的应用程序,要使它具有启动画面是很简单的(下面会体验到),而要使一个基于对话框的应用程序也有启动画面则要费些事了,不过按以下笔者的方法则也是很容易的,我主要介绍方法,对画面仅采用默认情况,读者有兴趣可自己加工。 一、给一文档/视图应用程序做启动画面 
      (一) 建立一单文档/视图应用程序Hs   从File菜单选择New对话,在Projects选项卡中选择AppWizard(exe)图标。键入Hs作为项目名并单击OK。在第一步中选中Single Document单选按钮,其它接受所有默认选项。   (二) 添加启动画面   当AppWizard完成,而且Visual C++打开项目的时候,从Project菜单中选择Add To Project,并单击位于次级菜单上的Comonents and Controls…,选择Splash screen组件,如图1(略)所示,单击Insert。接受所有的默认设置。   以上几步就建立起了一个有主框架结构的应用程序,并使它具有了启动画面。这是我们要做的准备工作已经完成。 二、给基于对话框应用程序做启动画面 
      (一)建立基于对话框的应用程序Spla   从File菜单选择New对话,在Projects选项卡中选择AppWizard(exe)图标。键入Spla 作为项目名并单击OK。在第一步中选中Dialog Based单选按钮,其它接受所有默认选项。   (二)做启动画面   这里做启动画面如果仍采用前述用Gallery来插入是不行的,因为基于对话框的应用程序没有主框架。不过我们可以把上面建立起的启动画面文件移植过来,然后,对程序进行少许编程修改就行。请按照下面的步骤来做:   1、将Splash.cpp和Splash.h两个文件从Hs工程中拷贝到你的工程中。添加如下代码到CSplaApp的InitInstance()函数中。   #include "Splash.h"//头文件请放在开始位置
    BOOL CSplaApp::InitInstance()
    {
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
    CSplashWnd::EnableSplashScreen
    (cmdInfo.m_bShowSplash);
    ...
    }
      2、接下来,使用ClassWizard来添加OnCreate函数到你的对话框类中,并且添加如下代码: #include "Splash.h"//头文件请放在开始位置 int CSplaDlg::OnCreate
    (LPCREATESTRUCT lpCreateStruct)
    {

    CSplashWnd::ShowSplashScreen(this);

    }
      3、将Splash16.bmp文件从Hs工程中拷贝到你的工程中。打开Workspace的Resouce项,将Splash16.bmp插入。打开Properties将IDB_BITMAP1改为IDB_SPLASH,这个ID值只要和程序中一致起来就行,现在这样改最简便。   现在可以编译运行程序了,程序运行时出现如图2(略)的启动画面。这是默认的画面,你可以打开图形编辑器自己加工。如果你要改变启动画面的停留时间,就修改SetTime中的第二个参数,这里是750毫秒。 int CSplashWnd::OnCreate
    (LPCREATESTRUCT lpCreateStruct)
    {

    // Set a timer to destroy the splash screen.
    SetTimer(1, 750, NULL);
    return 0;
    }