Contains the sample source code of this Article
I have seen many programs about the program startup screen in the VC knowledge base, and I think the program is "simple and easy to understand". I don't need too many skills, as long as the program is written, so I used another simple method to design the program startup screen and play the sound during the program startup, the key of this program is the sleep and playsound APIs and the strectblt function must remember to link winmm. the playsound function can be used only in Lib. The method is as follows:
Load bitmap in the csplashwindow: csplashwindow () construction function as the program startup Screen
CSplashWindow::CSplashWindow(){ m_Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_SPLASHWINDOW)); //Load Bitmap m_Bitmap.GetBitmap(&bmBitmap); //Get Bitmap Info /*Show Splash Window and Play SplashWindow.wav*/ ::PlaySound("SplashWindow.wav", NULL, SND_ASYNC | SND_FILENAME);}
Next is the specific description of the program.
Step 1.
Create three categories as program startup screen and main program
Class csplashwindow: Public cwnd // The splashwindow category {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 // The cmainwindow category for the main program {public: cmainwindow (); ~ Cmainwindow () ;}; class cmainwindowapp: Public cwinapp // used for program initialization cmainwindowapp category {public: cmainwindowapp ();~ Cmainwindowapp (); Virtual bool initinstance ();};
Step 2.
Use strectblt in void csplashwindow: onpaint () to copy the bitmap to the splashwindow as the startup screen.
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}
Step 3.
Initialize the startup Screen Settings in void cmainwindowapp: initinstance ().
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 Seconds m_pSplashWindow->DestroyWindow(); //Destroy Window delete m_pSplashWindow; m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return true;}CMainWindowApp MainWindowApp;
If you have any questions about this procedure, please feel free to contact our r39710@giga.net.tw.