-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2PexploreCtrl.cpp
More file actions
346 lines (313 loc) · 10.7 KB
/
Copy pathP2PexploreCtrl.cpp
File metadata and controls
346 lines (313 loc) · 10.7 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// Copyright © 2011, 2026 Ivyware Pty Ltd, Khrustal & Mann
// MELBOURNE, VICTORIA, AUSTRALIA, 3000
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//
// Implementation for P2PexploreCtrl
//
#include "stdafx.h"
#include <afxpriv.h> // For WM_IDLEUPDATECMDUI
#include "P2PexploreCtrl.h"
#include "Msgexception.h"
#include "P2Pwin32.h"
#include "Resource.h"
///////////////////////////////////////////////////////////////////////
// CP2PexploreCtrl dialog
IMPLEMENT_DYNAMIC(CP2PexploreCtrl, CDialog)
CP2PexploreCtrl::CP2PexploreCtrl ( CWnd *pParent /*=NULL*/)
: CDialog ( IDD_P2Pevent, pParent )
{
// Firstly
StartupP2Pevent ( );
m_pP2PeventTreeCtrl = 0;
m_nP2PeventSinkID = 0;
}
CP2PexploreCtrl::~CP2PexploreCtrl()
{
}
void CP2PexploreCtrl::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BOOL CP2PexploreCtrl::Create ( CWnd *pParent )
{
// Locals
BOOL bResult = FALSE;
// Creation
if ( CDialog::Create((UINT)IDD_P2Pevent,pParent) < 0 )
return FALSE;
// P2Pevents tree
m_pP2PeventTreeCtrl = new CTreeCtrl ( );
//this->GetDlgItem (IDC_PIC_P2Pevent
//m_pP2PeventTreeCtrl -> Create ( TVS_HASBUTTONS, oRect, this, IDC_PIC_P2PeventTree );
// P2Pevents registration
// This line was commented out for development and debug purposes
// compiled issue with expected version of CreateP2PeventSink LJm 2025-05-15
//m_nP2PeventSinkID = CreateP2PeventSink ( (DWORD_PTR)m_hWnd, P2PeventCB_HWND );
ASSERT(m_nP2PeventSinkID);
m_dwP2PeventNotn = RegP2PeventCmd ( m_nP2PeventSinkID
, P2Pevent_AddMask, P2Pevotn_FULL );
// Tidy up, and
return bResult;
}
///////////////////////////////////////////////////////////////////////
// MFC Virtual Overrides
//
// OnInitDialog MFC Virtual override
//
BOOL CP2PexploreCtrl::OnInitDialog ( )
{
// Compliments Class Wizard
CDialog::OnInitDialog();
// Create toolbar
// NOTES: Follow CMainFrame pattern with the additional
// CToolBar_OnInitDialog() integration step.
if ( !m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1_P2PeventDlg) ||
!m_wndToolBar.CDialog_OnInitDialog(this) )
{
TRACE0("Failed to create and integrate dialog toolbar\n");
EndDialog ( IDCANCEL );
}
// Size control bars
/*CRect oCRectClientStart;
CRect oCRectClientNow;
GetClientRect ( oCRectClientStart );
RepositionBars ( AFX_IDW_CONTROLBAR_FIRST
, AFX_IDW_CONTROLBAR_LAST
, 0, reposQuery, oCRectClientNow );
// Reposition controls
CPoint oCPointOS( oCRectClientNow.left - oCRectClientStart.left
, oCRectClientNow.top -oCRectClientStart.top );
CRect oCRectChild;
CWnd *pCWndChild = GetWindow ( GW_CHILD );
while ( pCWndChild )
{
pCWndChild->GetWindowRect ( oCRectChild );
ScreenToClient ( oCRectChild );
oCRectChild.OffsetRect ( oCPointOS );
pCWndChild -> MoveWindow ( oCRectChild, FALSE );
pCWndChild = pCWndChild -> GetNextWindow();
}
// Adjust the dialog window dimensions to make room for control bars
CRect oCRectWindow;
GetWindowRect ( oCRectWindow );
oCRectWindow.right += oCRectClientStart.Width() - oCRectClientNow.Width();
oCRectWindow.bottom += oCRectClientStart.Height() - oCRectClientNow.Height();
MoveWindow ( oCRectWindow, FALSE );
// Position Control Bars
RepositionBars ( AFX_IDW_CONTROLBAR_FIRST
, AFX_IDW_CONTROLBAR_LAST, 0 );
// Centre dialog on the screen
//CenterWindow ( );*/
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// CP2PexploreCtrl message handlers
BEGIN_MESSAGE_MAP(CP2PexploreCtrl, CDialog)
ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
ON_MESSAGE(WM_P2PeventNOTN,OnP2PeventNOTN)
ON_COMMAND(ID_P2Pevent_CLEAR, OnP2PeventClear)
ON_UPDATE_COMMAND_UI(ID_P2Pevent_CLEAR, OnUpdateP2PeventClear)
ON_COMMAND(ID_P2Pevent_EVERR, OnP2PeventEVERR)
ON_UPDATE_COMMAND_UI(ID_P2Pevent_EVERR, OnUpdateP2PeventEVERR)
ON_COMMAND(ID_P2Pevent_EVDBG, OnP2PeventEVDBG)
ON_UPDATE_COMMAND_UI(ID_P2Pevent_EVDBG, OnUpdateP2PeventEVDBG)
ON_COMMAND(ID_P2Pevent_EVTRC, OnP2PeventEVTRC)
ON_UPDATE_COMMAND_UI(ID_P2Pevent_EVTRC, OnUpdateP2PeventEVTRC)
END_MESSAGE_MAP()
LRESULT
CP2PexploreCtrl::OnIdleUpdateCmdUI ( WPARAM, LPARAM )
{
SendMessageToDescendants ( WM_IDLEUPDATECMDUI );
return 0L;
}
//
// WM_KICKIDLE message handler
// NOTES: Specifically intercepted and utilised to initiate
// WM_IDLEUPDATECMDUI processing in the integrated CToolBar
void
CP2PexploreCtrl::OnKickIdle ( )
{
SendMessageToDescendants ( WM_IDLEUPDATECMDUI );
}
//
// WM_P2PeventNOTN message handler
// NOTES: P2Pevent notifications from P2Peer API received at random
//
//
// Parameters: WPARAM wParam
// Precipitating P2Pevent object. Handler becomes
// responsible for life cycle
//
// LPARAM lParam
// Not used
//
LRESULT
CP2PexploreCtrl::OnP2PeventNOTN ( WPARAM wParam, LPARAM )
{
// Introduce locals
m_pP2PeventTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE_P2Pevent);
P2Pevent *pP2Pevent = (P2Pevent *)wParam;
if ( pP2Pevent == NULL ) // SNHappen, but
return 0;
HTREEITEM hItemHeader;
// Header
CString strSummary;
strSummary += pP2Pevent -> GetClassText ( );
hItemHeader = m_pP2PeventTreeCtrl -> InsertItem ( strSummary, TVI_ROOT, TVI_LAST );
// Module
if ( _tcslen(pP2Pevent->GetModule()) > 0 )
{
CString strModule("Module: ");
strModule += pP2Pevent->GetModule();
m_pP2PeventTreeCtrl -> InsertItem ( strModule
, hItemHeader, TVI_LAST );
}
// HRESULT
if ( pP2Pevent->GetHRESULT() )
{
CString strHRESULT;
strHRESULT.Format ( _T("HRESULT: [%i] ") );
strHRESULT += pP2Pevent->GetHRESULText();
m_pP2PeventTreeCtrl -> InsertItem ( strHRESULT
, hItemHeader, TVI_LAST );
}
// Message
if ( pP2Pevent->Exists(L"Desc") )
{
CString strMessage("Message: ");
strMessage += (*pP2Pevent)[LDesc].c_wstr();
HTREEITEM hItem = m_pP2PeventTreeCtrl
-> InsertItem ( strMessage, hItemHeader, TVI_LAST );
UNREFERENCED_PARAMETER ( hItem ); // used only by the block commented out below
//if ( (*pP2Pevent)[LDesc].r_Object().IsNode() )
//{
// //P3PmsgNode& oNode = dynamic_cast<P3PmsgNode&>((*pP2Pevent)[LDesc]);
// P3PmsgCurs oCurs ( dynamic_cast<P3PmsgField&>((*pP2Pevent)[LDesc]) );
// for ( int i = 0; oCurs.Goto(i); i++ )
// {
// m_pP2PeventTreeCtrl -> InsertItem ( oCurs.r_data().c_wstr()
// , hItem, TVI_LAST );
// }
//}
}
// Advice
if ( pP2Pevent->Exists(LAdvice) )
{
CString strMessage("Advice: ");
strMessage += (*pP2Pevent)[LAdvice].c_wstr();
HTREEITEM hItem = m_pP2PeventTreeCtrl
-> InsertItem ( strMessage, hItemHeader, TVI_LAST );
UNREFERENCED_PARAMETER ( hItem ); // used only by the block commented out below
//if ( (*pP2Pevent)[LAdvice].r_Object().IsNode() )
//{
// //P3PmsgNode& oNode = dynamic_cast<P3PmsgNode&>((*pP2Pevent)[LAdvice]);
// P3PmsgCurs oCurs ( dynamic_cast<P3PmsgField&>((*pP2Pevent)[LAdvice]) );
// for ( int i = 0; oCurs.Goto(i); i++ )
// {
// m_pP2PeventTreeCtrl -> InsertItem ( oCurs.r_data().c_wstr()
// , hItem, TVI_LAST );
// }
//}
}
// Tidy up and
delete pP2Pevent;
return 0;
}
//
//
// Description: [P2Pevent >> Clear] menu command handlers
// NOTES: Clears P2Pevent list control contents
//
void
CP2PexploreCtrl::OnP2PeventClear ( )
{
m_pP2PeventTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE_P2Pevent);
if ( m_pP2PeventTreeCtrl->m_hWnd )
m_pP2PeventTreeCtrl -> DeleteAllItems ( );
}
void
CP2PexploreCtrl::OnUpdateP2PeventClear ( CCmdUI *pCmdUI )
{
m_pP2PeventTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE_P2Pevent);
if ( m_pP2PeventTreeCtrl->m_hWnd &&
m_pP2PeventTreeCtrl->GetCount() )
pCmdUI -> SetCheck ( TRUE );
else
pCmdUI -> SetCheck ( FALSE );
}
//
//
// Description: [P2Pevent >> EVERR] menu command handlers
// NOTES: Toggles P2Pevent on and off for this object
//
void
CP2PexploreCtrl::OnP2PeventEVERR ( )
{
// Delegate
DWORD dwCmd = P2Pevent_AddMask;
if ( (m_dwP2PeventNotn&P2Pevotn_ERROR) == P2Pevotn_ERROR )
dwCmd = P2Pevent_RemMask;
m_dwP2PeventNotn = RegP2PeventCmd ( m_nP2PeventSinkID
, dwCmd, P2Pevotn_ERROR );
}
void
CP2PexploreCtrl::OnUpdateP2PeventEVERR ( CCmdUI *pCmdUI )
{
// Summarise current state
if ( (m_dwP2PeventNotn&P2Pevotn_ERROR) == P2Pevotn_ERROR )
pCmdUI -> SetCheck ( TRUE );
else
pCmdUI -> SetCheck ( FALSE );
}
void
CP2PexploreCtrl::OnP2PeventEVDBG ( )
{
// Delegate
DWORD dwCmd = P2Pevent_AddMask;
if ( (m_dwP2PeventNotn&P2Pevotn_DEBUG) == P2Pevotn_DEBUG )
dwCmd = P2Pevent_RemMask;
m_dwP2PeventNotn = RegP2PeventCmd ( m_nP2PeventSinkID
, dwCmd, P2Pevotn_DEBUG );
}
void
CP2PexploreCtrl::OnUpdateP2PeventEVDBG ( CCmdUI *pCmdUI )
{
// Summarise current state
if ( (m_dwP2PeventNotn&P2Pevotn_DEBUG) == P2Pevotn_DEBUG )
pCmdUI -> SetCheck ( TRUE );
else
pCmdUI -> SetCheck ( FALSE );
}
void
CP2PexploreCtrl::OnP2PeventEVTRC ( )
{
// Delegate
DWORD dwCmd = P2Pevent_AddMask;
if ( (m_dwP2PeventNotn&P2Pevotn_TRACE) == P2Pevotn_TRACE )
dwCmd = P2Pevent_RemMask;
m_dwP2PeventNotn = RegP2PeventCmd ( m_nP2PeventSinkID
, dwCmd, P2Pevotn_TRACE );
}
void
CP2PexploreCtrl::OnUpdateP2PeventEVTRC ( CCmdUI *pCmdUI )
{
// Summarise current state
if ( (m_dwP2PeventNotn&P2Pevotn_TRACE) == P2Pevotn_TRACE )
pCmdUI -> SetCheck ( TRUE );
else
pCmdUI -> SetCheck ( FALSE );
}