forked from irwir/eMule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreditsDlg.cpp
177 lines (141 loc) · 3.96 KB
/
CreditsDlg.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
/*
You may NOT modify this copyright message. You may add your name, if you
changed or improved this code, but you mot not delete any part of this message or
make it invisible etc.
*/
#include "stdafx.h"
#include "emule.h"
#include "CreditsDlg.h"
#include "CreditsThread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// drawable area of the dialog
#define SCREEN_LEFT 6
#define SCREEN_TOP 175
#define SCREEN_RIGHT 345
#define SCREEN_BOTTOM 296
// button to dismiss dialog
#define BUTTON_TOP_Y 0
#define BUTTON_BOTTOM_Y 300
#define BUTTON_LEFT_X 0
#define BUTTON_RIGHT_X 350
/////////////////////////////////////////////////////////////////////////////
// CCreditsDlg dialog
CCreditsDlg::CCreditsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCreditsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCreditsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pDC = NULL;
}
CCreditsDlg::~CCreditsDlg(){
m_imgSplash.DeleteObject();
}
void CCreditsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCreditsDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCreditsDlg, CDialog)
ON_WM_LBUTTONDOWN()
ON_WM_DESTROY()
ON_WM_CREATE()
ON_WM_PAINT()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCreditsDlg message handlers
void CCreditsDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);
// see if they clicked on our button to dismiss the dialog
if((point.x >= BUTTON_LEFT_X) && (point.x <= BUTTON_RIGHT_X))
{
if((point.y >= BUTTON_TOP_Y) && (point.y <= BUTTON_BOTTOM_Y))
{
CDialog::OnOK();
return;
}
}
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}
BOOL CCreditsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
VERIFY( m_imgSplash.Attach(theApp.LoadImage(_T("ABOUT"), _T("JPG"))) );
m_rectScreen.SetRect(SCREEN_LEFT, SCREEN_TOP, SCREEN_RIGHT, SCREEN_BOTTOM);
StartThread();
return TRUE;
}
void CCreditsDlg::OnDestroy()
{
KillThread();
delete m_pDC;
m_pDC = NULL;
CDialog::OnDestroy();
}
void CCreditsDlg::StartThread()
{
m_pThread = new CCreditsThread(this, m_pDC->GetSafeHdc(), m_rectScreen);
if (m_pThread == NULL)
return;
ASSERT_VALID(m_pThread);
m_pThread->m_pThreadParams = NULL;
// Create Thread in a suspended state so we can set the Priority
// before it starts getting away from us
if (!m_pThread->CreateThread(CREATE_SUSPENDED))
{
delete m_pThread;
m_pThread = NULL;
return;
}
// thread priority has been set at idle priority to keep from bogging
// down other apps that may also be running.
VERIFY(m_pThread->SetThreadPriority(THREAD_PRIORITY_IDLE));
// Now the thread can run wild
m_pThread->ResumeThread();
}
void CCreditsDlg::KillThread()
{
// tell thread to shutdown
VERIFY(SetEvent(m_pThread->m_hEventKill));
// wait for thread to finish shutdown
VERIFY(WaitForSingleObject(m_pThread->m_hThread, INFINITE) == WAIT_OBJECT_0);
delete m_pThread;
m_pThread = NULL;
}
int CCreditsDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// m_pDC must be initialized here instead of the constructor
// because the HWND isn't created until Create is called.
m_pDC = new CClientDC(this);
return 0;
}
void CCreditsDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (m_imgSplash.GetSafeHandle())
{
CDC dcMem;
if (dcMem.CreateCompatibleDC(&dc))
{
CBitmap* pOldBM = dcMem.SelectObject(&m_imgSplash);
BITMAP BM;
m_imgSplash.GetBitmap(&BM);
WINDOWPLACEMENT wp;
this->GetWindowPlacement(&wp);
wp.rcNormalPosition.right= wp.rcNormalPosition.left+BM.bmWidth;
wp.rcNormalPosition.bottom= wp.rcNormalPosition.top+BM.bmHeight;
this->SetWindowPlacement(&wp);
dc.BitBlt(0, 0, BM.bmWidth, BM.bmHeight, &dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject(pOldBM);
}
}
}