因为软件初始化硬件比较费时,不想让用户看到界面没有反应的样子,可以做了一个进度条,像WINDOWS启动时的进度条一样,来回显示 SplashThread.h #include "StdAfx.h" #include "SplashScreen.h" CSplashScreen::CSplashScreen() { m_pSplashThread=NULL; } CSplashScreen::~CSplashScreen(void) { if ( m_pSplashThread ) { Close(); } } /// 显示窗口 bool CSplashScreen::ShowWindow(CString szMessage, UINT nTime/* =200 */) { if ( !m_pSplashThread ) { m_pSplashThread= new CSplashThread(); m_pSplashThread->m_szMessage= szMessage; m_pSplashThread->m_nTime= nTime; m_pSplashThread->CreateThread(); } return true; } /// 关闭窗口 void CSplashScreen::Close() { m_pSplashThread->PostThreadMessage( WM_QUITSPLASHSCREEN, NULL, NULL); m_pSplashThread=NULL; } SplashThread.cpp #include "StdAfx.h" #include "SplashThread.h" IMPLEMENT_DYNCREATE(CSplashThread, CWinThread) CSplashThread::CSplashThread(void) { m_szMessage=_T("请稍候,正在启动..."); m_nTime= 200; m_pProgress=NULL; m_bAutoDelete=TRUE; } CSplashThread::~CSplashThread(void) { } BEGIN_MESSAGE_MAP(CSplashThread, CWinThread) ON_THREAD_MESSAGE(WM_QUITSPLASHSCREEN, OnQuit) END_MESSAGE_MAP() BOOL CSplashThread::InitInstance() { m_pProgress= new COPWILLProgress(); //一定要加下面的这行,否则如果主界面线程忙碌的话,进度条会没有反应 m_pMainWnd=m_pProgress; m_pProgress->Create(m_szMessage, m_nTime); m_pProgress->ShowWindow(SW_SHOW); return TRUE; } BOOL CSplashThread::ExitInstance() { if ( m_pProgress ) { m_pProgress->DestroyWindow(); delete m_pProgress; } return TRUE; } /// 退出启动条 void CSplashThread::OnQuit(WPARAM wParam,LPARAM lParam) { PostQuitMessage(0); }