1. 程式人生 > >MFC軟體歡迎介面(基於對話方塊,VS2013)

MFC軟體歡迎介面(基於對話方塊,VS2013)


Step1:首先你需要一張BMP格式的圖片,這個工作可以在Photoshop中完成。

Step2:然後我們新建一個mfc工程檔案(基於對話方塊的)


Step3:進入類嚮導新增類,你也可以自己命名



Step4:插入BMP圖片




Step5:mySplash類標頭檔案程式碼編輯mySplash.h

#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();
	~mySplash();
};

Step5:mySplash類資原始檔程式碼編輯mySplash.cpp

#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(); //銷燬初始畫面視窗
}

Step5:在主對話方塊DLG檔案的初始化函式中呼叫(注意,主對話方塊cpp檔案需要包含類的標頭檔案)

	mySplash wndSplash;                 //建立啟動視窗類的例項
	wndSplash.Create(IDB_BITMAP1);     //BMP圖片的ID
	wndSplash.CenterWindow();
	wndSplash.UpdateWindow();          //send WM_PAINT
	Sleep(3000);
	wndSplash.DestroyWindow();//銷燬初始畫面視窗

大功告成