Fix: let the client log window close and reuse itself

CClientLog was the only sub-connection dialog without ON_WM_CLOSE, so
the close button did nothing and the window stayed until the master
exited. It now wires WM_CLOSE like the other dialogs: it detaches the
context's dialog pointer and cancels the log sub-connection before
destroying, so the client's three-second log push loop stops instead of
posting increments to a destroyed window.

Every menu click also opened a new dialog and a new log sub-connection:
the client starts one per COMMAND_QUERY_LOG, and each arrives on a new
context whose hDlg is empty, so the existing "append to open dialog"
path never matched. The master now keeps one log window per client id;
a repeat request closes the previous sub-connection, rebinds the window
to the new one and refreshes the snapshot instead of opening another.

Verified on the Debug server: WM_CLOSE destroys the window, two extra
clicks keep a single window, and the main connection stays online.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-30 13:30:58 +01:00
1 parent 381a7f85a0
commit f1315a8790
4 files changed
+71 -3

No files matched your search

+41 -3
View File
@@ -15305,11 +15305,49 @@ LRESULT CMy2015RemoteDlg::OnOpenClientLogDialog(WPARAM wParam, LPARAM lParam)
std::string initLog = pInitLog ? *pInitLog : "";
delete pInitLog;
CONTEXT_OBJECT* ctx = reinterpret_cast<CONTEXT_OBJECT*>(lParam);
const uint64_t cid = ctx ? ctx->GetClientID() : 0;
// 同一主机只保留一个日志窗口。每点一次菜单客户端都会新开一条日志子连接,
// 旧实现每来一条就新建窗口,点七八次就有七八个窗口、七八条推送连接。
// 复用旧窗口:关掉旧子连接,把窗口接到新子连接上,并刷新整份快照。
if (cid != 0) {
auto it = m_LogDlgWindows.find(cid);
if (it != m_LogDlgWindows.end()) {
CClientLog* dlg = dynamic_cast<CClientLog*>(CWnd::FromHandlePermanent(it->second));
if (dlg != nullptr && ::IsWindow(dlg->GetSafeHwnd()) && dlg->GetClientID() == cid) {
CONTEXT_OBJECT* oldCtx = dlg->m_ContextObject;
if (oldCtx && oldCtx != ctx) {
if (oldCtx->hDlg == dlg) {
oldCtx->hDlg = nullptr;
oldCtx->hWnd = nullptr;
}
oldCtx->CancelIO();
// 等旧的 OnReceiveComplete 收尾,再换上下文,避免并发读 m_ContextObject。
for (int i = 0; i < 50 && dlg->IsProcessing(); ++i)
Sleep(10);
}
if (ctx)
dlg->UpdateContext(ctx, cid);
dlg->ResetLog(initLog);
if (dlg->IsIconic())
dlg->ShowWindow(SW_RESTORE);
dlg->ShowWindow(SW_SHOW);
dlg->SetForegroundWindow();
return 0;
}
m_LogDlgWindows.erase(it);
}
}
OpenDialog<CClientLog, IDD_DIALOG_CLIENT_LOG>(0, lParam);
CONTEXT_OBJECT* ctx = reinterpret_cast<CONTEXT_OBJECT*>(lParam);
if (ctx && ctx->hDlg && !initLog.empty())
static_cast<CClientLog*>(ctx->hDlg)->AppendLog(initLog);
if (ctx && ctx->hDlg) {
if (cid != 0)
m_LogDlgWindows[cid] = static_cast<CDialogBase*>(ctx->hDlg)->GetSafeHwnd();
if (!initLog.empty())
static_cast<CClientLog*>(ctx->hDlg)->AppendLog(initLog);
}
return 0;
}