/
MyInfoWnd.cpp
224 lines (199 loc) · 5.38 KB
/
MyInfoWnd.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
222
223
224
//<<< eWombat [MYINFOWND]
// MyInfoWnd.cpp : Implementierungsdatei
//
#include "stdafx.h"
#include "emule.h"
#include "MyInfoWnd.h"
#include "emuledlg.h"
#include "sockets.h"
#include "TransferWnd.h"
#include "server.h"
#include "MuleToolbarCtrl.h"
// CMyInfoWnd
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CMyInfoWnd, CWnd)
CMyInfoWnd::CMyInfoWnd()
{
m_bIsActive=false;
m_bIsDragging=false;
}
CMyInfoWnd::~CMyInfoWnd()
{
}
BEGIN_MESSAGE_MAP(CMyInfoWnd, CWnd)
ON_WM_CLOSE()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN( )
END_MESSAGE_MAP()
// CMyInfoWnd-Meldungshandler
void CMyInfoWnd::OnClose()
{
m_bIsActive=false;
if (m_hIcon)
DestroyIcon(m_hIcon);
CWnd::OnClose();
}
void CMyInfoWnd::OnDestroy()
{
m_bIsActive=false;
if (m_hIcon)
DestroyIcon(m_hIcon);
CWnd::OnDestroy();
}
void CMyInfoWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
if (m_cList.GetSafeHwnd())
{
CRect rc;
GetClientRect(&rc);
m_cList.SetWindowPos(&wndTop,rc.left,rc.top,rc.Width(),rc.Height(),SWP_NOZORDER);
}
}
void CMyInfoWnd::Show(void)
{
if (!m_bIsActive)
{
//Create Window
// register window class:
CString strClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, LoadCursor(NULL, IDC_ARROW),CBrush(::GetSysColor(COLOR_WINDOW)));
CWnd* pParent = AfxGetApp()->GetMainWnd();
CRect rc,rect;
pParent->GetWindowRect(&rect);
theApp.emuledlg->transferwnd->GetWindowRect(&rc);
pParent->ClientToScreen(&rc);
rc.bottom=rc.top+160;
rc.right=rect.right-GetSystemMetrics(SM_CXFIXEDFRAME);
rc.left=rc.right-348;
if (!CreateEx(NULL , strClass, GetResString(IDS_MYINFO),WS_POPUP |WS_BORDER | WS_VISIBLE
,rc.left,rc.top,rc.Width(),rc.Height(),
pParent ? pParent->GetSafeHwnd() : NULL, NULL))
return;
m_hIcon=theApp.LoadIcon(_T("MyInfo"));
SetIcon(m_hIcon,TRUE);
SetIcon(m_hIcon,FALSE);
GetClientRect(&rc);
if (!m_cList.CreateEx(LVS_EX_FULLROWSELECT,WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_CLIPSIBLINGS|LVS_NOCOLUMNHEADER|LVS_REPORT,rc,(CWnd*)this,1001))
{
DestroyWindow();
return;
}
m_cList.InsertColumn(0, _T(""), LVCFMT_LEFT, 100, -1);
m_cList.InsertColumn(1, _T(""), LVCFMT_LEFT, rc.Width()-100, 1);
m_cList.InsertItem(0,_T("?"));
UpdateInfo();
m_bIsActive=true;
SetTransparent();
ShowWindow(SW_SHOW);
}
else
{
DestroyWindow();
}
}
void CMyInfoWnd::UpdateInfo(void)
{
if (!::IsWindow(m_hWnd) || !::IsWindow(m_cList.m_hWnd))
return;
FillMyInfo(&m_cList,true);
UpdatePos();
}
void CMyInfoWnd::UpdatePos(void)
{
if (!::IsWindow(m_hWnd) || !::IsWindow(m_cList.m_hWnd))
return;
CRect rc,rect;
m_cList.GetItemRect(0,&rc,LVIR_BOUNDS );
int height=4+(m_cList.GetItemCount()*rc.Height());
theApp.emuledlg->toolbar->GetWindowRect(&rc);
//theApp.emuledlg->ClientToScreen(&rc);
rc.left=rc.right-348;
SetWindowPos(&wndTop,rc.left,rc.bottom,rc.Width(),height,NULL);
}
bool CMyInfoWnd::SetTransparent(void)
{
return SetLayeredWindow(this->GetSafeHwnd(),192);
}
void CMyInfoWnd::FillMyInfo(CListCtrl* m_pList,bool bKeys)
{
if (!m_pList)
return;
CString buffer;
m_pList->DeleteAllItems();
m_pList->InsertItem(0,GetResString(IDS_STATUS)+_T(":"));
if (theApp.serverconnect->IsConnected())
m_pList->SetItemText(0, 1, GetResString(IDS_CONNECTED ));
else
m_pList->SetItemText(0, 1, GetResString(IDS_DISCONNECTED ));
if (theApp.IsConnected())
{
m_pList->InsertItem(1,GetResString(IDS_IP) + _T(":") + GetResString(IDS_PORT) );
if (theApp.serverconnect->IsLowID())
buffer=GetResString(IDS_UNKNOWN);
else
{
uint32 myid=theApp.serverconnect->GetClientID();
uint8 d=myid/(256*256*256);myid-=d*(256*256*256);
uint8 c=myid/(256*256);myid-=c*256*256;
uint8 b=myid/(256);myid-=b*256;
buffer.Format(_T("%i.%i.%i.%i:%i"),myid,b,c,d,thePrefs.GetPort());
}
m_pList->SetItemText(1,1,buffer);
buffer.Format(_T("%u"),theApp.serverconnect->GetClientID());
m_pList->InsertItem(2,GetResString(IDS_ID));
if (theApp.IsConnected())
m_pList->SetItemText(2, 1, buffer);
m_pList->InsertItem(3,_T(""));
if (theApp.serverconnect->IsLowID())
m_pList->SetItemText(3, 1,GetResString(IDS_IDLOW));
else
m_pList->SetItemText(3, 1,GetResString(IDS_IDHIGH));
}
if (!bKeys)
return;
int iItem=m_pList->GetItemCount();
buffer=EncodeBase16((const unsigned char*)thePrefs.GetUserHash(), 16);
if (!buffer.IsEmpty())
{
m_pList->InsertItem(iItem,_T("Hash:"));
m_pList->SetItemText(iItem,1,buffer);
iItem++;
}
iItem=m_pList->GetItemCount();
if (theApp.IsConnected())
{
buffer = theApp.serverconnect->GetCurrentServer()->GetListName();
if(!buffer.IsEmpty())
{
m_pList->InsertItem(iItem,_T("Server:"));
m_pList->SetItemText(iItem,1,buffer);
}
}
}
//>>> eWombat [MYINFOWND]
void CMyInfoWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bIsDragging = true;
}
void CMyInfoWnd::OnMouseMove(UINT nFlags, CPoint point)
{
if( !(nFlags & MK_LBUTTON) ) m_bIsDragging = false;
if (m_bIsDragging){
CPoint pt(point); //get our current mouse coordinates
ClientToScreen(&pt); //convert to screen coordinates
CRect rc;
GetClientRect(&rc);
m_cList.SetWindowPos(&wndTop,pt.x,pt.y,rc.Width(),rc.Height(),SWP_NOZORDER);
}
}
void CMyInfoWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bIsDragging = false;
}