用MFC制作程序启动logo

完了,这次土鳖了,介绍个非常过时的东西,其实就是自己收藏一下,怕以后想用的时候自己忘了。

直接进入正题,首先用ps等工具做一个自己喜欢的程序启动的logo位图,我这里制作的logo大小为500*313,比例为黄金比例,看上去很舒服。

新建mfc工程,把制作好的logo位图添加的资源中去,资源ID号设置为IDB_SPLASH

新建类CSplashWnd,

[cpp]  view plain  copy
  1. #pragma once  
  2. #include "afxwin.h"  
  3.   
  4. class CSplashWnd :  
  5.     public CWnd  
  6. {  
  7. public:  
  8.     CSplashWnd(void);  
  9.     ~CSplashWnd(void);  
  10.     CBitmap m_bitmap;  
  11.     static void ShowSplashScreen(CWnd* pParentWnd = NULL);  
  12. protected:  
  13.     BOOL Create(CWnd* pParentWnd = NULL);     
  14.     static CSplashWnd* c_pSplashWnd;  
  15. public:  
  16.     DECLARE_MESSAGE_MAP()  
  17.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);  
  18.     afx_msg void OnPaint();  
  19.     afx_msg void OnTimer(UINT_PTR nIDEvent);  
  20. };  

为各成员函数添加代码:

[cpp]  view plain  copy
  1. #include "StdAfx.h"  
  2. #include "SplashWnd.h"  
  3. #include "resource.h"  
  4.   
  5. CSplashWnd* CSplashWnd::c_pSplashWnd;  
  6.   
  7. BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)  
  8.     ON_WM_CREATE()  
  9.     ON_WM_PAINT()  
  10.     ON_WM_TIMER()  
  11. END_MESSAGE_MAP()  
  12.   
  13. CSplashWnd::CSplashWnd(void)  
  14. /*: c_pSplashWnd(NULL)*/  
  15. {  
  16. }  
  17.   
  18. CSplashWnd::~CSplashWnd(void)  
  19. {  
  20. }  
  21.   
  22. void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd)  
  23. {  
  24.     c_pSplashWnd = new CSplashWnd;  
  25.     if (!c_pSplashWnd->Create(pParentWnd))  
  26.         delete c_pSplashWnd;  
  27.     else  
  28.         c_pSplashWnd->UpdateWindow();  
  29. }  
  30.   
  31. BOOL CSplashWnd::Create(CWnd* pParentWnd)  
  32. {  
  33.     if (!m_bitmap.LoadBitmap(IDB_SPLASH))   /*加载位图资源,需在资源文件中添加*/  
  34.         return FALSE;  
  35.   
  36.     BITMAP bm;  
  37.     m_bitmap.GetBitmap(&bm);  
  38.   
  39.     return CreateEx(0,  
  40.         AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),  
  41.         NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);  
  42.     return 0;  
  43. }  
  44.   
  45. int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)  
  46. {  
  47.     if (CWnd::OnCreate(lpCreateStruct) == -1)  
  48.         return -1;  
  49.   
  50.     // TODO:  在此添加您专用的创建代码  
  51.     // Center the window.  
  52.     CenterWindow();  
  53.   
  54.     // Set a timer to destroy the splash screen.  
  55.     SetTimer(1, 1000, NULL);                /*设置消隐时间*/  
  56.   
  57.     return 0;  
  58. }  
  59.   
  60. void CSplashWnd::OnPaint()  
  61. {  
  62.     CPaintDC dc(this); // device context for painting  
  63.     // TODO: 在此处添加消息处理程序代码  
  64.     // 不为绘图消息调用 CWnd::OnPaint()  
  65.     CDC dcImage;  
  66.     if (!dcImage.CreateCompatibleDC(&dc))  
  67.         return;  
  68.   
  69.     BITMAP bm;  
  70.     m_bitmap.GetBitmap(&bm);  
  71.   
  72.     // Paint the image.  
  73.     CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);  
  74.     dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);  
  75.     dcImage.SelectObject(pOldBitmap);  
  76. }  
  77.   
  78. void CSplashWnd::OnTimer(UINT_PTR nIDEvent)  
  79. {  
  80.     // TODO: 在此添加消息处理程序代码和/或调用默认值  
  81.     DestroyWindow();  
  82.     AfxGetMainWnd()->UpdateWindow();  
  83.   
  84.     CWnd::OnTimer(nIDEvent);  
  85. }  

其中消隐时间的设置为你喜欢的数值。

接下来,只需在MFC工程中的CMainFrame类中添加函数OnCreate,并在函数定义中添加语句CSplashWnd::ShowSplashScreen(this);

[cpp]  view plain  copy
  1. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)  
  2. {  
  3.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)  
  4.         return -1;  
  5.   
  6.     // TODO:  在此添加您专用的创建代码  
  7.     CSplashWnd::ShowSplashScreen(this);  
  8.   
  9.     return 0;  
  10. }  

好了,你的程序启动logo做好了,编译运行吧,少年!~~


from: http://blog.csdn.net/yang_xian521/article/details/7322619

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值