📄 splash.cpp
字号:
//
// Splash.cpp : implementation file
//
#include <atlbase.h>
#include <afxwin.h>
#include <afxpriv2.h>
#include "stdafx.h"
#include "Splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSplashWnd class
////////////////////////////////////////////////////////////////////////////
CSplashWnd::CSplashWnd(LPCTSTR lpszFileName)
{
fileIsValid = pic.Load(lpszFileName);
if(fileIsValid)
{
CSize cz = pic.GetImageSize(NULL);
width = cz.cx;
height = cz.cy;
}
}
////////////////////////////////////////////////////////////////////////////////
CSplashWnd::~CSplashWnd()
{
}
////////////////////////////////////////////////////////////////////////////////
//message map
//
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
//{{AFX_MSG_MAP(CSplashWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////////
//ShowSplash
//to display the given image on screen
//
BOOL CSplashWnd::ShowSplash()
{
if(fileIsValid)
{
if (!Create(AfxGetMainWnd()))
return false;
else
{
UpdateWindow();
return true;
}
}
else
{
return false;
}
}
////////////////////////////////////////////////////////////////////////////////
BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
{
// 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)
{
CloseSplash();
return TRUE; // message handled here
}
return FALSE; // message not handled
}
////////////////////////////////////////////////////////////////////////////////
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
{
return CreateEx(0,
AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
NULL, WS_POPUP | WS_VISIBLE, 0, 0, width, height, pParentWnd->GetSafeHwnd(), NULL);
}
////////////////////////////////////////////////////////////////////////////////
void CSplashWnd::CloseSplash()
{
DestroyWindow();
}
////////////////////////////////////////////////////////////////////////////////
void CSplashWnd::PostNcDestroy()
{
}
////////////////////////////////////////////////////////////////////////////////
int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CenterWindow();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
void CSplashWnd::OnPaint()
{
if(fileIsValid)
{
CPaintDC dc(this);
CRect rc(0,0,0,0);;
pic.Render(&dc, rc);
}
}
void CSplashWnd::ShowText(LPCTSTR lpStr)
{
if(fileIsValid)
{
Invalidate();
CPaintDC dc(this);
dc.SetBkMode(TRANSPARENT);
SIZE sz;
sz = (SIZE)dc.GetTextExtent(lpStr,strlen(lpStr));
dc.TextOut((width-sz.cx)/2,height/2,lpStr);
}
}
CPicture::CPicture()
{
}
CPicture::~CPicture()
{
}
BOOL CPicture::Load(UINT nIDRes)
{
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource(hInst,
MAKEINTRESOURCE(nIDRes),
"IMAGE");
if (!hRsrc)
return FALSE;
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return FALSE;
CMemFile file(lpRsrc, len);
BOOL bRet = Load(file);
FreeResource(hRsrc);
return bRet;
}
BOOL CPicture::Load(LPCTSTR pszPathName)
{
CFile file;
if (!file.Open(pszPathName, CFile::modeRead|CFile::shareDenyWrite))
return FALSE;
BOOL bRet = Load(file);
file.Close();
return bRet;
}
BOOL CPicture::Load(CFile& file)
{
CArchive ar(&file, CArchive::load | CArchive::bNoFlushOnDelete);
return Load(ar);
}
BOOL CPicture::Load(CArchive& ar)
{
CArchiveStream arcstream(&ar);
return Load((IStream*)&arcstream);
}
BOOL CPicture::Load(IStream* pstm)
{
Free();
HRESULT hr = OleLoadPicture(pstm, 0, FALSE,
IID_IPicture, (void**)&m_spIPicture);
ASSERT(SUCCEEDED(hr) && m_spIPicture);
return TRUE;
}
CSize CPicture::GetImageSize(CDC* pDC) const
{
if (!m_spIPicture)
return CSize(0,0);
LONG hmWidth, hmHeight;
m_spIPicture->get_Width(&hmWidth);
m_spIPicture->get_Height(&hmHeight);
CSize sz(hmWidth,hmHeight);
if (pDC==NULL) {
CWindowDC dc(NULL);
dc.HIMETRICtoDP(&sz);
} else {
pDC->HIMETRICtoDP(&sz);
}
return sz;
}
BOOL CPicture::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const
{
ASSERT(pDC);
if (rc.IsRectNull()) {
CSize sz = GetImageSize(pDC);
rc.right = sz.cx;
rc.bottom = sz.cy;
}
long hmWidth,hmHeight;
GetHIMETRICSize(hmWidth, hmHeight);
m_spIPicture->Render(*pDC, rc.left, rc.top, rc.Width(), rc.Height(),
0, hmHeight, hmWidth, -hmHeight, prcMFBounds);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -