我的程序启动时加载了很多库文件,所以运行后要等待好久才能出现主界面。我想让它能够有一个启动界面,当主界面完成后让启动界面消失,能够加上进度条自然最好,还有能做成例如GIF动态的等待界面吗?请大家赐教,谢谢!

解决方案 »

  1.   

    用事件对象吧,在主线程中创建事件对象,在启动界面线程中WaitForSingleObject,主线程加载完成后SetEvent
      

  2.   

    http://www.image2003.com/book/down/1921682911620074111627558496418.rar上面是下载地址,191MB,是本好书,值得看。
      

  3.   

    我把这个类的代码,给你了,先是图片部分,你自己做了,因为我们有自己专用的模组了.所以你修改一下就可以了
    .H文件:
    // CG: This file was added by the Splash Screen component.#ifndef _SPLASH_SCRN_
    #define _SPLASH_SCRN_// Splash.h : header file
    //
    /////////////////////////////////////////////////////////////////////////////
    //   Splash Screen class
    class CSplashWnd : public CWnd
    {
    // Construction
    protected:
    CSplashWnd();// Attributes:
    public:
    // CBitmap m_bitmap;
    // Operations
    public:
    static void EnableSplashScreen(BOOL bEnable = TRUE);
    static void ShowSplashScreen(CWnd* pParentWnd = NULL);
    static BOOL PreTranslateAppMessage(MSG* pMsg);
    static CSplashWnd *GetWnd() { return c_pSplashWnd; }
    static void HideSplashScreen();// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CSplashWnd)
    //}}AFX_VIRTUAL// Implementation
    public:
    ~CSplashWnd();
    virtual void PostNcDestroy();protected:
    BOOL Create(CWnd* pParentWnd = NULL);
    static BOOL c_bShowSplashWnd;
    static CSplashWnd* c_pSplashWnd;// Generated message map functions
    protected:
    //{{AFX_MSG(CSplashWnd)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnPaint();
    afx_msg void OnTimer(UINT nIDEvent);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    .cpp // CG: This file was added by the Splash Screen component.
    // Splash.cpp : implementation file
    //#include "stdafx.h"  // e. g. stdafx.h
    #include "resource.h"  // e.g. resource.h#include "Splash.h"  // e.g. splash.h
    #include "prestopm.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char BASED_CODE THIS_FILE[] = __FILE__;
    #endifextern UINT IDM_CREATEDOCVIEW;
    extern CPrestopmApp theApp;
    /////////////////////////////////////////////////////////////////////////////
    //   Splash Screen classBOOL CSplashWnd::c_bShowSplashWnd;
    CSplashWnd* CSplashWnd::c_pSplashWnd;
    CSplashWnd::CSplashWnd()
    {
    m_pSplash = NULL;
    }CSplashWnd::~CSplashWnd()
    {
    // Clear the static window pointer.
    ASSERT(c_pSplashWnd == this);
    c_pSplashWnd = NULL;
    if(m_pSplash)
    delete m_pSplash;
    m_pSplash = NULL;
    }BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
    //{{AFX_MSG_MAP(CSplashWnd)
    ON_WM_CREATE()
    ON_WM_PAINT()
    ON_WM_TIMER()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
    {
    c_bShowSplashWnd = bEnable;
    }void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
    {
    if (!c_bShowSplashWnd)
    return; if(c_pSplashWnd != NULL)
    {
    c_pSplashWnd->KillTimer(1);
    c_pSplashWnd->SetTimer(1, 25000, NULL);
    return;
    } // Allocate a new splash screen, and create the window.
    c_pSplashWnd = new CSplashWnd;
    if (!c_pSplashWnd->Create(pParentWnd))
    delete c_pSplashWnd;
    else
    c_pSplashWnd->UpdateWindow();
    }BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
    {
    if (c_pSplashWnd == NULL)
    return FALSE; // If we get a keyboard or mouse message, hide the splash screen.
    if (pMsg->message == WM_KEYDOWN ||
        pMsg->message == WM_SYSKEYDOWN ||
        pMsg->message == WM_LBUTTONDOWN ||
        pMsg->message == WM_RBUTTONDOWN ||
        pMsg->message == WM_MBUTTONDOWN ||
        pMsg->message == WM_NCLBUTTONDOWN ||
        pMsg->message == WM_NCRBUTTONDOWN ||
        pMsg->message == WM_NCMBUTTONDOWN)
    {
    c_pSplashWnd->HideSplashScreen();
    return TRUE; // message handled here
    } return FALSE; // message not handled
    }BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
    { char szFileName[MAX_PATH];
    GetModuleFileName(NULL, szFileName, sizeof(szFileName));
    *(strrchr(szFileName, '\\') + 1) = NULL;
    strcat(szFileName,"Resource\\splash.bmp"); m_pSplash = new PIsm;
    if(ISM_OpenImage2ISM(szFileName,m_pSplash,LMMT_ANY,NULL))
    {
    return CreateEx(0,
    AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
    NULL, WS_POPUP | WS_VISIBLE, 0, 0, m_pSplash->GetImageWidth(),m_pSplash->GetImageHeight(), 
    pParentWnd->GetSafeHwnd(), NULL);
    }
    ASSERT(0);
    return FALSE;
    }void CSplashWnd::HideSplashScreen()
    {
    // Destroy the window, and update the mainframe.
    CWnd * pWnd = AfxGetMainWnd();
    if (pWnd)
    pWnd->SendMessage(IDM_CREATEDOCVIEW,NULL,NULL); if (c_pSplashWnd) {
    c_pSplashWnd->DestroyWindow();
    }
    }void CSplashWnd::PostNcDestroy()
    {
    // Free the C++ class.
    delete this;
    }int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CWnd::OnCreate(lpCreateStruct) == -1)
    return -1; // Center the window.
    CWnd wnd;
    wnd.Attach(::GetDesktopWindow());
    CenterWindow(&wnd);
    wnd.Detach();
    // Set a timer to destroy the splash screen.
    SetTimer(1, 99000, NULL); return 0;
    }void CSplashWnd::OnPaint()
    {
    CPaintDC dc(this);
    CRect rect(0,0,m_pSplash->GetImageWidth(),m_pSplash->GetImageHeight());
    ISM_DrawImage(&dc,m_pSplash,CPoint(0,0),this->m_hWnd,rect,0); /*
    TCHAR szPmIni[MAX_PATH], szPMName[MAX_PATH], szPMVer[MAX_PATH];
    GetPMINIFileName(PM_INI, szPmIni, sizeof(szPmIni));
    GetPrivateProfileString("ProductInfo", "ProductName", "", szPMName, sizeof(szPMName), szPmIni);
    GetPrivateProfileString("ProductInfo", "ProductVersion", "", szPMVer, sizeof(szPMVer), szPmIni);
    CString strVersion, strCopyRight, strCompany;
    strVersion.Format("PageManager %s", szPMVer); strCopyRight.Format("CopyRights %s. All rights reserved.", "2007");
    strCompany.Format("NewSoft Technology Corporation %s.", "2007");

    CFont labelFont;
    // labelFont.Attach(::GetStockObject(DEFAULT_GUI_FONT));
    labelFont.CreateFont(12,6,0,0, FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial"); int nOldMode = dc.SetBkMode(TRANSPARENT); 
    CGdiObject *pOldBrush = dc.SelectStockObject(NULL_BRUSH);
    CFont *pOldFont = dc.SelectObject(&labelFont);
    int nX = 488, nY = 302;
    CSize size = dc.GetTextExtent(strVersion);
    int nSpace = size.cy;
    dc.SetTextColor(RGB(0, 46, 122));
    dc.SetTextAlign(TA_RIGHT);
    dc.TextOut(nX, nY, strVersion);
    dc.TextOut(nX, nY + nSpace, strCopyRight+strCompany);
    //dc.TextOut(nX, nY + nSpace*2, strCompany); dc.SelectObject(pOldFont);
    dc.SelectObject(pOldBrush);
    dc.SetBkMode(nOldMode);
    labelFont.DeleteObject();
    */

    }void CSplashWnd::OnTimer(UINT nIDEvent)
    {
    // Destroy the splash screen window.
    HideSplashScreen();
    }
     调用:CSplashWnd::ShowSplashScreen(this);
      

  4.   

    如果單純是因爲加載庫的原因引起延遲 用/DELAYLOAD開關看看/DELAYLOAD   (Delay Load Import)
    Home |  Overview |  How Do I |  Linker OptionsSyntax
    /DELAYLOAD:dllnameThis option causes delayed loading of DLLs. The dllname specifies a DLL to delay load. You can use this option as many times as necessary to specify as many DLLs as you choose. You must link your program with Delayimp.lib or implement your own delay-load helper function.The /DELAY option specifies.
      

  5.   

    我用的是VS2005,已经没有splash控件了,所以还是要自己去弄啊……
      

  6.   

    你把源文件给我吧,#include "prestopm.h"这个头文件我没有啊,而且去掉后调试出了N多错误。
      

  7.   

    又出现了一个新的问题:启动界面能够做好,并且是那种慢慢显示出启动界面的。在调试状态下即直接按F5或者ctrl+f5都没有问题,可以看到启动界面,但是直接双击运行生成的可执行文件时启动画面就不见了,这是什么原因呢?
      

  8.   

    1、利用组件库中的Splash Screen组件生成Splash1.cpp 和Splash1.h 这两个文件(也就是基于框架类的应用程序添加启动画面的步骤)
    (1)用Photoshop等制作启动画面图像,保存为bmp格式。 
      (2)用Appwizard建一个基于单文档的工程Splash。 
      (3)在资源中插入位图资源
         打开VC++的资源编辑器,用鼠标右键单击Resources文件夹,选择Import命令,插入所制作的位图。如果位图超过256色,VC会弹出一个对话框,提示位图已经插入但不能在位图编辑器中显示,确定即可。将位图ID改为IDB_SPLASH。
      (4)添加Splash Screen控件
      ①选择菜单“project”/“Add To Project”/“Conponents and Controls”打开对话框,在列表框中双击“Visual C++ Conponents”选项,选择“Splash Screen”控件,然后单击“Insert”。 
      ②确认或修改类名和位图资源ID,单击OK确认。 
      ③编译、连接,漂亮的启动画面就显示出来了。
      (5)如果需要改变启动画面的停留时间,就修改SetTimer()函数的第二个参数,默认是750 毫秒。该函数所在位置:
    int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 

     ... 
       // Set a timer to destroy the splash screen. 
       SetTimer(1, 2000, NULL); //修改第二个参数以调整画面停留时间 
       return 0; 

    这样就生成了Splash1.cpp 和Splash1.h 这两个文件
    2、制作基于对话框的应用程序启动画面
         (1)建立基于对话框的工程Cover。  (2)文件移植 
      ①将Splash1.cpp 和Splash1.h 两个文件从步骤一建立的工程拷贝到Cover工程中,并且分别加入到Source Files和Header Files中; 
      ②导入位图文件到工程的资源中,改ID为IDB_SPLASH。  (3)修改代码,实现启动画面的调用 
      ①添加CCoverApp 的InitInstance() 函数代码
    #include "Splash1.h" //加在Cover.cpp文件的头文件调用部位 
    BOOL CCoverApp::InitInstance() 

    CCommandLineInfo cmdInfo; 
    ParseCommandLine(cmdInfo); 
    CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash); 
    ... 

    ②使用ClassWizard 添加OnCreate() 函数到对话框类CCoverDlg中,并修改代码#include "Splash1.h" //加在CoverDlg.cpp文件的头文件调用部位
    int CCoverDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 

    ... 
    CSplashWnd::ShowSplashScreen(this); //显示启动画面 
    ... 

    3、使得启动画面消失后再显示主程序
         ①在CCoverDlg类中添加WM­_TIMER消息响应函数
            void CCoverDlg::OnTimer(UINT nIDEvent) 
      {
              // TODO: Add your message handler code here and/or call default
              this->MoveWindow(300,300,600,400);
              CDialog::OnTimer(nIDEvent);
    }
    ②    在intCCoverDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)中添加如下代码:
       CSplashWnd::ShowSplashScreen(this);
     this->MoveWindow(0,0,0,0);
     this->SetTimer(1,2000,NULL);//注意这个2000一点要等于步骤1中的2000
     return 0;
    ③在void CCoverDlg::OnPaint()的末尾添加如下代码:
         this->KillTimer(1);
      

  9.   

    http://blog.csdn.net/scq2099yt/archive/2008/03/27/2223575.aspx