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

+24
View File
@@ -25,6 +25,7 @@ void CClientLog::DoDataExchange(CDataExchange* pDX)
}
BEGIN_MESSAGE_MAP(CClientLog, CDialogBase)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_MESSAGE(WM_REPORT_CLIENT_LOG, OnReportLog)
@@ -50,8 +51,25 @@ void CClientLog::OnSize(UINT nType, int cx, int cy)
m_editLog.MoveWindow(7, 7, cx - 14, cy - 14);
}
void CClientLog::OnClose()
{
// 关闭前先断开日志子连接:客户端日志推送线程以 IsConnected 为循环条件,
// 不关子连接会一直往已销毁的窗口推增量;同时把上下文里的对话框指针摘掉,
// 避免 Close 期间的迟到包再次 PostMessage 到已释放的对象。
if (m_ContextObject && m_ContextObject->hDlg == this) {
m_ContextObject->hDlg = nullptr;
m_ContextObject->hWnd = nullptr;
}
CancelIO();
CDialogBase::OnClose();
}
void CClientLog::OnDestroy()
{
if (m_ContextObject && m_ContextObject->hDlg == this) {
m_ContextObject->hDlg = nullptr;
m_ContextObject->hWnd = nullptr;
}
if (m_ContextObject && m_bConnected) {
BYTE cmd = COMMAND_BYE;
m_ContextObject->Send2Client(&cmd, 1);
@@ -59,6 +77,12 @@ void CClientLog::OnDestroy()
CDialogBase::OnDestroy();
}
void CClientLog::ResetLog(const std::string& text)
{
m_editLog.SetWindowText(_T(""));
AppendLog(text);
}
void CClientLog::AppendLog(const std::string& text)
{
if (text.empty()) return;