-
Notifications
You must be signed in to change notification settings - Fork 0
/
Splash.cpp
221 lines (181 loc) · 10.8 KB
/
Splash.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// CG: This file was added by the Splash Screen component.
// Splash.cpp : implementation file
//////////////////////////////////////////////////
//类名:CSplashWnd
//功能:菲屏显示
//作者:徐景周(Johnny Xu, xujingzhou2016@gmail.com)
//组织:未来工作室(Future Studio)
//日期:2001.12.1
//////////////////////////////////////////////////
#include "stdafx.h" // e. g. stdafx.h
#include "resource.h" // e.g. resource.h
#include "Splash.h" // e.g. splash.h
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define MOUSE_MOVE 0xF012
/////////////////////////////////////////////////////////////////////////////
// Splash Screen class
//UINT CSplashWnd::m_nResourceID;
//BOOL CSplashWnd::c_bShowSplashWnd;
//CSplashWnd* CSplashWnd::c_pSplashWnd;
CSplashWnd::CSplashWnd()
{
}
CSplashWnd::~CSplashWnd()
{
// Clear the static window pointer.
// ASSERT(c_pSplashWnd == this);
// c_pSplashWnd = NULL;
if (m_wndOwner.m_hWnd != NULL)
m_wndOwner.DestroyWindow();
}
BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
//{{AFX_MSG_MAP(CSplashWnd)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CSplashWnd::EnableSplashScreen(UINT nResourceID,BOOL bEnable /*= TRUE*/)
{
m_nResourceID = nResourceID;
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)
{
SendMessage(WM_CLOSE);
// c_pSplashWnd->HideSplashScreen();
// SendMessage(WM_LBUTTONUP);
// SendMessage(WM_SYSCOMMAND, MOUSE_MOVE);
return TRUE; // message handled here
}
return FALSE; // message not handled
}
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
{
if (!m_bitmap.LoadBitmap(m_nResourceID))
return FALSE;
BITMAP bm;
m_bitmap.GetBitmap(&bm);
LPCTSTR pszWndClass = AfxRegisterWndClass(0);
VERIFY(m_wndOwner.CreateEx(0, pszWndClass, _T(""), WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, 0));
//Create this window
pszWndClass = AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW));
VERIFY(CreateEx(0, pszWndClass, _T(""), WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, m_wndOwner.GetSafeHwnd(), NULL));
return TRUE;
}
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();
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.
}
void CSplashWnd::OnClose()
{
CWnd::OnClose();
}
/////////////////////////////////////////////////////////////////////////////
// CSplashThread
IMPLEMENT_DYNCREATE(CSplashThread, CWinThread)
CSplashThread::CSplashThread()
{
}
CSplashThread::~CSplashThread()
{
}
BOOL CSplashThread::InitInstance()
{
//Attach this threads UI state to the main one, This will ensure that
//the activation state is managed consistenly across the two threads
ASSERT(AfxGetApp());
BOOL bSuccess = AttachThreadInput(m_nThreadID, AfxGetApp()->m_nThreadID, TRUE);
if (!bSuccess)
TRACE(_T("Failed in call to AttachThredInput, GetLastError:%d\n"), ::GetLastError());
//Create the Splash Screen UI
BOOL bCreated = m_SplashScreen.Create();
VERIFY(bCreated);
m_pMainWnd = &m_SplashScreen;
return bCreated;
}
//设置显示位图资源ID
void CSplashThread::SetBitmapID(UINT nResourceID)
{
m_SplashScreen.EnableSplashScreen(nResourceID,true);
}
//隐藏窗体
void CSplashThread::HideSplash()
{
//Wait until the splash screen has been created
//before trying to close it
while (!m_SplashScreen.GetSafeHwnd());
m_SplashScreen.SendMessage(WM_CLOSE);
}
int CSplashThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CSplashThread, CWinThread)
//{{AFX_MSG_MAP(CSplashThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSplashThread message handlers