如何製作啟動介面 C+/VC
實現閃屏一、安裝splash screen組件 點擊菜單project/add to project/component and control,然後雙擊”visual c++ components” , 選中splash screen組件,接受預設id為 idb_splash.(筆者在此處有疑問,接受預設的id時當程式運行時總沒有閃屏出現,重新取個id就可以了,試試看!)二、插入位元影像用一幅準備好的真彩位元影像替換剛才產生的即可。真彩位元影像在資源編輯器(它不能開啟超過256色的圖片)中是不可視的!或者,點擊resouce view ,在bitmap上點擊滑鼠右鍵,選中“import…”功能表項目,然後選你所要的真彩位元影像資源,把位元影像的id設定為idb_splash.。 三、運行程式編譯、串連,漂亮的真彩啟動位元影像就顯示出來了。就這麼簡單!四、幾點說明 1.如果你要改變啟動畫面的停留時間,就修改settime 中的第二個參數,這裡是750毫秒。int csplashwnd::oncreate(lpcreatestruct lpcreatestruct){ if (cwnd::oncreate(lpcreatestruct) == -1) return -1;
// center the window. centerwindow();
// set a timer to destroy the splash screen. settimer(1, 750, null); 此停留時間為0。75秒,可通過修改第二個參數來改變閃屏時間!
return 0;}2.基於對話方塊的程式不能插入閃屏,可如下設定:首先建立一對話方塊工程,將剛才已經產生的splash.cpp和splash.h檔案拷貝到工作資料夾,並將其加入到你的基於對話方塊的項目中(project->add to project->files...)。在cdialogapp衍生類別的initinstance()中加入下列代碼:#include "splash.h"bool cdialogapp::initinstance(){ // cg: the following block was added by the splash screen component. { ccommandlineinfo cmdinfo; parsecommandline(cmdinfo); csplashwnd::enablesplashscreen(cmdinfo.m_bshowsplash); } ......}使用class wizard為在cdialog衍生類別添加oncreate()函數,並加入下列代碼:#include "splash.h"int cdialogldlg::oncreate(lpcreatestruct lpcreatestruct){ if (cdialog::oncreate(lpcreatestruct) == -1) return -1; // cg: the following line was added by thesplash screen component. csplashwnd::showsplashscreen(this); return 0;}最後將splash.cpp檔案中的csplashwnd::create()函數中的位元影像資源id改為真彩位元影像的id就可以了。bool csplashwnd::create(cwnd* pparentwnd /*= null*/){ if (!m_bitmap.loadbitmap(idb_bitmap1)) return false; ......}