MFC添加启动splash

本文介绍如何使用MFC实现应用程序的启动画面。通过创建自定义类mySplash继承CWnd,并重写消息映射来实现加载位图资源及定时销毁启动画面窗口的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

添加启动类

 

添加.h和cpp

复制代码
#pragma once
#include "afxwin.h"
class mySplash :
    public CWnd
{
    DECLARE_DYNAMIC(mySplash)

protected:

    DECLARE_MESSAGE_MAP()

public:

    CBitmap m_bitmap;

    void Create(UINT nBitmapID);

    afx_msg void OnPaint();

    afx_msg void OnTimer(UINT_PTR nIDEvent);
public:
    mySplash(void);
    ~mySplash(void);
};
复制代码
复制代码
#include "stdafx.h"

#include "mySplash.h"

IMPLEMENT_DYNAMIC(mySplash, CWnd)

mySplash::mySplash()

{

}

mySplash::~mySplash()

{

}

BEGIN_MESSAGE_MAP(mySplash, CWnd)

    ON_WM_PAINT()

    ON_WM_TIMER()

END_MESSAGE_MAP()

void mySplash::Create(UINT nBitmapID)

{

    m_bitmap.LoadBitmap(nBitmapID);

    BITMAP bitmap;

    m_bitmap.GetBitmap(&bitmap);

    CreateEx(0,AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),NULL, WS_POPUP | WS_VISIBLE, 0, 0, bitmap.bmWidth, bitmap.bmHeight, NULL, NULL);

}

void mySplash::OnPaint()

{

    CPaintDC dc(this); 

    BITMAP bitmap;

    m_bitmap.GetBitmap(&bitmap);

    CDC dcComp;

    dcComp.CreateCompatibleDC(&dc);

    dcComp.SelectObject(&m_bitmap);

    dc.BitBlt(0, 0, bitmap.bmWidth, bitmap.bmHeight, &dcComp, 0, 0, SRCCOPY);

}

void mySplash::OnTimer(UINT_PTR nIDEvent)

{
    DestroyWindow(); //销毁初始画面窗口
}
复制代码

 

而后在initdialog中添加

mySplash wndSplash; //创建启动窗口类的实例
wndSplash.Create(IDB_BITMAP1);
wndSplash.CenterWindow();
wndSplash.UpdateWindow(); //send WM_PAINT
Sleep(2500);
wndSplash.DestroyWindow();//销毁初始画面窗口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值