日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MFC中添加Splash Screen

發布時間:2023/12/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MFC中添加Splash Screen 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.? 新建一個MFC項目SDI或MDI。

2.? 新建或導入一個ID為IDB_SPLASH的位圖。

3.? 添加現有項SplashWnd.h和SplashWnd.cpp。

SplashWnd.h源代碼
#ifndef _SPLASH_HEADER_
#define _SPLASH_HEADER_

#pragma once
//#include "afxwin.h"

// CSplashWnd

class CSplashWnd : public CWnd
{
//DECLARE_DYNAMIC(CSplashWnd)

public:
CSplashWnd();
virtual ~CSplashWnd();
virtual void PostNcDestroy();

public:
CBitmap m_bitmap;

protected:
static BOOL c_bShowSplashWnd;
static CSplashWnd* c_pSplashWnd;

public:
static void EnableSplashScreen(BOOL bEnable = TRUE);
static void ShowSplashScreen(CWnd* pParentWnd = NULL);
static BOOL PreTranslateAppMessage(MSG* pMsg);

protected:
BOOL Create(CWnd
* pParentWnd = NULL);
void HideSplashScreen();

afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg
void OnPaint();
afx_msg
void OnTimer(UINT nIDEvent);

protected:
DECLARE_MESSAGE_MAP()
};

#endif
SplashWnd.cpp源代碼 // SplashWnd.cpp : 實現文件
//

#include
"stdafx.h"
#include
"resource.h"
#include
"SplashWnd.h"


// CSplashWnd

//IMPLEMENT_DYNAMIC(CSplashWnd, CWnd)

BOOL CSplashWnd::c_bShowSplashWnd
= FALSE;
CSplashWnd
* CSplashWnd::c_pSplashWnd;

CSplashWnd::CSplashWnd()
{

}

CSplashWnd::
~CSplashWnd()
{
// Clear the static window pointer.
ASSERT(c_pSplashWnd == this);
c_pSplashWnd
= NULL;
}


BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()


void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
{
c_bShowSplashWnd
= bEnable;
}

void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
{
if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
return;
// Allocate a new splash screen, and create the window.
c_pSplashWnd = new CSplashWnd;
if (!c_pSplashWnd->Create(pParentWnd))
delete c_pSplashWnd;
else
c_pSplashWnd
->UpdateWindow();
}

BOOL CSplashWnd::PreTranslateAppMessage(MSG
* pMsg)
{
if (c_pSplashWnd == NULL)
return FALSE;

// If we get a keyboard or mouse message, hide the splash screen.
if (pMsg->message == WM_KEYDOWN ||
pMsg
->message == WM_SYSKEYDOWN ||
pMsg
->message == WM_LBUTTONDOWN ||
pMsg
->message == WM_RBUTTONDOWN ||
pMsg
->message == WM_MBUTTONDOWN ||
pMsg
->message == WM_NCLBUTTONDOWN ||
pMsg
->message == WM_NCRBUTTONDOWN ||
pMsg
->message == WM_NCMBUTTONDOWN)
{
c_pSplashWnd
->HideSplashScreen();
return TRUE; // message handled here
}

return FALSE; // message not handled
}

BOOL CSplashWnd::Create(CWnd
* pParentWnd /*= NULL*/)
{
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);
}


void CSplashWnd::HideSplashScreen()
{
// Destroy the window, and update the mainframe.
DestroyWindow();
AfxGetMainWnd()
->UpdateWindow();
}

void CSplashWnd::PostNcDestroy()
{
// Free the C++ class.
delete this;
}

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, 1000, NULL);

return 0;
}

void CSplashWnd::OnPaint()
{
CPaintDC dc(
this);

CDC dcImage;
if (!dcImage.CreateCompatibleDC(&dc))
return;

BITMAP bm;
m_bitmap.GetBitmap(
&bm);

// Paint the image.
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 nIDEvent)
{
// Destroy the splash screen window.
HideSplashScreen();
}

4.? 在App主程序實現代碼中把上面的頭文件包含進去,并在InitInstance函數中添加下面一段代碼。?

{
  CCommandLineInfo cmdInfo;
  ParseCommandLine(cmdInfo);
  CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
}

5.? 最后,在主框架窗口實現代碼中包含Splash頭文件,在OnCreate函數return前調用CSplashWnd類的ShowSplashScreen函數即可。?

//顯示Splash窗口
CSplashWnd::ShowSplashScreen(this);

?

轉載于:https://www.cnblogs.com/flyandon/archive/2010/09/21/1832475.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的MFC中添加Splash Screen的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。