| 1 |
#if defined(_MSC_VER) |
| 2 |
#pragma comment(lib, "comctl32.lib") |
| 3 |
#endif |
| 4 |
|
| 5 |
#include "UFrmNsmMainDebug.h" |
| 6 |
|
| 7 |
#include <ctime> |
| 8 |
#include <windowsx.h> |
| 9 |
#include <windows.h> |
| 10 |
#include <commctrl.h> |
| 11 |
|
| 12 |
#include "../../Common/UNsmConsts.h" |
| 13 |
#include "../../Common/dummy.h" |
| 14 |
|
| 15 |
#include "UNsmCom.h" |
| 16 |
#include "UNsmSystem.h" |
| 17 |
#include "resource.h" |
| 18 |
#include "nsmsgs.h" |
| 19 |
|
| 20 |
namespace Regnessem |
| 21 |
{ |
| 22 |
namespace System |
| 23 |
{ |
| 24 |
LRESULT CALLBACK NsmMainDebug::DebugWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| 25 |
{ |
| 26 |
NsmMainDebug *const debug = (msg != WM_CREATE) ? |
| 27 |
reinterpret_cast<NsmMainDebug*>(GetWindowLongPtr(hWnd, GWLP_USERDATA)) |
| 28 |
: static_cast<NsmMainDebug*>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams); |
| 29 |
|
| 30 |
if(debug) |
| 31 |
switch(msg) |
| 32 |
{ |
| 33 |
HANDLE_MSG(hWnd, WM_CREATE, debug->Cls_OnCreate); |
| 34 |
HANDLE_MSG(hWnd, WM_SIZE, debug->Cls_OnSize); |
| 35 |
HANDLE_MSG(hWnd, WM_NOTIFY, debug->Cls_OnNotify); |
| 36 |
HANDLE_MSG(hWnd, WM_KEYDOWN, debug->Cls_OnKey); |
| 37 |
HANDLE_MSG(hWnd, WM_DESTROY, debug->Cls_OnDestroy); |
| 38 |
} |
| 39 |
|
| 40 |
return DefWindowProc(hWnd, msg, wParam, lParam); |
| 41 |
} |
| 42 |
|
| 43 |
LRESULT CALLBACK NsmMainDebug::DebugSubProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR /* uIdSubclass */, DWORD_PTR dwRefData) |
| 44 |
{ |
| 45 |
switch(uMsg) |
| 46 |
{ |
| 47 |
case WM_KEYDOWN: |
| 48 |
PostMessage(reinterpret_cast<HWND>(dwRefData), uMsg, wParam, lParam); |
| 49 |
break; |
| 50 |
} |
| 51 |
|
| 52 |
return DefSubclassProc(hWnd, uMsg, wParam, lParam); |
| 53 |
} |
| 54 |
|
| 55 |
// ���i�K���������� |
| 56 |
NsmMainDebug::NsmMainDebug() |
| 57 |
{ |
| 58 |
#if defined(WINCE) |
| 59 |
WNDCLASS wc = {}; |
| 60 |
#else |
| 61 |
WNDCLASSEX wc = {}; |
| 62 |
wc.cbSize = sizeof(wc); |
| 63 |
#endif |
| 64 |
wc.lpszClassName = TEXT("NsmMainDebug"); |
| 65 |
wc.lpfnWndProc = DebugWndProc; |
| 66 |
wc.style = CS_VREDRAW | CS_HREDRAW; |
| 67 |
wc.hInstance = static_cast<HINSTANCE>(GetModuleHandle(NULL)); |
| 68 |
wc.hIcon = static_cast<HICON>(LoadImage(wc.hInstance, |
| 69 |
MAKEINTRESOURCE(IDI_MAINICON), |
| 70 |
IMAGE_ICON, |
| 71 |
0, |
| 72 |
0, |
| 73 |
LR_DEFAULTSIZE | LR_SHARED)); |
| 74 |
|
| 75 |
#if !defined(WINCE) |
| 76 |
RegisterClassEx(&wc); |
| 77 |
#else |
| 78 |
RegisterClass(&wc); |
| 79 |
#endif |
| 80 |
//---------------------------------- |
| 81 |
Handle = CreateWindowEx(0, |
| 82 |
wc.lpszClassName, |
| 83 |
NMM_SYSTEM TEXT("/Debug"), |
| 84 |
WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, |
| 85 |
CW_USEDEFAULT, CW_USEDEFAULT, |
| 86 |
WindowWidth, |
| 87 |
WindowHeight, |
| 88 |
NULL, |
| 89 |
NULL, |
| 90 |
NULL, |
| 91 |
this); |
| 92 |
|
| 93 |
UpdateWindow(Handle); |
| 94 |
|
| 95 |
// [TODO]delegate�������������������Bboost::bind + boost::function? |
| 96 |
g_NsmCom.OnLog = &NsmMainDebug::NsmComLog; |
| 97 |
g_NsmCom.OnServiceListChange = &NsmMainDebug::UpdateServiceList; |
| 98 |
g_NsmCom.OnEventListChange = &NsmMainDebug::UpdateEventList; |
| 99 |
g_NsmSystem.OnConnectionChange = &NsmMainDebug::UpdateConnectionList; |
| 100 |
g_NsmSystem.OnSessionChange = &NsmMainDebug::UpdateSessionList; |
| 101 |
g_NsmSystem.OnModuleChange = &NsmMainDebug::UpdateModuleList; |
| 102 |
} |
| 103 |
|
| 104 |
NsmMainDebug::~NsmMainDebug() |
| 105 |
{ |
| 106 |
g_NsmCom.OnLog = NULL; |
| 107 |
g_NsmCom.OnServiceListChange = NULL; |
| 108 |
g_NsmCom.OnEventListChange = NULL; |
| 109 |
g_NsmSystem.OnConnectionChange = NULL; |
| 110 |
g_NsmSystem.OnSessionChange = NULL; |
| 111 |
g_NsmSystem.OnModuleChange = NULL; |
| 112 |
} |
| 113 |
|
| 114 |
HWND NsmMainDebug::CreateTabChild(HWND parent, const TabChildParam ¶m, UINT_PTR identifier) |
| 115 |
{ |
| 116 |
HWND hwnd = CreateWindowEx(0, |
| 117 |
WC_LISTVIEW, |
| 118 |
NULL, |
| 119 |
WS_CHILD | WS_BORDER | LVS_REPORT, |
| 120 |
0, 0, 0, 0, |
| 121 |
parent, |
| 122 |
reinterpret_cast<HMENU>(identifier), |
| 123 |
NULL, |
| 124 |
NULL); |
| 125 |
|
| 126 |
const DWORD dwStyle = ListView_GetExtendedListViewStyle(hwnd) | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES; |
| 127 |
ListView_SetExtendedListViewStyle(hwnd, dwStyle); |
| 128 |
|
| 129 |
SetWindowSubclass(hwnd, DebugSubProc, reinterpret_cast<UINT_PTR>(hwnd), reinterpret_cast<DWORD_PTR>(parent)); |
| 130 |
|
| 131 |
LVCOLUMN lvcol = {}; |
| 132 |
lvcol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; |
| 133 |
lvcol.fmt = LVCFMT_LEFT; |
| 134 |
|
| 135 |
for(TabChildParam::const_iterator it = param.begin(); it != param.end(); ++lvcol.iSubItem, ++it) |
| 136 |
{ |
| 137 |
lvcol.pszText = const_cast<LPTSTR>(it->first); |
| 138 |
lvcol.cx = it->second; |
| 139 |
ListView_InsertColumn(hwnd, lvcol.iSubItem, &lvcol); |
| 140 |
} |
| 141 |
|
| 142 |
return hwnd; |
| 143 |
} |
| 144 |
|
| 145 |
HWND NsmMainDebug::GetTabChild(int index) const |
| 146 |
{ |
| 147 |
switch(index) |
| 148 |
{ |
| 149 |
case 0: return TabModules; |
| 150 |
case 1: return TabServices; |
| 151 |
case 2: return TabEvents; |
| 152 |
case 3: return TabConnections; |
| 153 |
case 4: return TabSessions; |
| 154 |
case 5: return TabLog; |
| 155 |
case 6: return TabDebug; |
| 156 |
} |
| 157 |
|
| 158 |
return NULL; |
| 159 |
} |
| 160 |
|
| 161 |
void NsmMainDebug::AdjustTabChild() const |
| 162 |
{ |
| 163 |
RECT rc = {}; |
| 164 |
GetClientRect(TabHandle, &rc); |
| 165 |
TabCtrl_AdjustRect(TabHandle, FALSE, &rc); |
| 166 |
|
| 167 |
MoveWindow(GetTabChild(TabCtrl_GetCurSel(TabHandle)), rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); |
| 168 |
} |
| 169 |
|
| 170 |
BOOL NsmMainDebug::Cls_OnCreate(HWND hwnd, const CREATESTRUCT *lpCreateStruct) |
| 171 |
{ |
| 172 |
INITCOMMONCONTROLSEX init = {0}; |
| 173 |
init.dwSize = sizeof(INITCOMMONCONTROLSEX); |
| 174 |
init.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES; |
| 175 |
|
| 176 |
InitCommonControlsEx(&init); |
| 177 |
|
| 178 |
TabHandle = CreateWindowEx(0, |
| 179 |
WC_TABCONTROL, |
| 180 |
NULL, |
| 181 |
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, |
| 182 |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 183 |
hwnd, |
| 184 |
reinterpret_cast<HMENU>(IDTab), |
| 185 |
NULL, |
| 186 |
NULL); |
| 187 |
|
| 188 |
SetWindowSubclass(TabHandle, DebugSubProc, reinterpret_cast<UINT_PTR>(TabHandle), reinterpret_cast<DWORD_PTR>(hwnd)); |
| 189 |
|
| 190 |
TCITEM tcItem = {}; |
| 191 |
tcItem.mask = TCIF_TEXT; |
| 192 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Modules")); |
| 193 |
TabCtrl_InsertItem(TabHandle, 0, &tcItem); |
| 194 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Services")); |
| 195 |
TabCtrl_InsertItem(TabHandle, 1, &tcItem); |
| 196 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Events")); |
| 197 |
TabCtrl_InsertItem(TabHandle, 2, &tcItem); |
| 198 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Connections")); |
| 199 |
TabCtrl_InsertItem(TabHandle, 3, &tcItem); |
| 200 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Sessions")); |
| 201 |
TabCtrl_InsertItem(TabHandle, 4, &tcItem); |
| 202 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Log")); |
| 203 |
TabCtrl_InsertItem(TabHandle, 5, &tcItem); |
| 204 |
tcItem.pszText = const_cast<LPTSTR>(TEXT("Debug")); |
| 205 |
TabCtrl_InsertItem(TabHandle, 6, &tcItem); |
| 206 |
|
| 207 |
// Modules --------------------------------------------------------- |
| 208 |
|
| 209 |
TabChildParam param; |
| 210 |
param.push_back(TabChildParamSub(TEXT("FileName"), 140)); |
| 211 |
param.push_back(TabChildParamSub(TEXT("ModuleName"), 200)); |
| 212 |
param.push_back(TabChildParamSub(TEXT("API Ver"), 60)); |
| 213 |
|
| 214 |
TabModules = CreateTabChild(TabHandle, param, 1); |
| 215 |
|
| 216 |
// Services --------------------------------------------------------- |
| 217 |
|
| 218 |
param.clear(); |
| 219 |
param.push_back(TabChildParamSub(TEXT("ServiceName"), 450)); |
| 220 |
param.push_back(TabChildParamSub(TEXT("ProcAddr"), 100)); |
| 221 |
|
| 222 |
TabServices = CreateTabChild(TabHandle, param, 2); |
| 223 |
|
| 224 |
// Events ----------------------------------------------------------- |
| 225 |
|
| 226 |
param.clear(); |
| 227 |
param.push_back(TabChildParamSub(TEXT("EventName"), 350)); |
| 228 |
param.push_back(TabChildParamSub(TEXT("HookCount"), 100)); |
| 229 |
|
| 230 |
TabEvents = CreateTabChild(TabHandle, param, 3); |
| 231 |
|
| 232 |
// Connections ------------------------------------------------------ |
| 233 |
|
| 234 |
param.clear(); |
| 235 |
param.push_back(TabChildParamSub(TEXT("Handle"), 100)); |
| 236 |
param.push_back(TabChildParamSub(TEXT("Protocol"), 100)); |
| 237 |
param.push_back(TabChildParamSub(TEXT("Caption"), 200)); |
| 238 |
param.push_back(TabChildParamSub(TEXT("Status"), 60)); |
| 239 |
|
| 240 |
TabConnections = CreateTabChild(TabHandle, param, 4); |
| 241 |
|
| 242 |
// Sessions --------------------------------------------------------- |
| 243 |
|
| 244 |
TabSessions = CreateTabChild(TabHandle, param, 5); |
| 245 |
|
| 246 |
// Log -------------------------------------------------------------- |
| 247 |
|
| 248 |
param.clear(); |
| 249 |
param.push_back(TabChildParamSub(TEXT("LogStr"), WindowWidth - 50)); |
| 250 |
|
| 251 |
TabLog = CreateTabChild(TabHandle, param, 6); |
| 252 |
|
| 253 |
// Debug ------------------------------------------------------------ |
| 254 |
|
| 255 |
param.clear(); |
| 256 |
param.push_back(TabChildParamSub(TEXT("LogStr debug"), WindowWidth - 50)); |
| 257 |
|
| 258 |
TabDebug = CreateTabChild(TabHandle, param, 7); |
| 259 |
|
| 260 |
// ---------------------------------------------- |
| 261 |
|
| 262 |
SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(lpCreateStruct->lpCreateParams)); |
| 263 |
|
| 264 |
ShowWindow(TabModules, SW_SHOW); |
| 265 |
|
| 266 |
return TRUE; |
| 267 |
} |
| 268 |
|
| 269 |
void NsmMainDebug::Cls_OnSize(HWND /* hwnd */, UINT /* state */, int cx, int cy) const |
| 270 |
{ |
| 271 |
MoveWindow(TabHandle, 0, 0, cx, cy, TRUE); |
| 272 |
|
| 273 |
AdjustTabChild(); |
| 274 |
} |
| 275 |
|
| 276 |
LRESULT NsmMainDebug::Cls_OnNotify(HWND /* hwnd */, int /* idCtrl */, const NMHDR *pnmh) const |
| 277 |
{ |
| 278 |
switch(pnmh->code) |
| 279 |
{ |
| 280 |
case TCN_SELCHANGING: |
| 281 |
if(pnmh->idFrom == IDTab) |
| 282 |
{ |
| 283 |
const int index = TabCtrl_GetCurSel(pnmh->hwndFrom); |
| 284 |
ShowWindow(GetTabChild(index), SW_HIDE); |
| 285 |
MoveWindow(GetTabChild(index), 0, 0, 0, 0, FALSE); |
| 286 |
} |
| 287 |
break; |
| 288 |
case TCN_SELCHANGE: |
| 289 |
if(pnmh->idFrom == IDTab) |
| 290 |
{ |
| 291 |
const int index = TabCtrl_GetCurSel(pnmh->hwndFrom); |
| 292 |
ShowWindow(GetTabChild(index), SW_SHOW); |
| 293 |
AdjustTabChild(); |
| 294 |
} |
| 295 |
break; |
| 296 |
} |
| 297 |
|
| 298 |
return FALSE; |
| 299 |
} |
| 300 |
|
| 301 |
void NsmMainDebug::Cls_OnKey(HWND /* hwnd */, UINT vk, BOOL /* fDown */, int /* cRepeat */, UINT /* flags */) const |
| 302 |
{ |
| 303 |
switch(vk) |
| 304 |
{ |
| 305 |
case VK_TAB: |
| 306 |
if(GetKeyState(VK_CONTROL) & MINSHORT) |
| 307 |
{ |
| 308 |
const int index = TabCtrl_GetCurSel(TabHandle); |
| 309 |
|
| 310 |
if(GetKeyState(VK_SHIFT) & MINSHORT) |
| 311 |
TabCtrl_SetCurFocus(TabHandle, index ? index - 1 : 6); |
| 312 |
else |
| 313 |
TabCtrl_SetCurFocus(TabHandle, index < 6 ? index + 1 : 0); |
| 314 |
} |
| 315 |
break; |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
void NsmMainDebug::Cls_OnDestroy(HWND /* hwnd */) const |
| 320 |
{ |
| 321 |
PostQuitMessage(0); |
| 322 |
} |
| 323 |
|
| 324 |
// ----------------------------------------------------------------------------- |
| 325 |
|
| 326 |
void NsmMainDebug::UpdateModuleList() const |
| 327 |
{ |
| 328 |
ListView_DeleteAllItems(TabModules); |
| 329 |
|
| 330 |
tstring moduleName = ExtractFileName(Application::ExeName()); |
| 331 |
|
| 332 |
LVITEM item = {0}; |
| 333 |
item.mask = LVIF_TEXT; |
| 334 |
item.iItem = 0; |
| 335 |
item.pszText = const_cast<LPTSTR>(moduleName.c_str()); |
| 336 |
item.iSubItem = 0; |
| 337 |
ListView_InsertItem(TabModules, &item); |
| 338 |
|
| 339 |
item.pszText = const_cast<LPTSTR>(NMM_SYSTEM); |
| 340 |
item.iSubItem = 1; |
| 341 |
ListView_SetItem(TabModules, &item); |
| 342 |
|
| 343 |
item.pszText = const_cast<LPTSTR>(NSM_API_VERSION); |
| 344 |
item.iSubItem = 2; |
| 345 |
ListView_SetItem(TabModules, &item); |
| 346 |
|
| 347 |
//------- |
| 348 |
|
| 349 |
++item.iItem; |
| 350 |
|
| 351 |
const NsmPluginList &p = g_NsmSystem.Plugins; |
| 352 |
for(NsmPluginList::const_iterator it = p.begin(); it != p.end(); ++item.iItem, ++it) |
| 353 |
{ |
| 354 |
moduleName = ExtractFileName((*it)->FileName); |
| 355 |
|
| 356 |
item.pszText = const_cast<LPTSTR>(moduleName.c_str()); |
| 357 |
item.iSubItem = 0; |
| 358 |
ListView_InsertItem(TabModules, &item); |
| 359 |
|
| 360 |
item.pszText = const_cast<LPTSTR>((*it)->PluginInfo.ModuleName.c_str()); |
| 361 |
item.iSubItem = 1; |
| 362 |
ListView_SetItem(TabModules, &item); |
| 363 |
|
| 364 |
item.pszText = const_cast<LPTSTR>((*it)->PluginInfo.ApiVersion.c_str()); |
| 365 |
item.iSubItem = 2; |
| 366 |
ListView_SetItem(TabModules, &item); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
void NsmMainDebug::UpdateServiceList() const |
| 371 |
{ |
| 372 |
ListView_DeleteAllItems(TabServices); |
| 373 |
|
| 374 |
LVITEM item = {0}; |
| 375 |
item.mask = LVIF_TEXT; |
| 376 |
item.iItem = 0; |
| 377 |
|
| 378 |
NsmThreadServiceList::ConstAutoLock lock(g_NsmCom.ServiceList); |
| 379 |
const NsmServiceList &p = lock.List(); |
| 380 |
|
| 381 |
for(NsmServiceList::const_iterator it = p.begin(); it != p.end(); ++item.iItem, ++it) |
| 382 |
{ |
| 383 |
const tstring servName = it->first; |
| 384 |
const tstring servProc = PtrToHex(reinterpret_cast<void*>(it->second->ServiceProc)); |
| 385 |
|
| 386 |
item.pszText = const_cast<LPTSTR>(servName.c_str()); |
| 387 |
item.iSubItem = 0; |
| 388 |
ListView_InsertItem(TabServices, &item); |
| 389 |
|
| 390 |
item.pszText = const_cast<LPTSTR>(servProc.c_str()); |
| 391 |
item.iSubItem = 1; |
| 392 |
ListView_SetItem(TabServices, &item); |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
void NsmMainDebug::UpdateEventList() const |
| 397 |
{ |
| 398 |
ListView_DeleteAllItems(TabEvents); |
| 399 |
|
| 400 |
LVITEM item = {0}; |
| 401 |
item.mask = LVIF_TEXT; |
| 402 |
item.iItem = 0; |
| 403 |
|
| 404 |
NsmThreadEventList::ConstAutoLock lock(g_NsmCom.EventList); |
| 405 |
const NsmEventList &p = lock.List(); |
| 406 |
|
| 407 |
for(NsmEventList::const_iterator it = p.begin(); it != p.end(); ++item.iItem, ++it) |
| 408 |
{ |
| 409 |
const tstring eventName = it->first; |
| 410 |
const tstring eventProc = ToString(it->second->HookProcs.size()); |
| 411 |
|
| 412 |
item.pszText = const_cast<LPTSTR>(eventName.c_str()); |
| 413 |
item.iSubItem = 0; |
| 414 |
ListView_InsertItem(TabEvents, &item); |
| 415 |
|
| 416 |
item.pszText = const_cast<LPTSTR>(eventProc.c_str()); |
| 417 |
item.iSubItem = 1; |
| 418 |
ListView_SetItem(TabEvents, &item); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
void NsmMainDebug::UpdateConnectionList() const |
| 423 |
{ |
| 424 |
ListView_DeleteAllItems(TabConnections); |
| 425 |
|
| 426 |
LVITEM item = {0}; |
| 427 |
item.mask = LVIF_TEXT; |
| 428 |
item.iItem = 0; |
| 429 |
|
| 430 |
NsmThreadConnectionList::ConstAutoLock lock(g_NsmSystem.Connections); |
| 431 |
const NsmConnectionList &p = lock.List(); |
| 432 |
|
| 433 |
for(NsmConnectionList::const_iterator it = p.begin(); it != p.end(); ++item.iItem, ++it) |
| 434 |
{ |
| 435 |
const tstring connHandle = PtrToHex(it->get()); |
| 436 |
const tstring connCaption = w2t((*it)->Caption); |
| 437 |
const tstring connStatus = ToString((*it)->Status); |
| 438 |
|
| 439 |
item.pszText = const_cast<LPTSTR>(connHandle.c_str()); |
| 440 |
item.iSubItem = 0; |
| 441 |
ListView_InsertItem(TabConnections, &item); |
| 442 |
|
| 443 |
item.pszText = const_cast<LPTSTR>((*it)->Protocol.c_str()); |
| 444 |
item.iSubItem = 1; |
| 445 |
ListView_SetItem(TabConnections, &item); |
| 446 |
|
| 447 |
item.pszText = const_cast<LPTSTR>(connCaption.c_str()); |
| 448 |
item.iSubItem = 2; |
| 449 |
ListView_SetItem(TabConnections, &item); |
| 450 |
|
| 451 |
item.pszText = const_cast<LPTSTR>(connStatus.c_str()); |
| 452 |
item.iSubItem = 3; |
| 453 |
ListView_SetItem(TabConnections, &item); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
void NsmMainDebug::UpdateSessionList() const |
| 458 |
{ |
| 459 |
ListView_DeleteAllItems(TabSessions); |
| 460 |
|
| 461 |
LVITEM item = {0}; |
| 462 |
item.mask = LVIF_TEXT; |
| 463 |
item.iItem = 0; |
| 464 |
|
| 465 |
NsmThreadSessionList::ConstAutoLock lock(g_NsmSystem.Sessions); |
| 466 |
const NsmSessionList &p = lock.List(); |
| 467 |
|
| 468 |
for(NsmSessionList::const_iterator it = p.begin(); it != p.end(); ++item.iItem, ++it) |
| 469 |
{ |
| 470 |
const tstring connHandle = PtrToHex(it->get()); |
| 471 |
const tstring connCaption = w2t((*it)->Caption); |
| 472 |
const tstring connStatus = ToString((*it)->Status); |
| 473 |
|
| 474 |
item.pszText = const_cast<LPTSTR>(connHandle.c_str()); |
| 475 |
item.iSubItem = 0; |
| 476 |
ListView_InsertItem(TabSessions, &item); |
| 477 |
|
| 478 |
item.pszText = const_cast<LPTSTR>((*it)->Protocol.c_str()); |
| 479 |
item.iSubItem = 1; |
| 480 |
ListView_SetItem(TabSessions, &item); |
| 481 |
|
| 482 |
item.pszText = const_cast<LPTSTR>(connCaption.c_str()); |
| 483 |
item.iSubItem = 2; |
| 484 |
ListView_SetItem(TabSessions, &item); |
| 485 |
|
| 486 |
item.pszText = const_cast<LPTSTR>(connStatus.c_str()); |
| 487 |
item.iSubItem = 3; |
| 488 |
ListView_SetItem(TabSessions, &item); |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
// ----------------------------------------------------------------------------- |
| 493 |
|
| 494 |
void NsmMainDebug::NsmComLog(const tstring &logStr, bool user) const |
| 495 |
{ |
| 496 |
if(user) |
| 497 |
{ |
| 498 |
int count = ListView_GetItemCount(TabDebug); |
| 499 |
|
| 500 |
if(MaxLogLines <= count) |
| 501 |
{ |
| 502 |
--count; |
| 503 |
ListView_DeleteItem(TabDebug, 0); |
| 504 |
} |
| 505 |
|
| 506 |
LVITEM item = {0}; |
| 507 |
item.mask = LVIF_TEXT; |
| 508 |
item.iItem = count; |
| 509 |
item.pszText = const_cast<LPTSTR>(logStr.c_str()); |
| 510 |
|
| 511 |
ListView_InsertItem(TabDebug, &item); |
| 512 |
} |
| 513 |
else |
| 514 |
{ |
| 515 |
int count = ListView_GetItemCount(TabLog); |
| 516 |
|
| 517 |
if(MaxLogLines <= count) |
| 518 |
{ |
| 519 |
--count; |
| 520 |
ListView_DeleteItem(TabLog, 0); |
| 521 |
} |
| 522 |
|
| 523 |
const tstring str = TimeToStr(time(NULL)) + TEXT(" ") + logStr; |
| 524 |
|
| 525 |
LVITEM item = {0}; |
| 526 |
item.mask = LVIF_TEXT; |
| 527 |
item.iItem = count; |
| 528 |
item.pszText = const_cast<LPTSTR>(str.c_str()); |
| 529 |
|
| 530 |
ListView_InsertItem(TabLog, &item); |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
} |