Feature: add tooltips to the main toolbar and status bar
The main toolbar already carried CBRS_TOOLTIPS/CBRS_FLYBY, but the dialog had no TTN_NEEDTEXT handler, so hovering produced no usable text. The status bar had no pane-level tooltip at all: CStatusBar panes are not child windows. Add a shared tip text builder and ANSI/Unicode TTN_NEEDTEXT handlers. The toolbar supplies one line per command, noting which actions need a selected host. The dialog's OnToolHitTest maps the cursor onto status-bar panes, which report live TLS, MCP, FRP, runtime and licence-expiry text; the hit pane index is recorded so the delayed text request cannot pick a neighbouring pane. The status bar is a Unicode window, so the W notification is handled too, decoding GBK with code page 936 rather than the system ACP. Width is widened for multi-line tips and every string goes through _TR. Add the 36 new strings to en_US, zh_TW and de_DE (GBK, literal \n). Toolbar buttons share one width taken from the longest label, so duplicate keys (Registry Mgr, Build Server, Keylogger, Connections, 登錄檔管理, 產生伺服器端, and long German labels) pushed every button to 111px and clipped the last icons. Shortening the effective labels brings them to 85px so all 19 fit a 1920-wide monitor. Verified with a Debug x64 build and automated hovering of all 19 buttons plus 6 status panes in en_US, zh_TW and de_DE (25/25 each); zh_CN passed earlier. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
f1315a8790
commit
1d03cbeb3f
5 files changed
+377
-27
No files matched your search
@@ -1045,6 +1045,11 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
||||
// 否则点表头排序失效。两条都注册到同一个处理函数。
|
||||
ON_NOTIFY(HDN_ITEMCLICK, 0, &CMy2015RemoteDlg::OnHdnItemclickList)
|
||||
ON_NOTIFY(HDN_ITEMCLICKW, 0, &CMy2015RemoteDlg::OnHdnItemclickList)
|
||||
// 工具栏(CToolBar 自带 tooltip)与状态栏(窗口型工具)都以
|
||||
// LPSTR_TEXTCALLBACK 回头要文本。状态栏是 Unicode 窗口,发 W 版通知;
|
||||
// 工具栏走 ANSI,两条都注册,用 ID 范围匹配而不是 0。
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, &CMy2015RemoteDlg::OnToolTipText)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CMy2015RemoteDlg::OnToolTipTextW)
|
||||
ON_COMMAND(ID_ONLINE_MESSAGE, &CMy2015RemoteDlg::OnOnlineMessage)
|
||||
ON_COMMAND(ID_ONLINE_DELETE, &CMy2015RemoteDlg::OnOnlineDelete)
|
||||
ON_COMMAND(ID_ONLINE_UPDATE, &CMy2015RemoteDlg::OnOnlineUpdate)
|
||||
@@ -1755,6 +1760,227 @@ VOID CMy2015RemoteDlg::CreateToolBar()
|
||||
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); //显示
|
||||
}
|
||||
|
||||
// 工具栏按钮的悬浮提示。每次 TTN_NEEDTEXT 时现算,切换语言后无需重建。
|
||||
CString CMy2015RemoteDlg::BuildToolBarTip(UINT cmdId) const
|
||||
{
|
||||
switch (cmdId) {
|
||||
case IDM_ONLINE_CMD:
|
||||
return _TR("打开选中主机的远程终端(CMD)。\n需先在在线列表中选择一台主机。");
|
||||
case IDM_ONLINE_PROCESS:
|
||||
return _TR("查看并管理选中主机的进程(结束/挂起)。\n需先选择主机。");
|
||||
case IDM_ONLINE_WINDOW:
|
||||
return _TR("枚举并控制选中主机的窗口(显示/隐藏/关闭)。\n需先选择主机。");
|
||||
case IDM_ONLINE_DESKTOP:
|
||||
return _TR("打开远程桌面,查看并控制选中主机的屏幕。\n需先选择主机。");
|
||||
case IDM_ONLINE_FILE:
|
||||
return _TR("打开远程文件管理器,浏览、上传和下载文件。\n需先选择主机。");
|
||||
case IDM_ONLINE_AUDIO:
|
||||
return _TR("监听选中主机的声音或麦克风。\n需先选择主机。");
|
||||
case IDM_ONLINE_VIDEO:
|
||||
return _TR("查看选中主机的摄像头画面。\n需先选择主机。");
|
||||
case IDM_ONLINE_SERVER:
|
||||
return _TR("管理选中主机的 Windows 服务(启动/停止/删除)。\n需先选择主机。");
|
||||
case IDM_ONLINE_REGISTER:
|
||||
return _TR("查看和编辑选中主机的注册表。\n需先选择主机。");
|
||||
case IDM_KEYBOARD:
|
||||
return _TR("查看或开启选中主机的键盘记录。\n需先选择主机。");
|
||||
case ID_MAIN_SET:
|
||||
return _TR("主控参数:监听端口、FRP、TLS、MCP、数据库等。");
|
||||
case IDM_ONLINE_BUILD:
|
||||
return _TR("生成并配置客户端安装包(可嵌入地址、授权与选项)。");
|
||||
case ID_TOOLBAR_SEARCH:
|
||||
return _TR("在在线主机列表中按关键字搜索。");
|
||||
case IDM_ONLINE_ABOUT:
|
||||
return _TR("查看版本、关于信息与帮助。");
|
||||
case ID_CHANGE_LANG:
|
||||
return _TR("切换界面语言。");
|
||||
case ID_MCP_SETTINGS:
|
||||
return _TR("MCP 服务设置:开关、端口与 HTTP/HTTPS。\n修改后需重启主控生效。");
|
||||
case ID_CONNECTION_MANAGE:
|
||||
return _TR("查看和管理当前连接/会话。");
|
||||
case ID_TALK_MANAGE:
|
||||
return _TR("与选中主机进行双向文字交谈。\n需先选择主机。");
|
||||
case ID_MACHINE_MANAGE:
|
||||
return _TR("管理主机分组、备注与批量操作。\n需先选择主机。");
|
||||
default:
|
||||
return CString();
|
||||
}
|
||||
}
|
||||
|
||||
// 状态栏分区的悬浮提示:分区文字可能被宽度截断,这里给出完整地址/状态与来源说明。
|
||||
CString CMy2015RemoteDlg::BuildStatusTip(UINT paneId) const
|
||||
{
|
||||
switch (paneId) {
|
||||
case IDR_STATUSBAR_STRING: {
|
||||
const int idx = m_StatusBar.CommandToIndex(IDR_STATUSBAR_STRING);
|
||||
return idx >= 0 ? m_StatusBar.GetPaneText(idx) : CString();
|
||||
}
|
||||
case IDR_STATUSBAR_TLS:
|
||||
if (ServerTlsIdentity::IsLoadError())
|
||||
return _TR("TLS 已启用,但证书或私钥加载失败;服务端会拒绝 TLS 握手(fail-closed),明文连接可能仍被接受。\n请检查 [tls] 的 CertPath / KeyPath。");
|
||||
if (!ServerTlsIdentity::IsEnabled())
|
||||
return _TR("TLS 未启用:客户端可使用明文连接,或由主控下发信任锚后切换到 TLS。");
|
||||
return ServerTlsIdentity::IsBuiltin()
|
||||
? _TR("TLS 使用内置自签证书(首次启用时自动生成),信任锚随客户端下发。")
|
||||
: _TR("TLS 使用自定义证书,入站凭据已加载。");
|
||||
case IDR_STATUSBAR_MCP: {
|
||||
if (!THIS_CFG.GetInt("settings", "McpEnabled", 0))
|
||||
return _TR("MCP 未启用。可在工具栏 MCP 或「扩展」菜单中开启,修改后需重启主控生效。");
|
||||
const int port = THIS_CFG.GetInt("settings", "McpPort", 6544);
|
||||
const bool https = THIS_CFG.GetInt("settings", "McpHttps", 0) != 0;
|
||||
CString tip = _TR("MCP 已启用:端口 ");
|
||||
tip.AppendFormat(_T("%d"), port);
|
||||
tip += _TR(",协议 ");
|
||||
tip += https ? _T("HTTPS") : _T("HTTP");
|
||||
tip += _TR("。\n修改 MCP 设置后需重启主控生效。");
|
||||
return tip;
|
||||
}
|
||||
case IDR_STATUSBAR_FRP: {
|
||||
CString tip = _TR("当前对外地址:");
|
||||
const int idx = m_StatusBar.CommandToIndex(IDR_STATUSBAR_FRP);
|
||||
if (idx >= 0)
|
||||
tip += m_StatusBar.GetPaneText(idx);
|
||||
if (!m_strFrpAddr.IsEmpty())
|
||||
tip += _TR("\n来源:上级配置的 FRPC 地址。");
|
||||
else if (CFrpsForSubDlg::IsFrpsConfigured())
|
||||
tip += _TR("\n来源:本机 FRPS。");
|
||||
else if (m_settings.UsingFRPProxy)
|
||||
tip += _TR("\n来源:上级 FRP 代理的 master 地址。");
|
||||
else
|
||||
tip += _TR("\n来源:本机直连(公网 WAN 或局域网 LAN)。");
|
||||
return tip;
|
||||
}
|
||||
case IDR_STATUSBAR_RUNTIME:
|
||||
if (m_runNormal == 1)
|
||||
return _TR("普通模式:显示主控本次运行时长。");
|
||||
return _TR("服务模式:显示累计运行时长;有崩溃记录时显示 MTBF 与失败率。");
|
||||
case IDR_STATUSBAR_EXPIRE:
|
||||
if (m_strExpireDate.IsEmpty())
|
||||
return CString();
|
||||
{
|
||||
CString tip = _TR("授权到期信息:");
|
||||
const int idx = m_StatusBar.CommandToIndex(IDR_STATUSBAR_EXPIRE);
|
||||
if (idx >= 0)
|
||||
tip += m_StatusBar.GetPaneText(idx);
|
||||
tip += _TR("\n剩余天数包含到期当天;已过期时主控功能可能受限。");
|
||||
return tip;
|
||||
}
|
||||
default:
|
||||
return CString();
|
||||
}
|
||||
}
|
||||
|
||||
INT_PTR CMy2015RemoteDlg::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
|
||||
{
|
||||
m_statusTipPane = -1;
|
||||
if (m_StatusBar.GetSafeHwnd() == nullptr)
|
||||
return -1;
|
||||
|
||||
// point 是对话框客户区坐标;先判断是否落在状态栏上。
|
||||
CRect sbClient;
|
||||
m_StatusBar.GetWindowRect(&sbClient);
|
||||
ScreenToClient(&sbClient);
|
||||
if (!sbClient.PtInRect(point))
|
||||
return -1;
|
||||
|
||||
const CPoint sbPoint(point.x - sbClient.left, point.y - sbClient.top);
|
||||
for (int i = 0; i < m_StatusBar.GetCount(); ++i) {
|
||||
CRect rc;
|
||||
m_StatusBar.GetItemRect(i, &rc);
|
||||
if (!rc.PtInRect(sbPoint))
|
||||
continue;
|
||||
m_statusTipPane = i;
|
||||
if (pTI != nullptr) {
|
||||
// 状态栏是 Unicode 窗口,TTN_NEEDTEXTW 会经 CControlBar 转发到本对话框。
|
||||
pTI->hwnd = m_hWnd; // 容器窗口
|
||||
pTI->uId = (UINT_PTR)m_StatusBar.m_hWnd; // 工具窗口
|
||||
pTI->uFlags |= TTF_IDISHWND | TTF_ALWAYSTIP;
|
||||
pTI->lpszText = LPSTR_TEXTCALLBACK;
|
||||
}
|
||||
// 内建提示默认单行;放宽最大宽度后 \n 才会折行。
|
||||
AFX_MODULE_THREAD_STATE* ts = AfxGetModuleThreadState();
|
||||
if (ts != nullptr && ts->m_pToolTip != nullptr && ts->m_pToolTip->GetSafeHwnd() != nullptr)
|
||||
ts->m_pToolTip->SetMaxTipWidth(600);
|
||||
// 返回随分区变化的命中值:跨分区时 MFC 会重新注册工具并重新取文本。
|
||||
return (INT_PTR)(0x7000 + i);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 工具栏与状态栏共用的提示文本解析。
|
||||
CString CMy2015RemoteDlg::BuildTipText(UINT_PTR nID, UINT uFlags) const
|
||||
{
|
||||
CString text;
|
||||
if (uFlags & TTF_IDISHWND) {
|
||||
HWND hwnd = (HWND)nID;
|
||||
if (hwnd == m_StatusBar.GetSafeHwnd()) {
|
||||
// 优先使用 OnToolHitTest 记录的分区,避免光标在边界移动后取错分区。
|
||||
int pane = m_statusTipPane;
|
||||
if (pane < 0 || pane >= m_StatusBar.GetCount()) {
|
||||
CPoint pt;
|
||||
::GetCursorPos(&pt);
|
||||
m_StatusBar.ScreenToClient(&pt);
|
||||
for (int i = 0; i < m_StatusBar.GetCount(); ++i) {
|
||||
CRect rc;
|
||||
m_StatusBar.GetItemRect(i, &rc);
|
||||
if (rc.PtInRect(pt)) {
|
||||
pane = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pane >= 0 && pane < m_StatusBar.GetCount())
|
||||
text = BuildStatusTip(m_StatusBar.GetItemID(pane));
|
||||
} else {
|
||||
nID = (UINT_PTR)::GetDlgCtrlID(hwnd);
|
||||
}
|
||||
}
|
||||
if (text.IsEmpty())
|
||||
text = BuildToolBarTip((UINT)nID);
|
||||
if (text.IsEmpty())
|
||||
text = BuildStatusTip((UINT)nID);
|
||||
return text;
|
||||
}
|
||||
|
||||
BOOL CMy2015RemoteDlg::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR;
|
||||
CString text = BuildTipText(pNMHDR->idFrom, pTTT->uFlags);
|
||||
if (text.IsEmpty())
|
||||
return FALSE;
|
||||
|
||||
// 内建提示默认单行;放宽最大宽度后 \n 才会折行。
|
||||
AFX_MODULE_THREAD_STATE* ts = AfxGetModuleThreadState();
|
||||
if (ts != nullptr && ts->m_pToolTip != nullptr && ts->m_pToolTip->GetSafeHwnd() != nullptr)
|
||||
ts->m_pToolTip->SetMaxTipWidth(600);
|
||||
|
||||
// 指向成员:提示显示期间必须保持有效。
|
||||
m_sToolTipText = text;
|
||||
pTTT->lpszText = const_cast<LPTSTR>((LPCTSTR)m_sToolTipText);
|
||||
*pResult = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CMy2015RemoteDlg::OnToolTipTextW(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
TOOLTIPTEXTW* pTTT = (TOOLTIPTEXTW*)pNMHDR;
|
||||
CString text = BuildTipText(pNMHDR->idFrom, pTTT->uFlags);
|
||||
if (text.IsEmpty())
|
||||
return FALSE;
|
||||
|
||||
// 最大宽度已在 OnToolHitTest 中设置(状态栏路径),这里不再重入提示控件。
|
||||
// 窄字符串来自编译期 GBK 字面量或 Bin/lang 的 GBK 语言包,
|
||||
// 必须按 936 解码,不能依赖非中文系统上的 ACP。
|
||||
const int len = text.GetLength();
|
||||
const int n = ::MultiByteToWideChar(936, 0, (LPCSTR)text, len, nullptr, 0);
|
||||
m_sToolTipTextW.assign(n > 0 ? (size_t)n : 0, L'\0');
|
||||
if (n > 0)
|
||||
::MultiByteToWideChar(936, 0, (LPCSTR)text, len, &m_sToolTipTextW[0], n);
|
||||
pTTT->lpszText = const_cast<LPWSTR>(m_sToolTipTextW.c_str());
|
||||
*pResult = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
VOID CMy2015RemoteDlg::InitControl()
|
||||
{
|
||||
@@ -2885,6 +3111,9 @@ BOOL CMy2015RemoteDlg::OnInitDialog()
|
||||
|
||||
UPDATE_SPLASH(75, "正在创建界面组件...");
|
||||
CreatStatusBar();
|
||||
// 工具栏自带 tooltip;状态栏 pane 由本对话框的 OnToolHitTest 命中,
|
||||
// 因此需要在对话框这层启用 MFC 内建工具提示。
|
||||
EnableToolTips(TRUE);
|
||||
CreateNotifyBar();
|
||||
CreateSolidMenu();
|
||||
|
||||
|
||||
Reference in new issue
Block a user