生活随笔
收集整理的這篇文章主要介紹了
用MFC制作程序启动logo
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
完了,這次土鱉了,介紹個非常過時的東西,其實就是自己收藏一下,怕以后想用的時候自己忘了。
直接進入正題,首先用ps等工具做一個自己喜歡的程序啟動的logo位圖,我這里制作的logo大小為500*313,比例為黃金比例,看上去很舒服。
新建mfc工程,把制作好的logo位圖添加的資源中去,資源ID號設置為IDB_SPLASH。
新建類CSplashWnd,
[cpp]?view plain
?copy #pragma?once?? #include?"afxwin.h"?? ?? class?CSplashWnd?:?? ????public?CWnd?? {?? public:?? ????CSplashWnd(void);?? ????~CSplashWnd(void);?? ????CBitmap?m_bitmap;?? ????static?void?ShowSplashScreen(CWnd*?pParentWnd?=?NULL);?? protected:?? ????BOOL?Create(CWnd*?pParentWnd?=?NULL);????? ????static?CSplashWnd*?c_pSplashWnd;?? public:?? ????DECLARE_MESSAGE_MAP()?? ????afx_msg?int?OnCreate(LPCREATESTRUCT?lpCreateStruct);?? ????afx_msg?void?OnPaint();?? ????afx_msg?void?OnTimer(UINT_PTR?nIDEvent);?? };??
為各成員函數添加代碼:
[cpp]?view plain
?copy #include?"StdAfx.h"?? #include?"SplashWnd.h"?? #include?"resource.h"?? ?? CSplashWnd*?CSplashWnd::c_pSplashWnd;?? ?? BEGIN_MESSAGE_MAP(CSplashWnd,?CWnd)?? ????ON_WM_CREATE()?? ????ON_WM_PAINT()?? ????ON_WM_TIMER()?? END_MESSAGE_MAP()?? ?? CSplashWnd::CSplashWnd(void)?? ?? {?? }?? ?? CSplashWnd::~CSplashWnd(void)?? {?? }?? ?? void?CSplashWnd::ShowSplashScreen(CWnd*?pParentWnd)?? {?? ????c_pSplashWnd?=?new?CSplashWnd;?? ????if?(!c_pSplashWnd->Create(pParentWnd))?? ????????delete?c_pSplashWnd;?? ????else?? ????????c_pSplashWnd->UpdateWindow();?? }?? ?? BOOL?CSplashWnd::Create(CWnd*?pParentWnd)?? {?? ????if?(!m_bitmap.LoadBitmap(IDB_SPLASH))????? ????????return?FALSE;?? ?? ????BITMAP?bm;?? ????m_bitmap.GetBitmap(&bm);?? ?? ????return?CreateEx(0,?? ????????AfxRegisterWndClass(0,?AfxGetApp()->LoadStandardCursor(IDC_ARROW)),?? ????????NULL,?WS_POPUP?|?WS_VISIBLE,?0,?0,?bm.bmWidth,?bm.bmHeight,?pParentWnd->GetSafeHwnd(),?NULL);?? ????return?0;?? }?? ?? int?CSplashWnd::OnCreate(LPCREATESTRUCT?lpCreateStruct)?? {?? ????if?(CWnd::OnCreate(lpCreateStruct)?==?-1)?? ????????return?-1;?? ?? ?????? ?????? ????CenterWindow();?? ?? ?????? ????SetTimer(1,?1000,?NULL);?????????????????? ?? ????return?0;?? }?? ?? void?CSplashWnd::OnPaint()?? {?? ????CPaintDC?dc(this);??? ?????? ?????? ????CDC?dcImage;?? ????if?(!dcImage.CreateCompatibleDC(&dc))?? ????????return;?? ?? ????BITMAP?bm;?? ????m_bitmap.GetBitmap(&bm);?? ?? ?????? ????CBitmap*?pOldBitmap?=?dcImage.SelectObject(&m_bitmap);?? ????dc.BitBlt(0,?0,?bm.bmWidth,?bm.bmHeight,?&dcImage,?0,?0,?SRCCOPY);?? ????dcImage.SelectObject(pOldBitmap);?? }?? ?? void?CSplashWnd::OnTimer(UINT_PTR?nIDEvent)?? {?? ?????? ????DestroyWindow();?? ????AfxGetMainWnd()->UpdateWindow();?? ?? ????CWnd::OnTimer(nIDEvent);?? }??
其中消隱時間的設置為你喜歡的數值。
接下來,只需在MFC工程中的CMainFrame類中添加函數OnCreate,并在函數定義中添加語句CSplashWnd::ShowSplashScreen(this);
[cpp]?view plain
?copy int?CMainFrame::OnCreate(LPCREATESTRUCT?lpCreateStruct)?? {?? ????if?(CFrameWnd::OnCreate(lpCreateStruct)?==?-1)?? ????????return?-1;?? ?? ?????? ????CSplashWnd::ShowSplashScreen(this);?? ?? ????return?0;?? }??
好了,你的程序啟動logo做好了,編譯運行吧,少年!~~
from:?http://blog.csdn.net/yang_xian521/article/details/7322619
總結
以上是生活随笔為你收集整理的用MFC制作程序启动logo的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。