生活随笔
收集整理的這篇文章主要介紹了
程序启动画面
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
載本文示例源代碼
在VC知識庫上看到許多有關(guān)程序啟動畫面的程序而我覺得程序講求的是"簡而易懂",不需要太多的技巧,只要程序?qū)懙某鰜砭秃?于是我以另外一種簡便的方式來設(shè)計程序啟動畫面同時在程序啟動時播放音效,此程序的關(guān)鍵在于Sleep以及PlaySound這兩個API函數(shù)與StrectBlt這個函數(shù)必須記得連結(jié)winmm.lib才可使用PlaySound函數(shù),具體方法如下:
在CSplashWindow::CSplashWindow()建構(gòu)函數(shù)當(dāng)中加載位圖以作為程序啟動畫面
CSplashWindow::CSplashWindow()
{m_Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_SPLASHWINDOW)); //Load Bitmapm_Bitmap.GetBitmap(&bmBitmap); //Get Bitmap Info/*Show Splash Window and Play SplashWindow.wav*/::PlaySound("SplashWindow.wav", NULL, SND_ASYNC | SND_FILENAME);
}
接著是此程序的具體描述
步驟一.
建立三個類別,分別作為程序啟動畫面與主程序
class CSplashWindow : public CWnd //用于程序啟動畫面的SplashWindow類別
{
private:CDC MemDC;BITMAP bmBitmap;CBitmap m_Bitmap;CBitmap *Old_Bitmap;
public:CSplashWindow();~CSplashWindow();void CreateSplash();afx_msg void OnPaint();DECLARE_MESSAGE_MAP()
};class CMainWindow : public CFrameWnd //用于主程序的CMainWindow類別
{
public:CMainWindow();~CMainWindow();
};class CMainWindowApp : public CWinApp //用于程序初始化CMainWindowApp類別
{
public:CMainWindowApp();~CMainWindowApp();virtual BOOL InitInstance();
};
步驟二.
在void CSplashWindow::OnPaint()當(dāng)中使用StrectBlt復(fù)制位圖到SplashWindow以當(dāng)作啟動畫面
void CSplashWindow::OnPaint()
{CPaintDC dc(this);MemDC.CreateCompatibleDC(NULL); //Create Memory DCOld_Bitmap = MemDC.SelectObject(&m_Bitmap); //Select DCdc.StretchBlt(0,0,bmBitmap.bmWidth,bmBitmap.bmHeight, &MemDC, 0,0,bmBitmap.bmWidth, bmBitmap.bmHeight,SRCCOPY);MemDC.SelectObject(Old_Bitmap); //Select Bitmap
}
步驟三.
在void CMainWindowApp::InitInstance()當(dāng)中初始化啟動畫面的相關(guān)設(shè)定
BOOL CMainWindowApp::InitInstance()
{CSplashWindow *m_pSplashWindow = new CSplashWindow;m_pSplashWindow->CreateSplash();m_pSplashWindow->CenterWindow();m_pSplashWindow->ShowWindow(SW_SHOW);m_pSplashWindow->UpdateWindow();Sleep(3000); //Delay 3 Secondsm_pSplashWindow->DestroyWindow(); //Destroy Windowdelete m_pSplashWindow;m_pMainWnd = new CMainWindow;m_pMainWnd->ShowWindow(SW_SHOW);m_pMainWnd->UpdateWindow();return true;
}CMainWindowApp MainWindowApp;
如果您對此程序有任何問題歡迎來信指教r39710@giga.net.tw
總結(jié)
以上是生活随笔為你收集整理的程序启动画面的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。